Ignore:
Timestamp:
12/26/2019 03:10:19 PM (6 years ago)
Author:
jdalbey
Message:

Modify extract_caddetails to not merge with unifiedlog; this is now done in mergelogs.bash shell script.

File:
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/python/unifiedlogger/extract_caddetails.py

    r545 r550  
    11import xml.etree.ElementTree as ET 
    22import os, ConfigParser 
     3# Standalone application to extract CAD DETAIL info from  
     4# incident_script.xml. 
     5# @author Ally Quan, jdalbey 
     6# Deploy:  zip file is created by package_jars target of NetBeans build.xml. 
     7#          Move unifiedlogger.zip from deploy folder to webapps folder. 
     8# Usage: PYTHONPATH=webapps/unifiedlogger.zip  python -m extract_caddetails 
     9def extract(): 
     10    config = ConfigParser.ConfigParser() 
     11    config.read('config/logging_service.cfg') 
     12    logfilepath  = config.get('Paths', 'UnifiedLogPath') 
     13     
     14    # read in the incident script in XML format 
     15    tree = ET.parse(logfilepath + 'incident_script.xml') 
     16    # root is TMC_SCRIPT tag  
     17    root = tree.getroot() 
     18     
     19    # entries contain all of the entry of cad incident from incident script  
     20    entries = "" 
     21     
     22    # loop through tags under TMC_SCRIPT  
     23    for script_event in root: 
     24        # if found tag SCRIPT_EVENT 
     25        if script_event.tag == 'SCRIPT_EVENT': 
     26            entry_str = "" 
     27            # loop through tags within SCRIPT_EVENT tags 
     28            for info_type in script_event: 
     29                # Add the time index field to entry string 
     30                if info_type.tag == 'TIME_INDEX': 
     31                    entry_time =  info_type.text + "," 
     32                # Get the incident number to entry string  
     33                if info_type.tag == "INCIDENT": 
     34                    incident_num = info_type.attrib["LogNum"] 
     35                    entry_incinum = " CAD Log, Incident #" + incident_num 
     36                # Get the cad data info  
     37                if info_type.tag == 'CAD_DATA': 
     38                    # Loop through all tags under CAD_DATA  
     39                    for event in info_type: 
     40                        # Look for CAD_INCIDENT_EVENT 
     41                        if event.tag == 'CAD_INCIDENT_EVENT': 
     42                            # set flag to check if DETAIL field exist 
     43                            detailFlag = False 
     44                            detailText = "" 
     45                            for info in event: 
     46                                # Add the incident detail to entry string  
     47                                if info.tag == "DETAIL": 
     48                                    # replace commas with whitespace 
     49                                    infotext = info.text.replace(",", " ") 
     50                                    # if it's the second DETAIL field,  
     51                                    # we don't need the "Detail" label 
     52                                    if not detailFlag: 
     53                                        detailText = ", Detail: " 
     54                                        detailFlag = True 
     55                                    detailText += infotext                                 
     56                            # Build the complete line from the header and details 
     57                            entry_str += entry_time + entry_incinum + detailText                                     
     58                            # if there's detail field add it to the entries  
     59                            if detailFlag: 
     60                                entries += entry_str + "\n" 
     61     
     62    # write all the entries from incident_sript.xml to the output file  
     63    # create a new file for the combined entry from incident script and unifiedlog 
     64    details_file = open(logfilepath + "caddetails.csv", "w") 
     65    details_file.write(entries) 
     66    details_file.close() 
    367 
    4 config = ConfigParser.ConfigParser() 
    5 config.read('config/logging_service.cfg') 
    6 logfilepath  = config.get('Paths', 'UnifiedLogPath') 
     68if __name__ == '__main__': 
     69    extract() 
     70     
     71# The following code is obsolete and has been replaced by a unix script 
    772 
    8 # read in the incident script in XML format 
    9 tree = ET.parse(logfilepath + 'incident_script.xml') 
    10 # root is TMC_SCRIPT tag  
    11 root = tree.getroot() 
     73# Append unifiedlog file to caddetails file 
     74#details_file = open(logfilepath + "caddetails.csv", "a") 
     75# read in unifiedlog.csv and append to the caddetails file  
     76#unified_log = open(logfilepath + "unifiedlog.csv", "r") 
     77#line = unified_log.readline()   
     78#while line: 
     79#    details_file.write(line) 
     80#    line = unified_log.readline() 
    1281 
    13 # entries contain all of the entry of cad incident from incident script  
    14 entries = "" 
    15 # create a new file for the combined entry from incident script and unifiedlog 
    16 out_file = open(logfilepath + "caddetails.csv", "w") 
    17  
    18 # read from the unifiedlog 
    19 unified_log = open(logfilepath + "unifiedlog.csv", "r") 
    20  
    21 # loop through tags under TMC_SCRIPT  
    22 for script_event in root: 
    23     # if found tag SCRIPT_EVENT 
    24     if script_event.tag == 'SCRIPT_EVENT': 
    25         entry_str = "" 
    26         # loop through tags within SCRIPT_EVENT tags 
    27         for info_type in script_event: 
    28             # Add the time index field to entry string 
    29             if info_type.tag == 'TIME_INDEX': 
    30                 entry_time =  info_type.text + "," 
    31             # Get the incident number to entry string  
    32             if info_type.tag == "INCIDENT": 
    33                 incident_num = info_type.attrib["LogNum"] 
    34                 entry_incinum = " CAD Log, Incident #" + incident_num 
    35             # Get the cad data info  
    36             if info_type.tag == 'CAD_DATA': 
    37                 # Loop through all tags under CAD_DATA  
    38                 for event in info_type: 
    39                     # Look for CAD_INCIDENT_EVENT 
    40                     if event.tag == 'CAD_INCIDENT_EVENT': 
    41                         # set flag to check if DETAIL field exist 
    42                         detailFlag = False 
    43                         detailText = "" 
    44                         for info in event: 
    45                             # Add the incident detail to entry string  
    46                             if info.tag == "DETAIL": 
    47                                 # replace commas with whitespace 
    48                                 infotext = info.text.replace(",", " ") 
    49                                 # if it's the second DETAIL field,  
    50                                 # we don't need the "Detail" label 
    51                                 if not detailFlag: 
    52                                     detailText = ", Detail: " 
    53                                     detailFlag = True 
    54                                 detailText += infotext                                 
    55                         # Build the complete line from the header and details 
    56                         entry_str += entry_time + entry_incinum + detailText                                     
    57                         # if there's detail field add it to the entries  
    58                         if detailFlag: 
    59                             entries += entry_str + "\n" 
    60 # write all the entries from incident_sript.xml to the output file  
    61 out_file.write(entries) 
    62  
    63 out_file = open(logfilepath + "caddetails.csv", "a") 
    64 # read in unifiedlog.csv and append to the output file  
    65 line = unified_log.readline() 
    66 while line: 
    67     out_file.write("0"+line) 
    68     line = unified_log.readline() 
    69  
    70 out_file.close() 
     82#details_file.close() 
    7183 
    7284# run the unix command line to sorting the file  
    73 os.system("sort -o " + logfilepath + "caddetails.csv " \ 
    74     + logfilepath + "caddetails.csv") 
     85#os.system("sort -o " + logfilepath + "caddetails.csv " \ 
     86#    + logfilepath + "caddetails.csv") 
    7587                             
Note: See TracChangeset for help on using the changeset viewer.