Example #1
0
class JsonReqMsg(object):
    '''
    Data structure for parsed JSON messages with print() testing feature.
    '''
    
    prsd = None
    
    def __init__(self):
        '''
        Constructor
        '''
        self.parser = DataParser()
        
    def parseMsg(self, rcvd):
        
        try:
            JsonReqMsg.prsd = self.parser.parseData(rcvd)   
            JsonReqMsg.org = JsonReqMsg.prsd.get('org_name')
            JsonReqMsg.device = JsonReqMsg.prsd.get("dev_name")
            JsonReqMsg.code = JsonReqMsg.prsd.get("code")
            
            JsonReqMsg.description = JsonReqMsg.prsd.get("desc")


        except:
            print(traceback.format_exc())
            print("JSON parsing failed.")          
    
    def _getMsg(self):
        return JsonReqMsg.prsd
    
    def printMsg(self):
        
        print("\n Org name: %s\n Ddevice name:  %s\n conf_code: %s\n desc: %s\n" 
          % (
             str(JsonReqMsg.org),
             str(JsonReqMsg.device),
             str(JsonReqMsg.code),
             str(JsonReqMsg.description)
            ) 
        )
        
        print("\n keys: %s\n" % str(JsonReqMsg.prsd.keys()))
Example #2
0
class JsonConfMsg(object):
    '''
    Data structure for parsed JSON messages with print() testing feature.
    ''' 
    prsd = None
    
    def __init__(self):
        '''
        Constructor
        '''       
        self.parser = DataParser()
        self.REQ = 'request'
         
    def parseMsg(self, rcvd):
        
        try:

            JsonConfMsg.prsd = self.parser.parseData(rcvd)
            
            JsonConfMsg.mtr_point = JsonConfMsg.prsd.get('meteringPointId')        
            JsonConfMsg.request_type = JsonConfMsg.prsd.get(self.REQ)
           
        except:
            print(traceback.format_exc())
            print("JSON parsing failed.")
            
    def _getMsg(self):
        return JsonConfMsg.prsd
    
    def printMsg(self):
        
        print("\n In JsonConf, metering point id: %s\n request type:  %s\n" 
          % (
             str(JsonConfMsg.mtr_point),
             str(JsonConfMsg.request_type)
            ) 
        )
        
        print("\n keys: %s\n" % str(JsonConfMsg.prsd.keys()))
Example #3
0
class JsonMsg(object):
    '''
    Data structure for parsed JSON messages with print() testing feature.
    '''
    prsd = None
    
    def __init__(self):
        '''
        Constructor
        '''    
        self.parser = DataParser()
      
    def parseMsg(self, rcvd):
        '''
        Parsing incoming JSON messages through DataParser and building up the data structure. 
        '''
        try:
            
            JsonMsg.prsd = self.parser.parseData(rcvd)
            
            JsonMsg.devices = JsonMsg.prsd['devices']
            for device in JsonMsg.devices:
        
                JsonMsg.metering_point_id = device.get("meteringPointId")
                JsonMsg.device_id = device.get("deviceId")
                JsonMsg.description = device.get("description")
                JsonMsg.privacy = device.get("privacy")
                
                for measurement in device["measurements"]["values"]:
                    JsonMsg.timestamp = measurement.get("timestamp")
                    JsonMsg.value = measurement.get("value")
                    JsonMsg.error = measurement.get("error")
            
                JsonMsg.latitude = device["location"].get('latitude')
                JsonMsg.longitude = device["location"].get("longitude")
                JsonMsg.loc_name = device["location"].get("name")             
#
        except:
            print(traceback.format_exc())
            print("JSON parsing failed.")
            
    def _getMsg(self):
        return JsonMsg.prsd
    
    def printMsg(self):
        '''
        For testing purposes
        '''
        print("\n metering point id: %s\n device id:  %s\n privacy: %s\n timestamp: %s\n latitude: %s\n longitude: %s\n name: %s\n description: %s\n " 
          % (
             str(JsonMsg.metering_point_id),
             str(JsonMsg.device_id),
             str(JsonMsg.privacy),
             str(JsonMsg.timestamp),
             str(JsonMsg.latitude),
             str(JsonMsg.longitude),
             str(JsonMsg.loc_name),
             str(JsonMsg.description)
            ) 
        )
        
        print("\n keys: %s\n" % str(JsonMsg.prsd.keys()))
Example #4
0
 def __init__(self):
     '''
     Constructor
     '''    
     self.parser = DataParser()
Example #5
0
 def __init__(self):
     '''
     Constructor
     '''       
     self.parser = DataParser()
     self.REQ = 'request'