【疑惑】打分页

@app.route('/Subjective_scoring', methods=['GET', 'POST'])
def subjective_scoring():
    # args = request.form
    # print(request.json)

    import uuid
    parent_task_uuid="5de8b01e7e0411eea20ba4dcbe1b9a90"
    remote_ip = request.remote_addr


    with DBOperate() as fp:
        data = fp.select("select task_uuid from evaluate_score_info where parent_task_uuid='%s' and remote_ip='%s';" % (parent_task_uuid,remote_ip))

    if not data:
        with DBOperate() as fp:
            res_data = fp.select("select task_cnt,total_json from evaluate_task_info where task_uuid='%s';" % parent_task_uuid)
        if res_data:
            task_cnt_total,total_json = res_data[0]
        task_uuid = uuid.uuid1().hex
        task_start_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        timestamp = str(int(time.time()))
        task_timestamp = timestamp + "_" + request.remote_addr
        score_total_json_path = os.path.join(static_path,"evaluate",parent_task_uuid,"task_info",task_timestamp+".json")
        with DBOperate() as fp:
            fp.insert(
                "insert into evaluate_score_info (task_uuid,status,cur_cnt,task_cnt,parent_task_uuid,task_start_time,task_end_time,tiemstamp_ip,score_total_json,remote_ip) values ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s');" % (
                task_uuid,"PROCESSING",'0',task_cnt_total,parent_task_uuid,task_start_time,task_start_time, task_timestamp,score_total_json_path,remote_ip))
            data_res = fp.select("select task_cnt,total_json from evaluate_task_info where task_uuid='%s';" % parent_task_uuid)
        if data_res:
            task_cnt, json_file = data_res[0]

            res = {}
            with open(json_file, 'r', encoding="utf-8") as f:
                res_tmp = json.load(f)
            for prompt,value in res_tmp.items():
                if str(value.get("index")) == "0":
                    res.update({prompt:value})
                    break
        return render_template("Subjective_scoring.html", data=res, count=int(task_cnt))
        #return render_template("Subjective_scoring1.html", data=res,count=int(task_cnt))

    else:
        with DBOperate() as fp:
            res_data = fp.select(
                "select a.cur_cnt,a.task_cnt,a.score_total_json,b.total_json from evaluate_score_info a,evaluate_task_info b where a.parent_task_uuid='%s' and a.remote_ip='%s' and a.parent_task_uuid=b.task_uuid;" % (parent_task_uuid,remote_ip))
        if res_data:
            cur_cnt, task_cnt, score_total_json,total_json = res_data[0]

        with open(total_json, 'r', encoding="utf-8") as f:
            res_tmp = json.load(f)
        target_cnt = int(cur_cnt) + 1
        res = {}
        for prompt,value in res_tmp.items():
            if str(value.get("index")) == str(target_cnt):
                res.update({prompt:value})
                break



# data={
# 	'2个柔顺的玩具车': {
# 		'index': 0,
# 		'test1108_1': {
# 			'5.png': {
# 				'image_name': '1',
# 				'image_path': '/static/evaluate/5de8b01e7e0411eea20ba4dcbe1b9a90/test1108_1/img/5.png',
# 				'split_word': {
# 					'柔顺的': 'other',
# 					'玩具车': 'object',
# 					'2个': 'other',
# 					'瘦瘦的': 'other'
# 				}
# 			}
# 		},
# 		'test1108_2': {
# 			'1.png': {
# 				'image_name': '1',
# 				'image_path': '/static/evaluate/5de8b01e7e0411eea20ba4dcbe1b9a90/test1108_2/img/1.png',
# 				'split_word': {
# 					'柔顺的': 'other',
# 					'玩具车': 'object',
# 					'2个': 'other',
# 					'瘦瘦的': 'other'
# 				}
# 			}
# 		},
# 		'test1108_3': {
# 			'0.png': {
# 				'image_name': '1',
# 				'image_path': '/static/evaluate/5de8b01e7e0411eea20ba4dcbe1b9a90/test1108_3/img/0.png',
# 				'split_word': {
# 					'柔顺的': 'other',
# 					'玩具车': 'object',
# 					'2个': 'other',
# 					'瘦瘦的': 'other'
# 				}
# 			}
# 		}
# 	},
# 	'2个可爱的花瓣': {
# 		'index': 1,
# 		'test1108_1': {
# 			'7.png': {
# 				'image_name': '2',
# 				'image_path': '/static/evaluate/5de8b01e7e0411eea20ba4dcbe1b9a90/test1108_1/img/7.png',
# 				'split_word': {
# 					'2个': 'other',
# 					'花瓣': 'object',
# 					'可爱的': 'other'
# 				}
# 			}
# 		},
# 		'test1108_2': {
# 			'3.png': {
# 				'image_name': '2',
# 				'image_path': '/static/evaluate/5de8b01e7e0411eea20ba4dcbe1b9a90/test1108_2/img/3.png',
# 				'split_word': {
# 					'2个': 'other',
# 					'花瓣': 'object',
# 					'可爱的': 'other'
# 				}
# 			}
# 		},
# 		'test1108_3': {
# 			'1.png': {
# 				'image_name': '2',
# 				'image_path': '/static/evaluate/5de8b01e7e0411eea20ba4dcbe1b9a90/test1108_3/img/1.png',
# 				'split_word': {
# 					'2个': 'other',
# 					'花瓣': 'object',
# 					'可爱的': 'other'
# 				}
# 			}
# 		}
# 	},
# 	'黑色香蕉': {
# 		'index': 2,
# 		'test1108_1': {
# 			'8.png': {
# 				'image_name': '3',
# 				'image_path': '/static/evaluate/5de8b01e7e0411eea20ba4dcbe1b9a90/test1108_1/img/8.png',
# 				'split_word': {
# 					'黑色': 'other',
# 					'香蕉': 'object'
# 				}
# 			}
# 		},
# 		'test1108_2': {
# 			'4.png': {
# 				'image_name': '3',
# 				'image_path': '/static/evaluate/5de8b01e7e0411eea20ba4dcbe1b9a90/test1108_2/img/4.png',
# 				'split_word': {
# 					'黑色': 'other',
# 					'香蕉': 'object'
# 				}
# 			}
# 		},
# 		'test1108_3': {
# 			'2.png': {
# 				'image_name': '3',
# 				'image_path': '/static/evaluate/5de8b01e7e0411eea20ba4dcbe1b9a90/test1108_3/img/2.png',
# 				'split_word': {
# 					'黑色': 'other',
# 					'香蕉': 'object'
# 				}
# 			}
# 		}
# 	}
# }

           
     return render_template("Subjective_scoring1.html", data=res, count=int(task_cnt),task_uuid=task_uuid)











@app.route('/Subjective_scoring_data', methods=['GET', 'POST'])
def Subjective_scoring_data():
    print(request.json)

    import uuid
    parent_task_uuid="5de8b01e7e0411eea20ba4dcbe1b9a90"
    remote_ip = request.remote_addr


    with DBOperate() as fp:
        data = fp.select("select task_uuid from evaluate_score_info where parent_task_uuid='%s' and remote_ip='%s';" % (parent_task_uuid,remote_ip))

    if not data:
        with DBOperate() as fp:
            res_data = fp.select("select task_cnt,total_json from evaluate_task_info where task_uuid='%s';" % parent_task_uuid)
        if res_data:
            task_cnt_total,total_json = res_data[0]
        task_uuid = uuid.uuid1().hex
        task_start_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        timestamp = str(int(time.time()))
        task_timestamp = timestamp + "_" + request.remote_addr
        score_total_json_path = os.path.join(static_path,"evaluate",parent_task_uuid,"task_info",task_timestamp+".json")
        with DBOperate() as fp:
            fp.insert(
                "insert into evaluate_score_info (task_uuid,status,cur_cnt,task_cnt,parent_task_uuid,task_start_time,task_end_time,tiemstamp_ip,score_total_json,remote_ip) values ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s');" % (
                task_uuid,"PROCESSING",'0',task_cnt_total,parent_task_uuid,task_start_time,task_start_time, task_timestamp,score_total_json_path,remote_ip))
            data_res = fp.select("select task_cnt,total_json from evaluate_task_info where task_uuid='%s';" % parent_task_uuid)
        if data_res:
            task_cnt, json_file = data_res[0]

            res = {}
            with open(json_file, 'r', encoding="utf-8") as f:
                res_tmp = json.load(f)
            for prompt,value in res_tmp.items():
                if str(value.get("index")) == "0":
                    res.update({prompt:value})
                    break
        return jsonify({"code": 0, "msg": "", "data": res})
        #return render_template("Subjective_scoring1.html", data=res,count=int(task_cnt))

    else:
        with DBOperate() as fp:
            res_data = fp.select(
                "select a.cur_cnt,a.task_cnt,a.score_total_json,b.total_json from evaluate_score_info a,evaluate_task_info b where a.parent_task_uuid='%s' and a.remote_ip='%s' and a.parent_task_uuid=b.task_uuid;" % (parent_task_uuid,remote_ip))
        if res_data:
            cur_cnt, task_cnt, score_total_json,total_json = res_data[0]

        with open(total_json, 'r', encoding="utf-8") as f:
            res_tmp = json.load(f)
        target_cnt = int(cur_cnt) + 1
        res = {}
        for prompt,value in res_tmp.items():
            if str(value.get("index")) == str(target_cnt):
                res.update({prompt:value})
                break

                       
    return jsonify({"code": 0, "msg": "", "data": res})
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值