bugfixes. finally works
authorBernhard Tittelbach <xro@realraum.at>
Thu, 10 Oct 2013 02:29:08 +0000 (02:29 +0000)
committerBernhard Tittelbach <xro@realraum.at>
Thu, 10 Oct 2013 02:29:08 +0000 (02:29 +0000)
sensorvalues-to-json-zmq.py

index bf71013..fa6e7f5 100755 (executable)
@@ -169,7 +169,7 @@ reset_these_structnames_ = {}
 
 def addEventToTempLastValueStore(structname, msgdata):
     global latest_values_
-    sensorindex = msgdata["Sensorindex"] if "Sensorindex" in msgdata else 0
+    sensorindex = int(msgdata["Sensorindex"]) if "Sensorindex" in msgdata else 0
     if not structname in latest_values_:
         latest_values_[structname]=[]
     if not structname in sensor_cols_num_ or sensor_cols_num_[structname] < sensorindex +1:
@@ -198,7 +198,7 @@ def addEventToTempLastValueStore(structname, msgdata):
 def cleanTempLastValueOfMovementValues():
     global latest_values_
     for k in reset_these_structnames_.keys():
-        latest_values_[k] = [0] * sensor_cols_num_[structname]
+        latest_values_[k] = [0] * sensor_cols_num_[k]
 
 
 def expandSensorStoreLists(structname, newlength):
@@ -208,11 +208,12 @@ def expandSensorStoreLists(structname, newlength):
     #remove old headings so we can add them again below
     try:
         if sensor_store_[structname][0][0] == time_column_name_:
-            sensor_store_[structname][0].pop(0)
+            sensor_store_[structname].pop(0)
     except:
         pass
     #expand all previous value lists
-    sensor_store_[structname] = map(lambda l: l + ([0] * (newlength +1 - len(l)))  , sensor_store_[structname])
+    newlength_including_time = newlength +1
+    sensor_store_[structname] = map(lambda l: l[:newlength_including_time] + ([0] * (newlength_including_time - len(l)))  , sensor_store_[structname])
 
 
 def addEventsToStore():
@@ -224,7 +225,7 @@ def addEventsToStore():
 
         #if missing, add Header List [Time, 0, 1, 2]
         if len(sensor_store_[structname]) == 0 or len(sensor_store_[structname][0]) < 2 or sensor_store_[structname][0][0] != time_column_name_:
-            sensor_store_[structname].insert(0,[time_column_name_] + list(map(str,range(0,sensor_cols_num_[structname]))))
+            sensor_store_[structname].insert(0,[time_column_name_] + list(map(lambda n: "Sensor %d"%n,range(0,sensor_cols_num_[structname]))))
 
         # add values
         sensor_store_[structname].append([ts] + latest_values_[structname])
@@ -303,6 +304,7 @@ if __name__ == "__main__":
 
             addEventsToStore()
             cleanTempLastValueOfMovementValues()
+            logging.debug("post-cleanMovement lastdata:"+str(latest_values_))
 
             backup_counter += 1
             # save sensor_store_ to json for apache