Example #1
0
 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 
Example #2
0
    def jsonToSensorData(self, jsonData):
        sdDict = json.loads(jsonData)

        #print(" decode [pre] --> " + str(sdDict))

        sd = SensorData("Temperature Sensor", 0.0, 30.0)
        sd.name = sdDict['name']
        sd.timeStamp = sdDict['time']
        sd.avgValue = sdDict['avgValue']
        sd.minValue = sdDict['minValue']
        sd.maxValue = sdDict['maxValue']
        sd.curValue = sdDict['curValue']

        #print(" decode [post] --> " + str(sd))

        return sd
Example #3
0
 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
Example #4
0
    def toSensorDataFromJson(self, jsonStr) -> SensorData:

        #instantiate SensorData
        sensorData = SensorData()

        #use json load to convert it to a dictionary
        jsonLoad = json.loads(jsonStr)

        #parse and add it to the sensorData object one by one
        sensorData.currentValue = jsonLoad["currentValue"]
        sensorData.average = jsonLoad["average"]
        sensorData.totalCount = jsonLoad["totalCount"]
        sensorData.minValue = jsonLoad["minValue"]
        sensorData.maxValue = jsonLoad["maxValue"]
        sensorData.totalValue = jsonLoad["totalValue"]
        sensorData.sensorName = jsonLoad["sensorName"]
        sensorData.timeStamp = jsonLoad["timestamp"]

        #return the SensorData  reference
        return sensorData