From 84480e7b26adcb41f503de7e3b04e6c399cd39ef Mon Sep 17 00:00:00 2001 From: Bernhard Tittelbach Date: Wed, 9 Oct 2013 23:00:07 +0000 Subject: [PATCH] --bugs --- sensorvalues-to-json-zmq.py | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/sensorvalues-to-json-zmq.py b/sensorvalues-to-json-zmq.py index e2ed5d6..bf71013 100755 --- a/sensorvalues-to-json-zmq.py +++ b/sensorvalues-to-json-zmq.py @@ -162,40 +162,43 @@ def exitHandler(signum, frame): sys.exit(0) time_column_name_="Time" -lastest_values_ = {} +latest_values_ = {} sensor_store_ = {} sensor_cols_num_ = {} #stores number of columns for a sensor not counting Time (x-axis) column. AKA the number of data-rows. Equals highest SensorIndex +1 reset_these_structnames_ = {} def addEventToTempLastValueStore(structname, msgdata): - global lastest_values_ + global latest_values_ sensorindex = msgdata["Sensorindex"] if "Sensorindex" in msgdata else 0 - if not structname in lastest_values_: - lastest_values_[structname]=[] + 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(lastest_values_[structname]) < sensor_cols_num_[structname]: - lastest_values_[structname] += [0] * (sensor_cols_num_[structname] - len(lastest_values_[structname])) + 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 dictdata["Sensorindex"] - del dictdata["Ts"] + 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 - lastest_values_[structname][sensorindex] = msgdata.values()[0] + latest_values_[structname][sensorindex] = msgdata.values()[0] else: #if that value does not exist, (i.e. movementevent), count event occurances - lastest_values_[structname][sensorindex] += 1 + latest_values_[structname][sensorindex] += 1 reset_these_structnames_[structname] = True def cleanTempLastValueOfMovementValues(): - global lastest_values_ + global latest_values_ for k in reset_these_structnames_.keys(): - lastest_values_[k] = [0] * sensor_cols_num_[structname] + latest_values_[k] = [0] * sensor_cols_num_[structname] def expandSensorStoreLists(structname, newlength): @@ -215,7 +218,7 @@ def expandSensorStoreLists(structname, newlength): def addEventsToStore(): global sensor_store_ ts = int(time.time()) - for structname in lastest_values_.keys(): + for structname in latest_values_.keys(): if not structname in sensor_store_: sensor_store_[structname]=[] @@ -224,7 +227,7 @@ def addEventsToStore(): sensor_store_[structname].insert(0,[time_column_name_] + list(map(str,range(0,sensor_cols_num_[structname])))) # add values - sensor_store_[structname].append([ts] + lastest_values_[structname]) + sensor_store_[structname].append([ts] + latest_values_[structname]) #cap list lenght if uwscfg.json_limit_list_len: @@ -291,7 +294,7 @@ if __name__ == "__main__": addEventToTempLastValueStore(structname, dictdata) - logging.debug("lastdata:"+str(lastest_values_)) + logging.debug("lastdata:"+str(latest_values_)) if int(time.time()) - last_update < int(uwscfg.json_updateinterval): continue -- 1.7.10.4