-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathIngestQRevIntMSManager.py
More file actions
256 lines (199 loc) · 9.51 KB
/
Copy pathIngestQRevIntMSManager.py
File metadata and controls
256 lines (199 loc) · 9.51 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
import math
from xml.etree import ElementTree
import wx
from datetime import datetime as dt
def GetRoot(filePath):
return ElementTree.parse(filePath).getroot()
def GetStationID(filePath):
try:
channel = GetRoot(filePath)
stationID = channel.find('SiteInformation').find('SiteID').text
return stationID
except:
print("Unable to read the xml file")
return -1
def GetDate(filePath):
channel = GetRoot(filePath)
# find first vertical that has a StartDateTime field
date = channel.find('./VerticalDetails/Vertical/StartDateTime').text
#06/28/2016 08:31:36
dt = date[6:10] + "/" + date[:5]
return dt
#Summary
def GetArea(filePath):
return GetRoot(filePath).find('ChannelSummary').find('ChannelArea').text
def GetVelocity(filePath):
return GetRoot(filePath).find('ChannelSummary').find('MeanNormalVelocity').text
def GetDischarge(filePath):
return GetRoot(filePath).find('ChannelSummary').find('ChannelTotalQ').text
def GetWidth(filePath):
return GetRoot(filePath).find('ChannelSummary').find('ChannelWidth').text
def GetUncertainty(filePath):
return GetRoot(filePath).find('ChannelSummary').find('Uncertainty').find('Total').text
def GetStartTime(filePath):
# find first vertical that has a StartDateTime field
return GetRoot(filePath).find('./VerticalDetails/Vertical/StartDateTime').text[11:16]
def GetEndTime(filePath):
# find the vertical that has the oldest EndDateTime field
end_time = GetRoot(filePath).find('./VerticalDetails/Vertical/StartDateTime').text[11:16]
all_endtimes = GetRoot(filePath).findall('./VerticalDetails/Vertical/EndDateTime')
for item in all_endtimes:
time_text = item.text[11:16]
if dt.strptime(time_text, "%H:%M").time() > dt.strptime(end_time, "%H:%M").time():
end_time = time_text
return end_time
#Detail
def GetFirmware(filePath):
return GetRoot(filePath).find('Instrument').find('FirmwareVersion').text
def GetSerialNum(filePath):
return GetRoot(filePath).find('Instrument').find('SerialNumber').text
def GetSoftware(filePath):
return GetRoot(filePath).find('Processing').find('SoftwareVersion').text
def GetManufacturer(filePath):
return GetRoot(filePath).find('Instrument').find('Manufacturer').text
def GetModel(filePath):
return GetRoot(filePath).find('Instrument').find('Model').text
def GetFrequency(filePath):
return GetRoot(filePath).find('Instrument').find('Frequency').text
def GetFrequencyUnit(filePath):
return GetRoot(filePath).find('Instrument').find('Frequency').attrib['unitsCode']
def GetADCPDepth(filePath):
return GetRoot(filePath).find('VerticalDetails/Vertical/Processing/Depth/ADCPDepth').text
def GetDiagTest(filePath):
return GetRoot(filePath).find('QA').find('DiagnosticTestResult').text
def GetMagDeclination(filePath):
return GetRoot(filePath).find('VerticalDetails/Vertical/Processing/Navigation/MagneticVariation').text
#Calculate the mean time
def mean(start, end):
startHour = int(start.GetHourVal())
endHour = int(end.GetHourVal())
startMin = int(start.GetMinuteVal())
endMin = int(end.GetMinuteVal())
startSec = int(start.GetSecondVal())
endSec = int(end.GetSecondVal())
start = float(startHour * 3600 + startMin * 60 + startSec)
end = float(endHour * 3600 + endMin * 60 + endSec)
mean = round((start + end) / 2)
meanHour = int(mean / 3600)
meanMin = int(mean % 3600 / 60)
meanSec = int(mean % 3600 % 60)
# if (startHour + endHour)%2 != 0:
# endMin += 60
# if (startMin + endMin)%2 != 0:
# endSec += 60
# meanHour = (startHour + endHour) / 2
# meanMin = (startMin + endMin) / 2
# meanSec = (startSec + endSec) / 2
meanHour = str(meanHour) if meanHour > 9 else ("0" + str(meanHour))
meanMin = str(meanMin) if meanMin > 9 else ("0" + str(meanMin))
meanSec = str(meanSec) if meanSec > 9 else ("0" + str(meanSec))
meanTime = meanHour + ':' + meanMin + ':' + meanSec
return meanTime
def AddDischargeSummary(filePath, disMeasManager):
color = disMeasManager.manager.gui.importedBGColor
start = GetStartTime(filePath)
end = GetEndTime(filePath)
width = GetWidth(filePath)
area = GetArea(filePath)
vel = GetVelocity(filePath)
dis = GetDischarge(filePath)
uncert = str(round(float(GetUncertainty(filePath)), 2))
# water = GetWaterTemp(filePath)
disMeasManager.startTimeCtrl = start
disMeasManager.endTimeCtrl = end
if width is not None:
disMeasManager.widthCtrl = width
myEvent = wx.FocusEvent(eventType=wx.wxEVT_KILL_FOCUS, id=wx.NewId())
myEvent.SetEventObject(disMeasManager.GetWidthCtrl())
wx.PostEvent(disMeasManager.GetWidthCtrl(), myEvent)
disMeasManager.GetWidthCtrl().SetBackgroundColour(color)
if area is not None:
disMeasManager.areaCtrl = area
myEvent = wx.FocusEvent(eventType=wx.wxEVT_KILL_FOCUS, id=wx.NewId())
myEvent.SetEventObject(disMeasManager.GetAreaCtrl())
wx.PostEvent(disMeasManager.GetAreaCtrl(), myEvent)
disMeasManager.GetAreaCtrl().SetBackgroundColour(color)
if vel is not None:
disMeasManager.meanVelCtrl = vel
myEvent = wx.FocusEvent(eventType=wx.wxEVT_KILL_FOCUS, id=wx.NewId())
myEvent.SetEventObject(disMeasManager.GetMeanVelCtrl())
wx.PostEvent(disMeasManager.GetMeanVelCtrl(), myEvent)
disMeasManager.GetMeanVelCtrl().SetBackgroundColour(color)
if dis is not None:
disMeasManager.dischCtrl = dis
myEvent = wx.FocusEvent(eventType=wx.wxEVT_KILL_FOCUS, id=wx.NewId())
myEvent.SetEventObject(disMeasManager.GetDischCtrl())
wx.PostEvent(disMeasManager.GetDischCtrl(), myEvent)
disMeasManager.GetDischCtrl().SetBackgroundColour(color)
disMeasManager.manager.movingBoatMeasurementsManager.finalDischCtrl = dis
disMeasManager.manager.movingBoatMeasurementsManager.gui.finalDischCtrl.SetBackgroundColour(color)
if uncert is not None:
disMeasManager.uncertaintyCtrl = uncert
myEvent = wx.FocusEvent(eventType=wx.wxEVT_KILL_FOCUS, id=wx.NewId())
myEvent.SetEventObject(disMeasManager.GetUncertaintyCtrl())
wx.PostEvent(disMeasManager.GetUncertaintyCtrl(), myEvent)
disMeasManager.GetUncertaintyCtrl().SetBackgroundColour(color)
# Adding uncertainty text to Discharge Activity Remarks
dischargeUncertainty = '@ Uncertainty: QRev Uncertainty Analysis (DS Mueller, 2016), 2-sigma value (1 x Uncertainty Value reported in *.xml File). @'
dischargeRemarks = disMeasManager.dischRemarksCtrl
if dischargeRemarks != '':
disMeasManager.dischRemarksCtrl = dischargeRemarks + '\n' + dischargeUncertainty
else:
disMeasManager.dischRemarksCtrl = dischargeUncertainty
# if water is not None:
# disMeasManager.waterTempCtrl = water
# myEvent = wx.FocusEvent(eventType=wx.wxEVT_KILL_FOCUS, id=wx.NewId())
# myEvent.SetEventObject(disMeasManager.GetWaterTempCtrl())
# wx.PostEvent(disMeasManager.GetWaterTempCtrl(), myEvent)
# disMeasManager.GetWaterTempCtrl().SetBackgroundColour(color)
disMeasManager.gui.Refresh()
# disMeasManager.GetStartTimeCtrl().SetBackgroundColour(color)
def AddDischargeDetail(filePath, instrDepManager):
color = instrDepManager.manager.gui.importedBGColor
diagTest = GetDiagTest(filePath)
depth = GetADCPDepth(filePath)
magDeclination = GetMagDeclination(filePath)
serialNum = GetSerialNum(filePath)
manufacturer = GetManufacturer(filePath)
model = GetModel(filePath)
frequency = GetFrequency(filePath)
freUnit = GetFrequencyUnit(filePath)
firmware = GetFirmware(filePath)
software = GetSoftware(filePath)
if diagTest is not None:
if diagTest.lower() == "pass":
instrDepManager.GetDiagTestCB().SetValue(True)
else:
instrDepManager.GetDiagTestCB().SetValue(False)
instrDepManager.GetDiagTestCB().SetBackgroundColour(color)
if depth is not None and instrDepManager.GetDeploymentCmbo().GetValue() != "Ice Cover":
instrDepManager.adcpDepthCtrl = depth
instrDepManager.GetAdcpDepthCtrl().SetBackgroundColour(color)
if magDeclination is not None:
instrDepManager.magnDeclCtrl = magDeclination
instrDepManager.GetMagnDeclCtrl().SetBackgroundColour(color)
if serialNum is not None:
instrDepManager.serialCmbo = serialNum
instrDepManager.GetSerialCmbo().SetBackgroundColour(color)
if manufacturer is not None:
instrDepManager.manufactureCmbo = manufacturer
instrDepManager.GetManufactureCmbo().SetBackgroundColour(color)
if model is not None:
instrDepManager.modelCmbo = model
instrDepManager.GetModelCmbo().SetBackgroundColour(color)
if frequency is not None:
if frequency == 'Multi':
instrDepManager.frequencyCmbo = frequency
else:
if freUnit is not None:
if "m" in freUnit.lower():
# frequency = str(float(frequency) * 1000)
frequency += "000"
instrDepManager.frequencyCmbo = str(math.trunc(float(frequency)))
instrDepManager.GetFrequencyCmbo().SetBackgroundColour(color)
if firmware is not None:
instrDepManager.firmwareCmbo = firmware
instrDepManager.GetFirmwareCmbo().SetBackgroundColour(color)
if software is not None:
instrDepManager.softwareCtrl = software
instrDepManager.GetSoftwareCtrl().SetBackgroundColour(color)