def write_ret(cls, ret): try: redis_cli.set('{0}:{1}'.format(ret['id'], ret['jid']), json.dumps(ret)) redis_cli.lpush('{0}:{1}'.format(ret['id'], ret['fun']), ret['jid']) except Exception as ex: from app import app import traceback app.logger.warn(str(traceback.print_exc()))
def update_page_data(cls, term: str = None, unscoped=False): if term is None: term = service.TermService.get_now_term()['name'] (_, num) = dao.NoticeLesson.query_notice_lessons(query_dict={'term': [term]}, unscoped=False) try: redis_cli.set('sys:notice_lesson_num', json.dumps(num)) except Exception as e: raise CustomError(500, 500, str(e)) return num
def count_visits(hostname): total_visits_count = redis_cli.get('visits') if not total_visits_count: total_visits_count = 0 redis_cli.set('visits', total_visits_count) else: total_visits_count = int(total_visits_count) + 1 redis_cli.set('visits', total_visits_count) host_visits_count = redis_cli.get(hostname) if not host_visits_count: host_visits_count = 0 redis_cli.set(hostname, host_visits_count) else: host_visits_count = int(host_visits_count) + 1 redis_cli.set(hostname, host_visits_count) return total_visits_count, host_visits_count
def update_page_data(cls): """ 更新首页数据 :return: """ _, has_submitted_num = dao.Form.query_forms( query_dict={"status": ["已完成"]}) _, wait_submitted_form_num = dao.Form.query_forms( query_dict={"status": ["待提交"]}) for unit in UNIT_LIST: _, submit_unit_num = dao.Form.query_forms(query_dict={ "status": ["已完成"], "meta.lesson.lesson_teacher_unit": [unit] }) redis_cli.set('sys:form_num:{unit}'.format(unit=unit), str(submit_unit_num)) redis_cli.set("sys:submitted_form", json.dumps(has_submitted_num)) redis_cli.set("sys:wait_submitted_form", json.dumps(wait_submitted_form_num))
def calculate_map(cls, meta_name): """ 督导的分布的计算, 包括对选项型的分布计算 和 文本型的并放入rediis :param meta_name: :return: """ if meta_name is None: return item_map = {} word_cloud = {} # 此处可能需要添加一个学期查询参数 forms, _ = dao.Form.query_forms(query_dict={ "bind_meta_name": [meta_name], 'status': ['已完成'] }) for form in forms: for item in form.get("values", []): if item.get('item_type') == "radio_option": # 处理单选 if not item_map.get(item['item_name']): # 初始化 point = { o['value']: { "option": o, "num": 0 } for o in item.get("payload", {}).get( "options", []) } if item.get('value'): point[item['value']]['num'] = point[ item['value']]['num'] + 1 item_map[item['item_name']] = { "item_name": item['item_name'], "point": list(point.values()) } else: # 存在直接+1 point = item_map[item['item_name']]["point"] for p in point: if p['option']['value'] == item['value']: p['num'] = p['num'] + 1 if item.get("item_type") == "checkbox_option": # 处理多选 if not item_map.get(item['item_name']): point = { o['label']: { "option": o, "num": 0 } for o in item.get("payload", {}).get( "options", []) } if item["value"]: for value in item["value"]: if value in point: point[value][ "num"] = point[value]["num"] + 1 item_map[item['item_name']] = { "item_name": item['item_name'], "point": list(point.values()) } else: point = item_map[item['item_name']]["point"] for p in point: if p['option']['label'] in item['value']: p['num'] = p['num'] + 1 if item.get("item_type") == "raw_text": # 处理文本分词 if not word_cloud.get(item['item_name']): # 首次 value = item['value'] if value: res = jieba.cut(value) word_cloud[item['item_name']] = list(res) else: value = item['value'] if value: if isinstance(value, str): res = jieba.cut(value) else: res = jieba.cut(str(value)) word_cloud[item['item_name']] = word_cloud[ item['item_name']] + list(res) # word_cloud 转成数组新式 word_cloud = [{ "item_name": k, "value": [{ "word": i[0], "num": i[1] } for i in Counter(v).items()] } for k, v in word_cloud.items()] redis_cli.set("form_service:{}:word_cloud".format(meta_name), json.dumps(word_cloud)) redis_cli.set("form_service:{}:map".format(meta_name), json.dumps(list(item_map.values()))) print("计算完成")
def update_page_data(cls): """ 更新首页数据 :return: """ _, has_submitted_num = dao.Form.query_forms(query_dict={ "status": ["已完成"] }) # 待提交包含了草稿和待提交 _, wait_submitted_form_num = dao.Form.query_forms(query_dict={ "status": ["待提交", "草稿"] }) # 当前学期已提交的问卷数量 from . import term term = term.TermService.get_now_term_no_cache()['name'] _, current_term_has_submitted_num = dao.Form.query_forms(query_dict={ "status": ["已完成"], "meta.term": [term] }) # 当前学期待提交的问卷数目 _, current_term_wait_submitted_num = dao.Form.query_forms(query_dict={ "status": ["待提交","草稿"], "meta.term": [term] }) print("history: has_submitted_num", has_submitted_num, "wait", wait_submitted_form_num) print("current_term: has_submitted_num ", current_term_has_submitted_num, "wait", current_term_wait_submitted_num) for unit in UNIT_LIST: _, submit_unit_num = dao.Form.query_forms(query_dict={ "status": ["已完成"], "meta.lesson.lesson_teacher_unit": [unit] }) redis_cli.set('sys:form_num:{unit}'.format(unit=unit), str(submit_unit_num)) # 当前学期 各学院评教情况统计 for unit in UNIT_LIST: _, current_term_submit_unit_num = dao.Form.query_forms(query_dict={ "status": ["已完成"], "meta.lesson.lesson_teacher_unit": [unit], "meta.term": [term], }) redis_cli.set('sys:current_term_form_num:{unit}'.format(unit=unit), str(current_term_submit_unit_num)) redis_cli.set("sys:submitted_form", json.dumps(has_submitted_num)) redis_cli.set("sys:wait_submitted_form", json.dumps(wait_submitted_form_num)) redis_cli.set("sys:current_term_submitted_form", json.dumps(current_term_has_submitted_num)) redis_cli.set("sys:current_term_wait_submitted_form", json.dumps(current_term_wait_submitted_num)) # 评价情况数据刷新 satisfy_num = mongo.db.form.count({ "values": { "$elemMatch":{ "title": "总体评价", "value":{ "$in": ["1","2"] } } } }) just_num = mongo.db.form.count({ "values": { "$elemMatch":{ "title": "总体评价", "value":{ "$in": ["3"] } } } }) unsatisfy_num = mongo.db.form.count({ "values": { "$elemMatch":{ "title": "总体评价", "value":{ "$in": ["4","5"] } } } }) print("总体评价 满意 {} 一般 {} 不满意 {}".format(satisfy_num, just_num, unsatisfy_num)) redis_cli.set("sys:form_statisfy_num", json.dumps(satisfy_num)) redis_cli.set("sys:form_just_num", json.dumps(just_num)) redis_cli.set("sys:form_unsatisfy_num", json.dumps(unsatisfy_num))
def update_page_data(cls): """ 更新首页数据 :return: """ _, has_submitted_num = dao.Form.query_forms(query_dict={ "status": ["已完成"] }) _, wait_submitted_form_num = dao.Form.query_forms(query_dict={ "status": ["待提交", "草稿"] }) print("has_submitted_num", has_submitted_num, "wait", wait_submitted_form_num) for unit in UNIT_LIST: _, submit_unit_num = dao.Form.query_forms(query_dict={ "status": ["已完成"], "meta.lesson.lesson_teacher_unit": [unit] }) redis_cli.set('sys:form_num:{unit}'.format(unit=unit), str(submit_unit_num)) redis_cli.set("sys:submitted_form", json.dumps(has_submitted_num)) redis_cli.set("sys:wait_submitted_form", json.dumps(wait_submitted_form_num)) # 评价情况数据刷新 satisfy_num = mongo.db.form.count({ "values": { "$elemMatch":{ "title": "总体评价", "value":{ "$in": ["1","2"] } } } }) just_num = mongo.db.form.count({ "values": { "$elemMatch":{ "title": "总体评价", "value":{ "$in": ["3"] } } } }) unsatisfy_num = mongo.db.form.count({ "values": { "$elemMatch":{ "title": "总体评价", "value":{ "$in": ["4","5"] } } } }) print("总体评价 满意 {} 一般 {} 不满意 {}".format(satisfy_num, just_num, unsatisfy_num)) redis_cli.set("sys:form_statisfy_num", json.dumps(satisfy_num)) redis_cli.set("sys:form_just_num", json.dumps(just_num)) redis_cli.set("sys:form_unsatisfy_num", json.dumps(unsatisfy_num))