Example #1
0
def account_decline():
    page = request.args.get('page')
    limit = request.args.get('limit')
    alias_name = request.args.get("acc_name")
    ca_data = cache.get('finance_decline_data')
    if not ca_data:
        data = SqlDataNative.bento_alltrans()
        acc_sum_trans = dict()
        for i in data:
            cus = i.get('before_balance')
            if cus not in acc_sum_trans:
                cus_dict = dict()
                cus_dict[cus] = {'decl': 0, 't_data': 0, 'three_decl': 0, 'three_tran': 0}
                acc_sum_trans.update(cus_dict)
        for n in data:
            date = n.get('date')
            do_type = n.get('do_type')
            cus = n.get('before_balance')
            value = {'t_data': acc_sum_trans.get(cus).get('t_data') + 1}
            acc_sum_trans.get(cus).update(value)
            if do_type == 'DECLINED':
                value = {'decl': acc_sum_trans.get(cus).get('decl') + 1}
                acc_sum_trans.get(cus).update(value)
            today_time = time.strftime('%Y-%m-%d', time.localtime(time.time()))
            max_today = datetime.datetime.strptime("{} {}".format(change_today(today_time, 0), "23:59:59"),
                                                   '%Y-%m-%d %H:%M:%S')
            min_today = datetime.datetime.strptime("{} {}".format(change_today(today_time, -3), "23:59:59"),
                                                   '%Y-%m-%d %H:%M:%S')
            trans_t = datetime.datetime.strptime(date, '%Y-%m-%d %H:%M:%S')
            if min_today <= trans_t <= max_today:
                value = {'three_tran': acc_sum_trans.get(cus).get('three_tran') + 1}
                acc_sum_trans.get(cus).update(value)
            if min_today < trans_t < max_today and do_type == 'DECLINED':
                value = {'three_decl': acc_sum_trans.get(cus).get('three_decl') + 1}
                acc_sum_trans.get(cus).update(value)
        res = list()
        for n in acc_sum_trans:
            value = acc_sum_trans.get(n)
            value['alias'] = n
            value['all_bili'] = "{} {}".format(float("%.4f" % (value.get('decl') / value.get('t_data') * 100)),
                                               "%") if value.get('decl') != 0 else 0
            value['bili'] = "{} {}".format(float("%.4f" % (value.get('three_decl') / value.get('three_tran') * 100)),
                                           "%") if value.get('three_tran') != 0 else 0
            if value.get('three_tran') != 0 and value.get('three_decl') / value.get('three_tran') > 0.1:
                value['show'] = 'T'
            else:
                value['show'] = 'F'
            res.append(value)
            # 设置缓存
        cache.set('finance_decline_data', res, timeout=60 * 60 * 6)

    else:
        res = ca_data
        if alias_name:
            res_alias = list()
            for i in res:
                if alias_name in i.get('alias'):
                    res_alias.append(i)
            return jsonify({"code": 0, "count": len(res_alias), "data": res_alias, "msg": "SUCCESSFUL"})
        return jsonify({"code": 0, "count": len(res), "data": res, "msg": "SUCCESSFUL"})
Example #2
0
 def get_materiascursadas(self, token, carrera):
     cache_data = cache.get(carrera)
     if cache_data:
         result = json.loads(cache_data)
     else:
         data = self.retrieve_materiascursadas(token, carrera)
         cache.set(carrera,
                   json.dumps(data, ensure_ascii=False).encode('utf8'))
         result = data
     return result
Example #3
0
 def get(self):
     cached = cache.get('user_%s' % self.user_id)
     if cached:
         logger.info('Sent from cache user_%s' % self.user_id)
         return cached
     else:
         q = db.query(User).filter(User.user_id == self.user_id).all()[0]
         cache.set('user_%s' % self.user_id, q)
         logger.info('Added to cache user_%s' % self.user_id)
         return q
Example #4
0
 def get(self):
     cached = cache.get('room_%s' % self.id)
     if cached:
         logger.info('Sent from cache room_%s' % self.id)
         return cached[0]
     else:
         q = db.query(Room).filter(Room.id == self.id).all()
         cache.set('room_%s' % self.id, q)
         logger.info('Added to cache room_%s' % self.id)
         return q[0]
 def getTakenSubjects(self, token, subjectCode):
     cache_data = cache.get(subjectCode)
     if cache_data:
         result = json.loads(cache_data)
     else:
         data = self.retrieveTakenSubjects(token, subjectCode)
         cache.set(subjectCode,
                   json.dumps(data, ensure_ascii=False).encode('utf8'))
         result = data
     return result
Example #6
0
 async def message_handler(msg):
     subject = msg.subject
     log.info(
         f'Received a message on: {subject}, data length: {len(msg.data)} bytes'
     )
     datastream_msg = datastream_pb2.DataStreamMessage()
     datastream_msg.ParseFromString(msg.data)
     payload = pickle.loads(datastream_msg.payload[0])
     cache.set('values', payload.get('values'))
     if payload.get('image'):
         cache.set('image', payload.get('image'))
Example #7
0
def ver_code_send():
    '''
    手机验证码的保存于验证
    :return:
    '''
    if request.method == 'POST':
        data = json.loads(request.form.get('data'))
        phone = data.get('phone')
        ver_key = data.get('ver_key')

        _code = verify_code(6, False)
        res = CCP().send_Template_sms(phone, [_code, '60s'], 488547,)
        if res == 0:
            cache.set(ver_key, _code, timeout=120)
            return jsonify({'code': RET.OK, 'msg': MSG.OK})
        else:
            return jsonify({'code': RET.SERVERERROR, 'msg': '短信发送失败!请检查号码是否正确!'})
Example #8
0
    def get(self, model=None):
        cached = cache.get('item_%s' % self.id)
        res = None

        if cached:
            logger.info('Sent from cache item_%s' % self.id)
            res = '{0} ({1})'.format(cached[0].title, cached[0].value)
            if model:
                res = cached[0]
        else:
            q = db.query(Item).filter(Item.id == self.id).all()
            if q:
                cache.set('item_%s' % self.id, q)
                logger.info('Added to cache item_%s' % self.id)
                res = '{0} ({1})'.format(q[0].title, q[0].value)
                if model:
                    res = q[0]
            else:
                res = 'Нет'

        return res
def detect_no_mask():
    prototext_path = f'{Config.FACE_DETECTOR_MODEL}.prototxt'
    weights_path = f'{Config.FACE_DETECTOR_MODEL}.caffemodel'
    model_path = f'{Config.MASK_DETECTOR_MODEL}.model'
    confidence = Config.CONFIDENCE
    sample_interval = Config.SAMPLE_INTERVAL

    net = cv2.dnn.readNet(prototext_path, weights_path)
    model = load_model(model_path)
    log.info('loaded face mask detector model ...')

    # Main detector loop
    while True:
        start_time = time.time()
        faces_without_mask = 0
        faces_with_mask = 0

        if capture_device.isOpened():
            image = capture_device.read()
            (locs, preds) = detect_and_predict_mask(image, net, model)

            # loop over the detected face locations and their corresponding
            # locations
            for (box, pred) in zip(locs, preds):
                # unpack the bounding box and predictions
                (startX, startY, endX, endY) = box
                (mask, withoutMask) = pred

                # determine the class label and color we'll use to draw
                # the bounding box and text
                if mask > withoutMask:
                    label = f'Mask: {mask:.2f}'
                    faces_with_mask += 1
                    color = (0, 255, 0)
                else:
                    label = f'No Mask: {withoutMask:.2f}'
                    faces_without_mask += 1
                    color = (0, 0, 255)

                # display the label and bounding box rectangle on the output
                # frame
                cv2.putText(image, label, (startX, startY - 10),
                            cv2.FONT_HERSHEY_SIMPLEX, 0.45, color, 2)
                cv2.rectangle(image, (startX, startY), (endX, endY), color, 2)

        cache.set('image', cv2.imencode('.jpg', image)[1].tobytes())
        cache.set('mask_count', faces_with_mask)
        cache.set('nomask_count', faces_without_mask)

        time_to_wait = sample_interval - time.time() - start_time
        if time_to_wait > 0:
            time.sleep(time_to_wait)
        else:
            time.sleep(0.5)
Example #10
0
def all_trans():
    page = request.args.get("page")
    limit = request.args.get("limit")
    # 客户名
    acc_name = request.args.get("acc_name")
    # 卡的名字
    order_num = request.args.get("order_num")
    # 时间范围
    time_range = request.args.get("time_range")
    # 操作状态
    trans_status = request.args.get("trans_status")
    # 交易类型
    trans_store = request.args.get("trans_store")

    args_list = []
    ca_data = cache.get('all_trans')
    # 设置缓存处理查询到的大量数据(6小时)
    if ca_data:
        data = ca_data
    else:
        data = SqlDataNative.bento_alltrans()
        cache.set('all_trans', data, timeout=60 * 60 * 6)
    results = {"code": RET.OK, "msg": MSG.OK, "count": 0, "data": ""}
    if len(data) == 0:
        results["MSG"] = MSG.NODATA
        return jsonify(results)

    # 下列判断为判断是否有搜索条件根据条件过滤
    acc_list = list()
    if acc_name:
        # args_list.append(acc_name)
        for i in data:
            cus = i.get('before_balance')
            if acc_name == cus:
                acc_list.append(i)
    else:
        acc_list = data

    order_list = list()
    if order_num:
        # args_list.append(order_num)
        for c in acc_list:
            card_name = c.get('hand_money')
            if order_num in card_name:
                order_list.append(c)
    else:
        order_list = acc_list

    trans_list = list()
    if trans_status:
        args_list.append(trans_status)
        for i in order_list:
            do_type = i.get('card_num')
            if trans_status in do_type:
                trans_list.append(i)
    else:
        trans_list = order_list

    time_list = list()
    if time_range:
        min_time = time_range.split(' - ')[0] + ' 00:00:00'
        max_time = time_range.split(' - ')[1] + ' 23:59:59'
        min_tuple = datetime.datetime.strptime(min_time, '%Y-%m-%d %H:%M:%S')
        max_tuple = datetime.datetime.strptime(max_time, '%Y-%m-%d %H:%M:%S')
        for d in trans_list:
            dat = datetime.datetime.strptime(d.get("date"), '%Y-%m-%d %H:%M:%S')
            if min_tuple < dat < max_tuple:
                time_list.append(d)
    else:
        time_list = trans_list

    store_list = list()
    if trans_store:
        for i in time_list:
            trans_type = i.get('trans_type')
            if trans_store in trans_type:
                store_list.append(i)
    else:
        store_list = trans_list

    if not store_list:
        return jsonify({'code': RET.OK, 'msg': MSG.NODATA})
    page_list = list()
    data = sorted(store_list, key=operator.itemgetter("date"))
    data = list(reversed(data))
    for i in range(0, len(data), int(limit)):
        page_list.append(data[i: i + int(limit)])
    results["data"] = page_list[int(page) - 1]
    results["count"] = len(data)
    return jsonify(results)
Example #11
0
 def update(self, update):
     user = db.query(User).filter(User.user_id == self.user_id)
     user.update(update)
     db.commit()
     cache.set('user_%s' % self.user_id, user.all()[0])
     logger.info('Cache updated user_%s' % self.user_id)