Browse code

revisions 11-16-2018

fractalxaos authored on 11/16/2018 19:15:09
Showing 1 changed files
... ...
@@ -34,10 +34,10 @@
34 34
 #   * v21 released 27 Nov 2017 by J L Owrey; bug fixes; updates
35 35
 #   * v22 released 03 Mar 2018 by J L Owrey; improved code readability;
36 36
 #         improved radmon device offline status handling
37
-#   * v23 released 15 Nov 2018 by J L Owrey; improved system fault
38
-#         handling and radiation monitor offline handling
37
+#   * v23 released 16 Nov 2018 by J L Owrey: improved fault handling
38
+#         and data conversion
39 39
 
40
-_MIRROR_SERVER = True
40
+_MIRROR_SERVER = False
41 41
 
42 42
 import os
43 43
 import urllib2
... ...
@@ -53,9 +53,10 @@ _USER = os.environ['USER']
53 53
    ### DEFAULT RADIATION MONITOR URL ###
54 54
 
55 55
 # ip address of radiation monitoring device
56
-_DEFAULT_RADIATION_MONITOR_URL = "{your radiation monitor url}"
56
+_DEFAULT_RADIATION_MONITOR_URL = "http://192.168.1.24"
57 57
 # url if this is a mirror server
58
-_PRIMARY_SERVER_URL = "{your primary server url}"
58
+_PRIMARY_SERVER_URL = "http://73.157.139.23:7361" \
59
+                      "/~pi/radmon/dynamic/radmonInputData.dat"
59 60
 
60 61
     ### FILE AND FOLDER LOCATIONS ###
61 62
 
... ...
@@ -243,15 +244,10 @@ def convertData(dData):
243 244
         #dData['ELT'] = time.time()
244 245
         
245 246
         dData['Mode'] = dData['Mode'].lower()
246
- 
247
-        dData['uSvPerHr'] = float(dData.pop('uSv/hr'))
248
-        
249
-        dData['CPM'] = int(dData.pop('CPM'))
250
-
251
-        dData['CPS'] = int(dData.pop('CPS'))
247
+        dData['uSvPerHr'] = '%.2f' % float(dData.pop('uSv/hr'))
252 248
 
253 249
     except Exception, exError:
254
-        print "%s convert data failed: %s" % (getTimeStamp(), exError)
250
+        print "%s data conversion failed: %s" % (getTimeStamp(), exError)
255 251
         result = False
256 252
 
257 253
     return result
... ...
@@ -268,14 +264,14 @@ def writeOutputDataFile(dData):
268 264
     # Set date to current time and data
269 265
     dData['date'] = time.strftime("%m/%d/%Y %T", time.localtime(dData['ELT']))
270 266
 
267
+    dTemp = dict(dData)
268
+    dTemp.pop('ELT')
269
+    dTemp.pop('UTC')
270
+    
271 271
     # Format the weather data as string using java script object notation.
272 272
     sData = '[{'
273
-    sData += "\"date\":\"%s\"," % dData['date']
274
-    sData += "\"CPM\":\"%d\"," % dData['CPM']
275
-    sData += "\"CPS\":\"%d\"," % dData['CPS']
276
-    sData += "\"uSvPerHr\":\"%.2f\"," % dData['uSvPerHr']
277
-    sData += "\"Mode\":\"%s\"," % dData['Mode']
278
-    sData += "\"status\":\"%s\"," % dData['status']
273
+    for key in dTemp:
274
+        sData += '\"%s\":\"%s\",' % (key, dData[key])
279 275
     sData = sData[:-1] + '}]\n'
280 276
 
281 277
     # Write the string to the output data file for use by html documents.
... ...
@@ -304,7 +300,7 @@ def writeInputDataFile(sData):
304 300
         fc.write(sData)
305 301
         fc.close()
306 302
     except Exception, exError:
307
-        print "%s writeOutputDataFile: %s" % (getTimeStamp(), exError)
303
+        print "%s writeInputDataFile: %s" % (getTimeStamp(), exError)
308 304
         return False
309 305
 
310 306
     return True
... ...
@@ -344,7 +340,7 @@ def updateDatabase(dData):
344 340
     global remoteDeviceReset
345 341
 
346 342
     # The RR database stores whole units, so convert uSv to Sv.
347
-    SvPerHr = dData['uSvPerHr'] * 1.0E-06 
343
+    SvPerHr = float(dData['uSvPerHr']) * 1.0E-06 
348 344
 
349 345
     # Create the rrdtool update command.
350 346
     strCmd = "rrdtool update %s %s:%s:%s" % \