Changeset 439 in tmcsimulator for trunk/webapps


Ignore:
Timestamp:
07/11/2019 02:45:25 PM (7 years ago)
Author:
jdalbey
Message:

setup wing project for logging service python files. Add config file for file paths.

Location:
trunk/webapps/unifiedlogger
Files:
2 added
2 deleted
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/webapps/unifiedlogger/cad_watcher.py

    r436 r439  
    33 
    44# CAD comment log Watcher 
    5 # Look for changes in the CAD comment log 
     5# Look for changes in the CAD comment log. 
     6# The CADserver will append new comments to the log as they arrive  
     7# from clients.  We only need to keep track of the log length in order to 
     8# determine if a new comment has been added.  We will output the  
     9# new messages that arrived during the last wait interval.  
    610# jdalbey  7/6/2019 
    711 
     
    1418    return not isEmpty(cmsitem) 
    1519 
    16 # Read the cms message file 
     20# Read the cad comments log  
    1721def readFile(): 
    1822    lines = [] 
    1923    try: 
    20         text_file = open("../../CADcomments.log", "r") 
     24        text_file = open("CADcomments.log", "r") 
    2125    except IOError: 
    2226        print "Error: missing CADcomments.log file." 
     
    3943    return currList 
    4044 
     45# Local main for unit testing 
    4146def main(): 
    4247    setup() 
    43     # Loop Forever 
     48    # Loop Forever, checking every five seconds 
    4449    while True: 
    45         # Look for changed messages 
     50        # Look for new messages 
    4651        answer = getLogEntries() 
    4752        # Output results 
  • trunk/webapps/unifiedlogger/cms_watcher.py

    r433 r439  
    88prevList = []  # previous messages 
    99currList = []  # current messages 
    10 locationMap = {} 
     10locationMap = {} # map of CMS ID's to locations 
    1111 
    1212# Utility functions 
     
    1818# Read the cms message file 
    1919def readFile():      
    20      with open ("../dynamicdata/cms_messages.json",'r') as myfile: 
     20     with open ("webapps/dynamicdata/cms_messages.json",'r') as myfile: 
    2121          jsonData=myfile.read() 
    2222  
     
    2525# Read the static file of cms locations and create a lookup map 
    2626def loadLocations(): 
    27      with open ("../cptms/data_layers/cms_locations_D12.gjson",'r') as myfile: 
     27     with open ("webapps/cptms/data_layers/cms_locations_D12.gjson",'r') as myfile: 
    2828          jsonData=myfile.read() 
    2929  
     
    4040     for idx in range(0,len(msgList)): 
    4141          idList.append(msgList[idx]['cms']['index']) 
    42           prevList.append(",,,,,") 
     42          prevList.append(":::::") 
    4343     return msgList 
    4444 
     
    4949     for idx in range(0,len(msgList)): 
    5050          currList.append( 
    51                     msgList[idx]['cms']['message']['phase1']['Line1'] + ',' +  
    52                     msgList[idx]['cms']['message']['phase1']['Line2'] + ',' + 
    53                     msgList[idx]['cms']['message']['phase1']['Line3'] + ',' + 
    54                     msgList[idx]['cms']['message']['phase2']['Line1'] + ',' + 
    55                     msgList[idx]['cms']['message']['phase2']['Line2'] + ',' + 
     51                    msgList[idx]['cms']['message']['phase1']['Line1'] + ':' +  
     52                    msgList[idx]['cms']['message']['phase1']['Line2'] + ':' + 
     53                    msgList[idx]['cms']['message']['phase1']['Line3'] + ':' + 
     54                    msgList[idx]['cms']['message']['phase2']['Line1'] + ':' + 
     55                    msgList[idx]['cms']['message']['phase2']['Line2'] + ':' + 
    5656                    msgList[idx]['cms']['message']['phase2']['Line3']) 
    5757 
     
    7171          # Is a new message activated? 
    7272          if isEmpty(prevList[idx]) and isFull(currList[idx]): 
    73                results.append("CMS Activated. " + locationMap[idList[idx]] + " '" + currList[idx] +"'") 
     73               results.append("CMS Activated.," + locationMap[idList[idx]] + ", '" + currList[idx] +"'") 
    7474          # Is an existing message turned off? 
    7575          if isEmpty(currList[idx]) and isFull(prevList[idx]): 
    76                results.append("CMS Deactivated. " + locationMap[idList[idx]]) 
     76               results.append("CMS Deactivated., " + locationMap[idList[idx]]) 
    7777          # Did a message change? 
    7878          if isFull(currList[idx]) and isFull(prevList[idx]) and currList[idx] != prevList[idx]: 
    79                results.append("CMS Updated. " + locationMap[idList[idx]] + " '" + currList[idx] +"'") 
     79               results.append("CMS Updated., " + locationMap[idList[idx]] + ", '" + currList[idx] +"'") 
    8080 
    8181     # Save the current list as previous 
     
    8383     return results 
    8484 
     85# Local main for unit testing 
    8586def main(): 
    8687     global currList 
  • trunk/webapps/unifiedlogger/logging_service.py

    r433 r439  
    1 import cms_watcher, cad_watcher, time, json 
     1import cms_watcher, cad_watcher, time, json, ConfigParser 
    22# Unified Logging Service 
    33# jdalbey 7/6/2019 
    44 
     5outputFilename = "unifiedlog.csv" 
    56 
    67# Load the sim time file and extract the seconds */ 
    78def getSimTime(): 
    8     with open ("../dynamicdata/sim_elapsedtime.json", 'r') as myfile: 
     9    with open ("webapps/dynamicdata/sim_elapsedtime.json", 'r') as myfile: 
    910        jsonData=myfile.read() 
    1011          
     
    1516    return  "%d:%02d:%02d" % (h, m, s)     
    1617 
    17 def main(): 
     18def startup(): 
     19    # get path to output file from configuration 
     20    config = ConfigParser.ConfigParser() 
     21    config.read('config/logging_service.cfg') 
     22    logfilepath  = config.get('Paths', 'UnifiedLogPath') 
     23     
    1824    # Delete any previously existing output file 
    19     f = open("../dynamicdata/unifiedlog.html", "w") 
    20     startHTML = "<HTML><HEAD><meta http-equiv=\"refresh\" content=\"5\" /></HEAD><BODY><PRE>" 
    21     f.write(startHTML); 
     25    f = open(logfilepath + outputFilename, "w") 
    2226    f.close()             
    2327    # List of the available plugin modules  
     
    5155                trimmed_item = item.strip() 
    5256                if len(trimmed_item) > 0: 
    53                     output += timeStamp + " " + trimmed_item + "\n" 
     57                    output += timeStamp + ", " + trimmed_item + "\n" 
    5458    #    END LOOP 
    5559    #    IF the Output Buffer has any contents THEN 
    5660        if len(output) > 0: 
    57     #       Write (append) Output Buffer to unified log file  
     61    #       Write (append) Output Buffer to unified log file as CSV 
     62    #       Assumes fields don't contain commas  
    5863            print output, 
    59             f = open("../dynamicdata/unifiedlog.html", "a") 
     64            f = open(logfilepath + outputFilename, "a") 
    6065            f.write(output) 
    6166            f.close()             
    6267    #    END IF 
    63     #    Wait one second 
    64         time.sleep(1) 
     68    #    Wait five seconds 
     69        time.sleep(5) 
    6570 
    6671#END DO 
    67 if __name__ == "__main__": 
    68     main() 
     72 
     73if __name__ == '__main__': 
     74    startup() 
Note: See TracChangeset for help on using the changeset viewer.