Esempio n. 1
0
def leave_room(user: OnlineUser, room: str) -> None:
    rooms_for_user = redis_client.hget('rooms_per_user', user.username)
    users_for_room = redis_client.hget('users_per_room', room)
    rooms_for_user.pop(rooms_for_user.index(room))
    users_for_room.pop(users_for_room.index(user.username))
    redis_client.hset('rooms_per_user', user.username, rooms_for_user)
    redis_client.hset('users_per_room', room, users_for_room)
Esempio n. 2
0
def scenario():
    error = None
    scenario_time = 0
    scenario_list = {'Fuse': '5', 'Circuit': '10', 'CO2leak': '5', 'Quiz': '5'}

    if request.method == 'POST':
        base_time = request.form['base-time']
        if not isInteger(base_time):
            flash('CORRECT Entry Error and RESUBMIT')
            error = " Base time must be an integer "
        is_checked = request.form
        if error is None:
            #scenarios default to NO
            for key in scenario_list:
                redis_client.hset("scenarios", key, "NO")
            #scenarios checked set to YES
            for key, value in is_checked.items():
                redis_client.hset("scenarios", key, key)
                scenario_time += int(is_checked[key])
        session['scenario_time'] = scenario_time

    else:
        is_checked = ""
        base_time = 40
        scenario_time = 40
        session['scenario_time'] = scenario_time

    return render_template('scenario.html',
                           title='Scenarios',
                           scenario_list=scenario_list,
                           is_checked=is_checked,
                           base_time=base_time,
                           error=error,
                           scenario_time=scenario_time)
Esempio n. 3
0
def goto_room(user: OnlineUser, room: str) -> None:
    rooms_for_user = redis_client.hget('rooms_per_user', user.username)
    users_for_room = redis_client.hget('users_per_room', room)
    rooms_for_user.append(room)
    users_for_room.append(user.username)
    redis_client.hset('rooms_per_user', user.username, rooms_for_user)
    redis_client.hset('users_per_room', room, users_for_room)
Esempio n. 4
0
def reset_threshold():
    pipes = {
        "WPA-H2O-pot-out", "WPA-H2O-in-CO2", "WPA-H2O-in-CDRA",
        "WPA-H2O-in-SRA", "SRA-H2O-out", "SRA-H2-in", "SRA-CH4-out",
        "SRA-N2-in", "OGA-O2-out", "OGA-H2-out", "OGA-H2O-pot-in",
        "CDRA-H2O-out", "CDRA-CO2-out"
    }
    for pipe in pipes:
        redis_client.hset("threshold", pipe, "10000")
    pipe_thresh_dict = redis_client.hgetall("threshold")
    print('threshold', pipe_thresh_dict)
Esempio n. 5
0
def get_roles_from_redis(user):
    result = redis_client.hget("user_{user_id}".format(user_id=user.id),
                               "roles")
    if result:
        return json.loads(result.decode('utf-8'))
    roles = set()
    if user.roles:
        for role in user.roles:
            roles.add(role.name)
        redis_client.hset("user_{user_id}".format(user_id=user.id), "roles",
                          json.dumps(list(sorted(roles))))
        redis_client.expire("user_{user_id}".format(user_id=user.id),
                            current_app.config['JWT_ACCESS_TOKEN_EXPIRES'])
    return list(sorted(roles))
Esempio n. 6
0
def save_property_listing_images_to_redis(image_files):
    """
    Saves the image files to redis in a hash map. The image_files_redis_key will be used to get the images in redis
    for resizing. The image_files_redis_key will also be used a folder name where the processed images will be saved.
    """
    image_files_redis_key = uuid.uuid4().__str__()[:15].replace("-", "")
    image_data_dict = {}
    for image_file in image_files:
        _, file_extension = os.path.splitext(image_file.filename)
        new_image_filename = uuid.uuid4().__str__()[:8]
        image_data_dict[
            f"{new_image_filename}{file_extension}"] = image_file.read()
    # update to use redis_client.hset("myKey", mapping=data) as a resolve to deprecated redis_client.hmset()
    redis_client.hset(image_files_redis_key, mapping=image_data_dict)
    return image_files_redis_key
Esempio n. 7
0
def get_permissions_from_redis(user_id):
    result = redis_client.hget("user_{user_id}".format(user_id=user_id),
                               "permissions")
    if result:
        return json.loads(result.decode('utf-8'))
    permissions = set()
    user = User.query.filter_by(id=user_id).first()
    if user.roles:
        for role in user.roles:
            for permission in role.permissions:
                permissions.add(permission.path)
    if permissions:
        redis_client.hset("user_{user_id}".format(user_id=user_id),
                          "permissions", json.dumps(list(sorted(permissions))))
        redis_client.expire("user_{user_id}".format(user_id=user_id),
                            current_app.config['JWT_ACCESS_TOKEN_EXPIRES'])
    return list(sorted(permissions))
Esempio n. 8
0
def piping():
    error = None
    #is this the first time to this page and came from scenario?
    url = request.referrer
    if "scenario" in url:
        #set initial time for countdown timer
        session['starttime'] = time.time()
        #place times into redis for retrival by a different browser
        redis_client.set("starttime", time.time())
        redis_client.set("scenariotime", session.get("scenario_time"))

        if (int(session.get("scenario_time")) == 0):
            return redirect(url_for('scenario'))
        else:
            countdown = (session.get("scenario_time")) * 60

    else:
        #account for time elapsed since countdown started
        elapsed_time = (time.time()) - (session.get('starttime'))
        countdown = (session.get("scenario_time")) * 60 - elapsed_time
        if request.method == 'POST':
            pipe_data = request.form
            for key, value in pipe_data.items():
                if value:  #was a value entered in the field?
                    if not isInteger(value):
                        flash('correct your error and RESUBMIT')
                        error = " Threshold value must be an integer "
                    else:
                        print("threshold", key, value)
                        redis_client.hset("threshold", key, value)

    pipe_thresh = redis_client.hgetall("threshold")
    return render_template('piping.html',
                           title='Piping',
                           countdown=countdown,
                           error=error,
                           pipe_thresh=pipe_thresh)
Esempio n. 9
0
 def save(self):
     redis_client.hset('sess_token', self.value)
Esempio n. 10
0
File: chat.py Progetto: Wjun0/nh
def save_result_to_redis(result, session_id):
    try:
        json_str_data = json.dumps(result)
        redis_client.hset(session_id, session_id, json_str_data)
    except Exception as e:
        current_app.logger.error(e)
Esempio n. 11
0
File: chat.py Progetto: Wjun0/nh
    def post(self):
        starTime = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())

        parser = RequestParser()
        parser.add_argument('type', required=True, location='json')
        parser.add_argument('sesskey', required=True, location='json')
        parser.add_argument('question', required=True, location='json')
        parser.add_argument('roundkey', location='json')
        args = parser.parse_args()

        question = args.question
        sesskey = args.sesskey
        type = args.type
        roundkey = args.roundkey

        #如果没有roundkey则是第一次对话
        if not roundkey:
            roundkey = "R1"

        # 获取算法数据

        name = [
            "张三盗窃电动⻋", "张三盗窃电动⻋", "张三盗窃电动⻋", "张三盗窃电动⻋", "张三盗窃电动⻋", "张三盗窃电动⻋",
            "张三盗窃电动⻋", "张三盗窃电动⻋", "张三盗窃电动⻋", "张三盗窃电动⻋"
        ]
        bamj = [
            "邹⼩⻥", "邹⼩⻥", "邹⼩⻥", "邹⼩⻥", "邹⼩⻥", "邹⼩⻥", "邹⼩⻥", "邹⼩⻥", "邹⼩⻥",
            "邹⼩⻥"
        ]
        ajxz = [
            "盗窃案", "盗窃案", "盗窃案", "盗窃案", "盗窃案", "盗窃案", "盗窃案", "盗窃案", "盗窃案",
            "盗窃案"
        ]
        place = [
            "深圳市南⼭区粤海街道科苑路23号讯美科技⼴场3栋23A", "深圳市南⼭区粤海街道科苑路23号讯美科技⼴场3栋23A",
            "深圳市南⼭区粤海街道科苑路23号讯美科技⼴场3栋23A", "深圳市南⼭区粤海街道科苑路23号"
        ]
        people = [
            "张⼩⾬", "张⼩⾬", "张⼩⾬", "张⼩⾬", "张⼩⾬", "张⼩⾬", "张⼩⾬", "张⼩⾬", "张⼩⾬",
            "张⼩⾬"
        ]

        table = {
            "案件ID": [
                "A83", "B45", "A32", "A79", "B98", "C23", "A24", "A25", "A26",
                "B78"
            ],
            "案件名称":
            name,
            "案发时间": [
                "2018.07.02 14:23", "2018.07.02 14:23", "2018.07.02 14:23",
                "2018.07.02 14:23", "2018.07.02 14:23", "2018.07.02 14:23",
                "2018.07.02 14:23", "2018.07.02 14:23", "2018.07.02 23:34"
            ],
            "案发地点":
            place,
            "办案⺠警":
            bamj,
            "案件性质":
            ajxz,
            "报警⼈":
            people,
            "联系电话": [
                "13522511892", "13522511892", "13522511892", "13522511892",
                "13522511892", "13522511892", "13522511892", "13522511892",
                "13522511892", "13522511892"
            ]
        }

        datasource = ["本地", "浙江省"]
        Rcondic = {"F1": "查询主类:案件", "F2": "案发时间:2020-02-19", "F3": "案件地址:南山区"}

        roundinfo = {
            "roundkey": roundkey,
            "roundID": roundkey,
            "Rcondic": Rcondic,
            "datasource": datasource
        }
        roundinfo_list = []
        try:
            s = SessionInfo.query.options(load_only(SessionInfo.sessKey,SessionInfo.sessCondic,SessionInfo.number,SessionInfo.roundInfo)).\
                filter(SessionInfo.sessKey == sesskey).first()
            if s:
                r = json.loads(s.roundInfo)
                r.append(roundinfo)
                SessionInfo.query.options(load_only(SessionInfo.sessKey)).filter(SessionInfo.sessKey ==s.sessKey).\
                    update(
                    {"endTime":time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()),
                     "number":s.number + 1,
                     "roundInfo":json.dumps(r)}
                )
            else:
                roundinfo_list.append(roundinfo)
                data = SessionInfo(sessName=sesskey,
                                   sessID=sesskey,
                                   sessCondic=json.dumps(Rcondic),
                                   sessKey=sesskey,
                                   starTime=starTime,
                                   endTime=time.strftime(
                                       "%Y-%m-%d %H:%M:%S", time.localtime()),
                                   number=1,
                                   owner=g.userid,
                                   roundInfo=json.dumps(roundinfo_list))
                db.session.add(data)
                db.session.commit()
        except Exception as e:
            current_app.logger.error(e)
            return {"message": "error", "data": "数据库保存错误!"}

        # 将算法返回的数据保存到数据库
        try:
            data = RoundInfo(roundName="案件筛选",
                             roundID=roundkey,
                             roundCondic=json.dumps(Rcondic),
                             starTime=starTime,
                             endTime=time.strftime("%Y-%m-%d %H:%M:%S",
                                                   time.localtime()),
                             roundKey=roundkey,
                             query=question,
                             tableInfo=table)
            db.session.add(data)
            db.session.commit()

        except Exception as e:
            current_app.logger.error(e)
            return {"message": "error", "data": "数据库保存失败!"}

        result = {
            "RoundID": roundkey,
            "query": "查⼀下深圳这三个⽉的犯罪记录",
            "RoundName": "案件筛选",
            "qtime": "2020021801",
            "roundKey": roundkey,
            "Rcondic": Rcondic,
            "datasource": datasource,
            "tablelLen": "10",
            "tableName": "案件信息表",
            "table": table
        }
        try:
            data = json.dumps(result)
            redis_client.hset(sesskey, roundkey, data)
        except Exception as e:
            current_app.logger.erroer(e)
            return {"message": "error", "data": "redis保存失败"}

        return result
Esempio n. 12
0
def record_event(bid_id, imp_id, event):
    # Record given event in stored bid entry.
    redis_client.hset(KEY_SPACE_BID + bid_id, event + ':' + imp_id, 1)
Esempio n. 13
0
def store_response(bid_id, bid_response):
    # Store bid response.
    redis_client.hset(
        KEY_SPACE_BID + bid_id, 'response', json.dumps(bid_response))
Esempio n. 14
0
def store_request(bid_id, bid_request):
    # Store bid request for a short period.
    redis_client.hset(
        KEY_SPACE_BID + bid_id, 'request', json.dumps(bid_request))
    redis_client.expire(KEY_SPACE_BID + bid_id, PERSIST_SHORT_SECONDS)
    return bid_id