+def addEventToTempLastValueStore(structname, msgdata):
+ global latest_values_
+ 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:
+ sensor_cols_num_[structname] = sensorindex +1
+ if len(latest_values_[structname]) < sensor_cols_num_[structname]:
+ latest_values_[structname] += [0] * (sensor_cols_num_[structname] - len(latest_values_[structname]))
+ expandSensorStoreLists(structname, sensor_cols_num_[structname])
+ # store Value in temp last value store:
+ try:
+ del msgdata["Sensorindex"]
+ except:
+ pass
+ try:
+ del msgdata["Ts"]
+ except:
+ pass
+ if len(msgdata) > 0:
+ #store first value that is not Sensorindex or Ts into store
+ latest_values_[structname][sensorindex] = msgdata.values()[0]
+ else:
+ #if that value does not exist, (i.e. movementevent), count event occurances
+ latest_values_[structname][sensorindex] += 1
+ reset_these_structnames_[structname] = True
+
+
+def cleanTempLastValueOfMovementValues():
+ global latest_values_
+ for k in reset_these_structnames_.keys():
+ latest_values_[k] = [0] * sensor_cols_num_[k]
+
+
+def expandSensorStoreLists(structname, newlength):
+ global sensor_store_
+ if not structname in sensor_store_:
+ sensor_store_[structname]=[]
+ #remove old headings so we can add them again below
+ try:
+ if sensor_store_[structname][0][0] == time_column_name_:
+ sensor_store_[structname].pop(0)
+ except:
+ pass
+ #expand all previous value lists
+ 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():
+ global sensor_store_
+ ts = int(time.time())
+ for structname in latest_values_.keys():
+ if not structname in sensor_store_:
+ sensor_store_[structname]=[]
+
+ #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(lambda n: "Sensor %d"%n,range(0,sensor_cols_num_[structname]))))
+
+ # add values
+ try:
+ # if latest values are identical, just update timestamp
+ if sensor_store_[structname][-1][1:] == latest_values_[structname] and sensor_store_[structname][-1][1:] == sensor_store_[structname][-2][1:]:
+ sensor_store_[structname].pop()
+ except:
+ pass
+ sensor_store_[structname].append([ts] + latest_values_[structname])
+
+ #cap list lenght
+ if uwscfg.json_limit_list_len:
+ if len(sensor_store_[structname]) > uwscfg.json_limit_list_len:
+ sensor_store_[structname] = sensor_store_[structname][- uwscfg.json_limit_list_len:]
+
+
+if __name__ == "__main__":
+ #signal.signal(signal.SIGTERM, exitHandler)
+ signal.signal(signal.SIGINT, exitHandler)
+ signal.signal(signal.SIGQUIT, exitHandler)
+
+ logging.info("%s started" % os.path.basename(sys.argv[0]))