Changeset 644 in tmcsimulator for trunk


Ignore:
Timestamp:
05/27/2021 01:49:06 PM (5 years ago)
Author:
jdalbey
Message:

activitylog_watcher.py modified to fix defect #255.

File:
1 edited

Legend:

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

    r549 r644  
    11import json, time, ConfigParser 
    2 #from copy import deepcopy 
    3  
    42# Incident Activity log Watcher 
    53# Look for changes in the IncidentActivity log. 
     
    108# new messages that arrived during the last wait interval.  
    119# jdalbey  7/24/2019 
     10# Refactored and revised to fix defect #255 5/27/2021 
     11# Notes: 
     12# incident_description.json contains the summary details of the incident  
     13# incident_activity.json contains the incident detail entries for all created incidents. 
     14# incident_description.json fields 
     15#      "20190523-008",  # Incident ID 
     16#      "05\\/23",                # Date 
     17#      "15:55.25",       # Time 
     18#      "Hall, Kacie",    # User ID 
     19#      "SR-73",          # Route 
     20#      "BAKER ",                 # Location 
     21#      "SB",             # Direction 
     22#      "Advisory",               # Incident Category 
     23#      "Advisory: National Weather Service Advisory",  # Incident Type 
     24#      "RV FIRE "                # Description 
     25#incident_activity fields: 
     26#      "20190523-004",   # Incident ID 
     27#      "05\\/23",               # Date 
     28#      "14:14.04",              # Time 
     29#      "Sarker, Afrid", # User ID 
     30#      "CMS Activation",         # Activity Code 
     31#      "UPDATED CMS CMS ID: 1214504   LOCATION: N I-5 12.86  Avery Pkwy"          Description 
    1232 
    13 lastLineNum = 0 
     33# Global variables to remember length of file between readings 
     34file1length = 0 
     35file2length = 0 
    1436 
    1537# Utility functions 
     
    1840def isFull(cmsitem): 
    1941    return not isEmpty(cmsitem) 
    20  
    21 # Read the log  
    22 def readFile(): 
    23     # get path to input file from configuration 
     42# get path to input file from configuration 
     43def getLogFilePath(): 
    2444    config = ConfigParser.ConfigParser() 
    2545    config.read('config/logging_service.cfg') 
    26     logfilepath = config.get('Paths', 'ActivityLogPath') 
    27     logfilename = "data.json"   #"IncidentActivity.log" 
    28     data_summary = "data_summary.json" 
    29     lines = [] 
     46    return config.get('Paths', 'ActivityLogPath') 
     47     
     48# Read the activty log entries  
     49def readFile1(): 
     50    logfilename = "incident_activity.json"   #"IncidentActivity.log" 
    3051    output = [] 
    31     try: 
    32         json_file = open (logfilepath + logfilename,'r') 
     52    try:   
     53        log_file = open (getLogFilePath() + logfilename,'r') 
    3354    except IOError: 
    34         print "Error: missing "+logfilepath+logfilename+" file." 
     55        print "Error: missing "+logfilepath + logfilename + " file." 
    3556    else: 
    36         jsonData=json_file.read() 
     57        logData=log_file.read()  # Read the activity log 
    3758        # implement ticket #192 
    38         output = json.loads(jsonData)['data']  
    39         # read in data_summary_json file 
    40         # assuming the data_summary.json is in the trunk foldera 
    41         data_summary = open(logfilepath + data_summary, 'r') 
     59        output = json.loads(logData)['data']  # parse the log data into a dict 
     60        log_file.close() 
     61    return output 
     62 
     63# Read the log of new incidents 
     64# It has a different format than incident_activity.json, so we put it in a separate function. 
     65def readFile2(): 
     66    data_summary = "incident_description.json" 
     67    output = [] 
     68    try:   
     69        data_summary = open(getLogFilePath() + data_summary, 'r') 
     70    except IOError: 
     71        print "Error: missing "+logfilepath + data_summary + " file." 
     72    else: 
     73        # read in incident_description json file that contains Incident summary data 
     74        # assuming this file is in the same folder 
    4275        summary_json = data_summary.read() 
    43         data_lst = json.loads(summary_json)['data'] 
     76        data_lst = json.loads(summary_json)['data'] # parse the new incident data 
     77        # Append each 'incident created' info to the results  
    4478        for entry in data_lst: 
    45             # put the first 3 entries as place holder to be consistent with other type of logging 
     79            # put the first 3 fields as place holder to be consistent with other type of logging 
    4680            output.append([entry[0], entry[1] , entry[2], entry[3] , ", Incident Created, ", ""])  
    47         json_file.close() 
     81        data_summary.close() 
    4882    return output 
    4983     
    50 def setup(): 
    51     # nothing needed for setup 
    52     return 
    53  
    5484# Retrieve new messages from activity log  
    5585def getLogEntries(): 
    56     global lastLineNum 
    57     msgList = readFile() 
    58     currList = [] 
    59     currList = msgList[lastLineNum:]    # new items since last file read 
    60     lastLineNum = len(msgList) 
     86    global file1length, file2length 
     87    # Read activity log of new activity  
     88    msgList = readFile1() 
     89    file1items = [] 
     90    file1items = msgList[file1length:]    # new items since last file read 
     91    file1length = len(msgList) 
     92    # Read activity log of new incidents 
     93    msgList = readFile2() 
     94    file2items = [] 
     95    file2items = msgList[file2length:]    # new items since last file read 
     96    file2length = len(msgList) 
     97    # Concatenate the two logs 
     98    currList = file1items + file2items 
     99 
    61100    resultList = [] 
    62101    # Format messages into desired result format 
     
    73112        resultList.append(desiredFields) 
    74113    return resultList 
     114 
     115def setup(): 
     116    # nothing needed for setup 
     117    return 
    75118 
    76119# Local main for unit testing 
Note: See TracChangeset for help on using the changeset viewer.