예제 #1
0
 def set(self):
     pipe = db0.pipeline()
     pipe.zremrangebyrank(
         ConstDB0.dev_gateways + hexlify(self.dev_eui).decode(), 0, -1)
     pipe.zadd(ConstDB0.dev_gateways + hexlify(self.dev_eui).decode(),
               self.cal_score(), self.gateway_mac_addr)
     pipe.execute()
예제 #2
0
    def save(self):
        try:
            app_eui = hexlify(
                db0.hget(self.category + self.eui, ConstDB0.app_eui)).decode()
        except TypeError as e:
            Logger.warning(action='MsgDn',
                           type=IDType.app,
                           id=self.category + self.eui,
                           msg=str(e))
            app_eui = self.eui.split(':')[0]

        key = ConstDB0.msg_down + self.category + \
            self.eui + ':' + str(round(self.ts))
        pipe = db0.pipeline()
        pipe.hmset(key, self.__obj_to_dict())
        pipe.expire(key, ConstMsg.EXPIRE_MSG)
        pipe.publish(Channel0.msg_alarm + app_eui, key)
        pipe.execute()
        self.__count_statistics_down()

        key = ConstDB2.dn_m + self.category + \
            self.eui + ':' + str(round(self.ts))
        pipe = db2.pipeline()
        info = {ConstMsg.fcnt: self.fcnt}
        if hasattr(self, ConstMsg.gateways):
            if isinstance(self.gateways, bytes):
                info[ConstMsg.gateways] = hexlify(self.gateways).decode()
            elif isinstance(self.gateways, list):
                info[ConstMsg.gateways] = ';'.join(
                    map(bytes_to_hexstr, self.gateways))
        pipe.hmset(key, info)
        pipe.expire(key, ConstMsg.EXPIRE_STATIS)
        pipe.publish(Channel0.dn_alarm + app_eui, key)
        pipe.execute()
예제 #3
0
    def save(self):
        """
        :param msg: MsgUp
        :return: None
        """
        dev_eui = hexlify(self.dev_eui).decode()
        app_eui = hexlify(db0.hget(ConstDB0.dev + dev_eui,
                                   FieldDevice.app_eui)).decode()
        key = ConstDB0.msg_up + app_eui + ':' + dev_eui + ':' + str(self.ts)
        pipe = db0.pipeline()
        pipe.hmset(key, self.__obj_to_dict())
        pipe.sadd(ConstDB0.mset + dev_eui, self.ts)
        pipe.expire(key, ConstMsg.EXPIRE_MSG)
        pipe.publish(Channel0.msg_alarm + app_eui, key)
        pipe.execute()
        self._count_statistics_up()

        pipe = db2.pipeline()
        if self.restart:
            cur_ts = self.ts
            pipe.rpush(ConstDB2.up_l_l + dev_eui, str(self.ts))
        else:
            cur_ts = db2.lindex(ConstDB2.up_l_l + dev_eui, -1)
            if cur_ts:
                cur_ts = int(cur_ts)
            else:
                cur_ts = self.ts
                pipe.rpush(ConstDB2.up_l_l + dev_eui, str(self.ts))
        pipe.rpush(ConstDB2.up_l + dev_eui + ':%s' % cur_ts, self.ts)
        key = ConstDB2.up_m + dev_eui + ':%s' % self.ts
        pipe.hmset(key, self.obj_to_dict())
        pipe.expire(key, ConstMsg.EXPIRE_STATIS)
        pipe.publish(Channel0.up_alarm + app_eui, key)
        pipe.execute()
예제 #4
0
 def __count_statistics_down(self):
     time_now = datetime.now()
     key = ConstDB0.statistics_down + self.category + \
         self.eui + ':' + time_now.strftime("%Y-%m-%d")
     pipe = db0.pipeline()
     pipe.hincrby(key, time_now.hour)
     pipe.expire(key, ConstMsg.EXPIRE_STATIS)
     pipe.execute()
예제 #5
0
 def frequency_statistics(self, freq_plan):
     """
     :param eui: DEV:hex string or GROUP:hex string
     :return:
     """
     time_now = datetime.now()
     key = ConstDB0.statistics_freq + hexlify(self.mac_addr).decode(
     ) + ':' + time_now.strftime("%Y-%m-%d") + ':' + str(time_now.hour)
     pipe = db0.pipeline()
     pipe.hincrby(key, freq_plan)
     pipe.expire(key, 30 * 86400)
     pipe.execute()
예제 #6
0
 def set_value(self, **kwargs):
     pipe = db0.pipeline()
     for name, value in kwargs.items():
         if name in DevInfo.fields:
             pipe.hset(self.key, name, value)
         else:
             Logger.error(action=Action.mac_cmd_get,
                          type=IDType.dev_info,
                          id=hexlify(self.dev_eui).decode(),
                          msg='DevInfo set_value unknow name:' % name)
             return
     pipe.execute()
예제 #7
0
 def p_to_c(self, *args):
     pipe = db0.pipeline()
     for arg in args:
         value = db0.hget(self.key, 'p_' + arg)
         if value is not None:
             pipe.hset(self.key, arg, value)
             pipe.hdel(self.key, 'p_' + arg)
         else:
             Logger.error(action=Action.mac_cmd_send,
                          type=IDType.dev_info,
                          id=hexlify(self.dev_eui).decode(),
                          msg='No P value can be set to C: %s' % arg)
             return
     pipe.execute()
예제 #8
0
 def _count_statistics_up(self):
     """
     :param eui: DEV:hex string or GROUP:hex string
     :return:
     """
     time_now = datetime.now()
     pipe = db0.pipeline()
     key = ConstDB0.statistics_up + \
         hexlify(self.dev_eui).decode() + ':' + \
         time_now.strftime("%Y-%m-%d")
     pipe.hincrby(key, time_now.hour)
     pipe.expire(key, ConstMsg.EXPIRE_STATIS)
     if self.retrans:
         key = ConstDB0.statistics_retrans + \
             hexlify(self.dev_eui).decode() + ':' + \
             time_now.strftime("%Y-%m-%d")
         pipe.hincrby(key, time_now.hour)
         pipe.expire(key, ConstMsg.EXPIRE_STATIS)
     pipe.execute()
예제 #9
0
    def save(self):
        hex_mac_addr = hexlify(self.gateway_mac_addr).decode()
        hex_dev_eui = hexlify(self.dev_eui).decode()
        pipe = db0.pipeline()
        key = ConstDB0.trans_params + hex_dev_eui + ':' + hex_mac_addr
        pipe.delete(key)
        pipe.hmset(key, self.trans_params)
        pipe.execute()

        pipe = db2.pipeline()
        key = ConstDB2.up_t + hex_dev_eui + ':' + hex_mac_addr + ':' + str(
            self.ts)
        pipe.rpush(ConstDB2.up_gateway + hex_mac_addr, self.ts)
        pipe.hmset(key, self.trans_params)
        s_key = ConstDB2.up_gw_s + hex_dev_eui + ':%s' % self.ts
        score = float(self.trans_params['rssi']) + float(
            self.trans_params['lsnr']) * 0.25
        pipe.zadd(s_key, score, hex_mac_addr)
        pipe.expire(key, ConstMsg.EXPIRE_STATIS)
        pipe.expire(s_key, ConstMsg.EXPIRE_STATIS)
        pipe.execute()