def toSensorDataFromJson(self, jsonData): sdDict = json.loads(jsonData) sd = SensorData() sd.name = sdDict['name'] sd.timeStamp = sdDict['timeStamp'] sd.avgValue = sdDict['avgValue'] sd.minValue = sdDict['minValue'] sd.maxValue = sdDict['maxValue'] sd.curValue = sdDict['curValue'] sd.totValue = sdDict['totValue'] sd.sampleCount = sdDict['sampleCount'] return sd
def jsonTosensor(self,jsonData): sensedataDict = json.loads(jsonData) print(" decode [pre] --> " + str(sensedataDict)) sensedata = SensorData('Temperature',0,30) sensedata.name = sensedataDict['name'] sensedata.timeStamp = sensedataDict['timeStamp'] sensedata.avgVal = sensedataDict['avgVal'] sensedata.minVal = sensedataDict['minVal'] sensedata.maxVal = sensedataDict['maxVal'] sensedata.curVal = sensedataDict['curVal'] sensedata.totValue = sensedataDict['totValue'] sensedata.sampleCount = sensedataDict['sampleCount'] print(" decode [post] --> " + str(sensedata)) return sensedata
def toSensorDataFromJson(self,jsonData): sdDict = json.loads(jsonData) print(" decode [pre] --> " + str(sdDict)) sd = SensorData() sd.name = sdDict['name'] sd.timeStamp = sdDict['timeStamp'] sd.avgValue = sdDict['avgValue'] sd.minValue = sdDict['minValue'] sd.maxValue = sdDict['maxValue'] sd.curValue = sdDict['curValue'] sd.totValue = sdDict['totValue'] sd.sampleCount = sdDict['sampleCount'] print(" decode [post] --> " + str(sd)) return sd