-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmain.py
More file actions
134 lines (118 loc) · 6.07 KB
/
main.py
File metadata and controls
134 lines (118 loc) · 6.07 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
from parsers.loop_read_file 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 = 30
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)
personDateSuffix = fileDict['person'] + '_' + fileDict['date'] + '.csv'
# Print csv output for determTddDF_old, determTddDF_tcd
determTddDF_old = loopReadDict['determTddDF_old']
if not determTddDF_old.empty:
# create a csv file with unique user name/dates
thisOutFile = outFlag + '/' + 'TDD_old_' + personDateSuffix
print(" *** determTddDF_old csv file created: ", thisOutFile)
determTddDF_old.to_csv(thisOutFile)
determTddDF_tcd = loopReadDict['determTddDF_tcd']
if not determTddDF_tcd.empty:
# create a csv file with unique user name/dates
thisOutFile = outFlag + '/' + 'TDD_tcd' + '_' + personDateSuffix
print(" *** determTddDF_tcd csv file created: ", thisOutFile)
determTddDF_tcd.to_csv(thisOutFile)
print('------------------------------------------\n')