-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.py
118 lines (104 loc) · 5.25 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
from parsers.messageLogs_functions import loop_read_file
from analysis.analyzePodMessages import analyzePodMessages
from analysis.analyzeAllPodsInDeviceLog import analyzeAllPodsInDeviceLog
from util.report import printLoopDict
from util.report import writeCombinedLogToOutputFile
from util.report import generatePlot, printDict
import platform
import os
# test git repo push
def main(fileDict, outFlag, vFlag):
# read file, create dictionaries and DataFrames
loopReadDict = loop_read_file(fileDict)
# loopReadDict has keys:
# fileDict, logDF, podMgrDict, faultInfoDict,
# loopVersionDict, determBasalDF
fileDict = loopReadDict['fileDict']
determBasalDF = loopReadDict['determBasalDF']
# print(loopReadDict)
if fileDict['recordType'] == 'FAPSX':
# printDict(fileDict)
# file was identified as being FAPSX by loop_read_file
if fileDict['file'] == "log_prev.txt":
old_name = (fileDict['path'] + "/" +
fileDict['person'] + "/" +
fileDict['file'])
fileDict['file'] = (fileDict['date'] + "_" +
fileDict['file'])
fileDict['personFile'] = (fileDict['person'] + "/" +
fileDict['file'])
fileDict['filename'] = (fileDict['path'] + "/" +
fileDict['personFile'])
new_name = (fileDict['path'] + "/" +
fileDict['person'] + "/" +
fileDict['file'])
# print("Renaming: \n *** ", old_name, "\n *** ", new_name)
sys_cmd = "mv -f " + old_name + " " + new_name
# print("sys_cmd is :", sys_cmd)
os.system(sys_cmd)
# printDict(fileDict)
# else:
# print("No renaming necessary")
print('\n------------------------------------------')
print(' File: {:s}'.format(fileDict["personFile"]))
if len(loopReadDict['loopVersionDict']):
commentString = 'Build Details reported in file'
maxItems = 10
printLoopDict(commentString, maxItems, loopReadDict['loopVersionDict'])
if len(loopReadDict['faultInfoDict']) and vFlag == 4:
commentString = 'PodInfoFaultEvent reported in file'
maxItems = 10
printLoopDict(commentString, maxItems, loopReadDict['faultInfoDict'])
if len(loopReadDict['podMgrDict']) and vFlag == 4:
commentString = 'podMgrDict reported in file'
maxItems = 3 # address, activated at, expired at
printLoopDict(commentString, maxItems, loopReadDict['podMgrDict'])
if fileDict['recordType'] == "unknown":
print('\n *** Did not recognize file type')
print(' Parser did not find required section in file: \n',
' ', fileDict["personFile"], '\n',
' ## MessageLog or\n',
' ## Device Communication Log')
return
if fileDict['recordType'] == "messageLog":
print(' ----------------------------------------')
print(' This file uses MessageLog')
print(' ----------------------------------------')
numChunks = 1 # number of pods in log file is always 1
analyzePodMessages(fileDict, loopReadDict['logDF'],
loopReadDict['podMgrDict'],
outFlag, vFlag, numChunks)
if vFlag == 4:
thisOutFile = outFlag + '/' + 'logDF_out.csv'
writeCombinedLogToOutputFile(thisOutFile, loopReadDict['logDF'])
elif fileDict['recordType'] == "deviceLog":
print(' ----------------------------------------')
print(' This file uses Device Communication Log')
analyzeAllPodsInDeviceLog(fileDict, loopReadDict, outFlag, vFlag)
if vFlag == 4 or vFlag == 5:
thisOutFile = outFlag + '/' + 'logDFCmb_out.csv'
writeCombinedLogToOutputFile(thisOutFile, loopReadDict['logDF'])
elif fileDict['recordType'] == 'FAPSX':
print(' ----------------------------------------')
print(' This file a FAPSX log file')
logDF = loopReadDict['logDF']
if not logDF.empty:
analyzeAllPodsInDeviceLog(fileDict, loopReadDict, outFlag, vFlag)
thisOutFile = outFlag + '/' + 'logDFCmb_out.csv'
writeCombinedLogToOutputFile(thisOutFile, loopReadDict['logDF'])
# Prepare the output from parsing the Determine Basal from FreeAPS X
determBasalDF = loopReadDict['determBasalDF']
if not determBasalDF.empty:
# create a csv file but don't add unique user name/dates to it
thisOutFile = outFlag + '/' + 'determBasalDF_out.csv'
print(" *** Determine Basal csv file created: ", thisOutFile)
determBasalDF.to_csv(thisOutFile)
# until we get it updated, PC does not yet do plots
thisPlatform = platform.system()
if thisPlatform == 'Windows':
print("PC plots do not work yet, skip plots")
else:
# plot pandas dataframe containing detemine basal data
thisOutFile = generatePlot(outFlag, fileDict, determBasalDF)
print(' *** Determine Basal plot created: ', thisOutFile)
print('------------------------------------------\n')