示例#1
0
    def _initData(self):
#         sql = "select dev_name,dev_id,dev_type from devices where session_name = %s and dev_type = 'infrared'"
        sql = "select dev_name,dev_id,dev_type from devices where session_name = %s"
        devices = self._sqlConnection.query(sql, self._session_name)
        for device in devices :
            self._dev_dict[device['dev_id']] = self.device_dict[device['dev_type']]()
            self._devname_dict[device['dev_name']] = device['dev_id']
            self._devid_dict[device['dev_id']] = device['dev_name']
            self._cycleCmd.update({device['dev_id'] : self.device_dict[device['dev_type']].genPratrolInstr(device['dev_id'])})
#             print self._cycleCmd
            sql = 'select * from data_constraints where dev_name = %s and link_flag = 0'
            datas = self._sqlConnection.query(sql,device['dev_name'])
            for data in datas :
                constraint = dataConstraint(data['state'], data['min_variation'], data['min_val'],data['max_val'])
                dataitem = devBaseData(data['data_name'],constraint, 0, None)
                self._dev_dict[device['dev_id']].addDataItem(data['conf_name'],dataitem)
                if data["algorithm"] is not None :
                    self._dev_dict[device['dev_id']].addAlgorithm(data['conf_name'], data["algorithm"])
            sql = 'select * from data_constraints where dev_name = %s and link_flag = 1'
            datas = self._sqlConnection.query(sql,device['dev_name'])
            for data in datas :
                constraint = dataConstraint(data['state'], data['min_variation'], data['min_val'],data['max_val'])
                dataitem = devBaseData(data['data_name'],constraint, 0, None)
                if device['dev_type'] == 'plc' or device['dev_type'] == 'mokuai' :
                    sql =  'select link_key,link_type,link_para1 from data_links where conf_name = %s and dev_name = %s'
                    data_links = self._sqlConnection.query(sql,data['conf_name'],device['dev_name'])
                else :
                    sql = 'select link_key,link_type,link_para1 from conf_links where conf_name = %s'
                    data_links = self._sqlConnection.query(sql,data['conf_name'])
                    for data_link in data_links : 
                        if data_link['link_type'] == 'error' :
                            self._dev_dict[device['dev_id']].addExceptDataItem(data['conf_name'],dataitem,data_link['link_key'])
                        elif data_link['link_type'] == 'average' :
                            self._dev_dict[device['dev_id']].addAverageDataItem(data['conf_name'],dataitem,data_link['link_key'],data_link['link_para1'])
示例#2
0
 def _initData(self):
     sql = "select dev_name,dev_id,dev_type from devices where session_name = %s and dev_type = 'voc'"
     devices = self._sqlConnection.query(sql, self._session_name)
     for device in devices :
         self._set.update({device['dev_id'] : self.device_dict[device['dev_type']]()})
         self._cycleCmd.extend(self.device_dict[device['dev_type']].genPratrolInstr(device['dev_id']))
         print self._cycleCmd
         sql = 'select * from data_constraints where dev_name = %s'
         datas = self._sqlConnection.query(sql,device['dev_name'])
         for data in datas :
             constraint = dataConstraint(data['state'], data['min_variation'], data['min_val'],data['max_val'])
             dataitem = devBaseData(data['data_name'],constraint)
             if data['link_flag'] == 0 :
                 self._set[device['dev_id']].addDataItem(data['conf_name'],dataitem)
             else :
                 data_links = None
                 if device['dev_type'] == 'plc' or device['dev_type'] == 'mokuai' :
                     sql =  'select link_key,link_type,link_para1 from data_links where conf_name = %s and dev_name = %s'
                     data_links = self._sqlConnection.query(sql,data['conf_name'],device['dev_name'])
                 else :
                     sql = 'select link_key,link_type,link_para1 from conf_links where conf_name = %s'
                     data_links = self._sqlConnection.query(sql,data['conf_name'])
                 for data_link in data_links : 
                     if data_link['link_type'] == 'error' :
                         self._set[device['dev_id']].addExceptDataItem(data['data_name'],constraint,data_link['link_key'])
                     elif data_link['link_type'] == 'average' :
                         self._set[device['dev_id']].addAverageDataItem(data['data_name'],constraint,data_link['link_key'],data_link['link_para1'])