Changeset 544 in tmcsimulator for trunk/src


Ignore:
Timestamp:
12/18/2019 01:53:04 PM (6 years ago)
Author:
liquan
Message:

Replace commas in DETAIL text with whitespace. Remove the text "Detail" for the second DETAIL field.

File:
1 edited

Legend:

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

    r542 r544  
    11import xml.etree.ElementTree as ET 
    22import os, ConfigParser 
    3  
    43 
    54config = ConfigParser.ConfigParser() 
     
    87 
    98# read in the incident script in XML format 
    10 tree = ET.parse(logfilepath + 'incident_script.xml') 
     9tree = ET.parse(logfilepath + 'incident_script_test.xml') 
    1110# root is TMC_SCRIPT tag  
    1211root = tree.getroot() 
     
    4039                    # Look for CAD_INCIDENT_EVENT 
    4140                    if event.tag == 'CAD_INCIDENT_EVENT': 
    42                         # count variable make sure there is as least a field  
    43                         # inside CAD_INCIDENT_EVENT  
    44                         count = 0 
     41                        # set flag to check if DETAIL field exist 
     42                        detail = False 
    4543                        for info in event: 
    46                             count += 1 
    47                             # Aad the incident detail to entry string  
     44                            # Add the incident detail to entry string  
    4845                            if info.tag == "DETAIL": 
    49                                 entry_str += ", Detail: " + info.text  
    50                             else: 
    51                                 # if no detail found then reset string 
    52                                 entry_str = "" 
    53                         # if no field inside CAD_INCIDENT_EVENT  
    54                         # reset the string  
    55                         if count == 0: 
    56                             entry_str = "" 
     46                                # replace commas with whitespace 
     47                                text = info.text.replace(",", " ") 
     48                                # if it's not the first DETAIL field,  
     49                                # append to the end without "Detail" text 
     50                                if detail: 
     51                                    entry_str += "; " + text 
     52                                else: 
     53                                    entry_str += ", Detail: " + text 
     54                                detail = True 
    5755                         
    58                         # if entry_str contain some info 
     56                        # if there's detail field 
    5957                        # add it to the entries  
    60                         if entry_str != "": 
     58                        if detail: 
    6159                            entries += entry_str + "\n" 
    6260# write all the entries from incident_sript.xml to the output file  
     
    7573os.system("sort -o " + logfilepath + "caddetails.csv " \ 
    7674    + logfilepath + "caddetails.csv") 
     75                             
Note: See TracChangeset for help on using the changeset viewer.