Changeset 644 in tmcsimulator
- Timestamp:
- 05/27/2021 01:49:06 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/python/unifiedlogger/activitylog_watcher.py
r549 r644 1 1 import json, time, ConfigParser 2 #from copy import deepcopy3 4 2 # Incident Activity log Watcher 5 3 # Look for changes in the IncidentActivity log. … … 10 8 # new messages that arrived during the last wait interval. 11 9 # 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 12 32 13 lastLineNum = 0 33 # Global variables to remember length of file between readings 34 file1length = 0 35 file2length = 0 14 36 15 37 # Utility functions … … 18 40 def isFull(cmsitem): 19 41 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 43 def getLogFilePath(): 24 44 config = ConfigParser.ConfigParser() 25 45 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 49 def readFile1(): 50 logfilename = "incident_activity.json" #"IncidentActivity.log" 30 51 output = [] 31 try: 32 json_file = open (logfilepath+ logfilename,'r')52 try: 53 log_file = open (getLogFilePath() + logfilename,'r') 33 54 except IOError: 34 print "Error: missing "+logfilepath +logfilename+" file."55 print "Error: missing "+logfilepath + logfilename + " file." 35 56 else: 36 jsonData=json_file.read()57 logData=log_file.read() # Read the activity log 37 58 # 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. 65 def 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 42 75 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 44 78 for entry in data_lst: 45 # put the first 3 entries as place holder to be consistent with other type of logging79 # put the first 3 fields as place holder to be consistent with other type of logging 46 80 output.append([entry[0], entry[1] , entry[2], entry[3] , ", Incident Created, ", ""]) 47 json_file.close()81 data_summary.close() 48 82 return output 49 83 50 def setup():51 # nothing needed for setup52 return53 54 84 # Retrieve new messages from activity log 55 85 def 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 61 100 resultList = [] 62 101 # Format messages into desired result format … … 73 112 resultList.append(desiredFields) 74 113 return resultList 114 115 def setup(): 116 # nothing needed for setup 117 return 75 118 76 119 # Local main for unit testing
Note: See TracChangeset
for help on using the changeset viewer.
