modify addannotation

This commit is contained in:
wrmswindmill 2018-10-01 11:38:46 +08:00
parent 840c1487c2
commit dca7b68d10
5 changed files with 26 additions and 19 deletions

View File

@ -21,6 +21,7 @@ from django.template.loader import render_to_string
import base64
import redis
import json
import os
import logging
@ -31,9 +32,9 @@ logging.basicConfig(level=logging.DEBUG,
filemode='w')
def get_educoder_teamdid_by_educoder_userid(educoder_userid):
url = "https://www.educoder.net/api/v1/sources/get_user_competition_id?educoder_userid="+educoder_userid+"&private_token=hriEn3UwXfJs3PmyXnSG"
url = "https://www.educoder.net/api/v1/sources/get_user_competition_id?educoder_userid="+str(educoder_userid)+"&private_token=hriEn3UwXfJs3PmyXnSG"
response = requests.get(url)
team_id = list(json.loads(response.text)['team_ids'])
team_id = list(json.loads(response.text)['team_id'])
if len(team_id)>0:
return team_id[0]
else:
@ -60,20 +61,23 @@ def update_rank_latest():
# 4.获取每个组的分数
score = len(Annotation.objects.filter(user__in=users,file__in=competition_files))
redis_db.zadd("gcc",score,team)
with open('user_team_data.json', 'w') as outfile:
json.dump(user_team_map, outfile)
with open('/user_team_data.json', 'w') as outfile:
json.dump(user_team_map, outfile)
def set_init_rank():
global user_team_map
# 1.获取当前的比赛项目id
# competition_projects=Project.objects.filter(is_competition_project=1)
user_team_map =json.load(open('user_team_data.json','r'))
with open('/user_team_data.json','r') as file:
user_team_map =json.load(file)
# for user_id in user_team_map:
# print(user_id,user_team_map[user_id])
print("init rank success")
redis_db = redis.StrictRedis(host='localhost', port=6379, db=0)
user_team_map ={}
# update_rank_latest()
set_init_rank()
@ -433,26 +437,24 @@ class AddAnnotationView(View):
anno_content = get_currentfile_comment_anno(file,content)
# 更新FileSummary
update_filesummary(file_id,"annotation")
# print(anno_content)
if not file.project.is_competition_project or not file.is_competition_file:
return HttpResponse('{"status":"success_but_not_correct_file","msg":"注释成功,但请注意您标注的不是比赛模块","anno_content":"'+anno_content+'"}', content_type='application/json')
# update LeaderBoard
if request.user.educoder_userid is not None:
try:
if str(request.user.id) in user_team_map:
team_id = user_team_map[str(request.user.id)]
except:
else:
team_id = get_educoder_teamdid_by_educoder_userid(request.user.educoder_userid)
finally:
if team_id is None:
return HttpResponse(json.dumps({"status": "success", "msg":"注释成功","anno_content":anno_content,}), content_type='application/json')
elif str(request.user.id) not in user_team_map:
user_team_map[str(request.user.id)]=team_id
# save to file
# with open('user_team_data.json', 'w') as outfile:
# json.dump(user_team_map, outfile)
redis_db.zincrby("gcc",team_id,1)
rank = int(redis_db.zrevrank("gcc",team_id))+1
return HttpResponse(json.dumps({"status": "success", "msg":"注释成功","anno_content":anno_content,"rank":rank}), content_type='application/json')
with open('/user_team_data.json', 'w') as outfile:
json.dump(user_team_map, outfile)
redis_db.zincrby("gcc",team_id,1)
rank = int(redis_db.zrevrank("gcc",team_id))+1
return HttpResponse(json.dumps({"status": "success", "msg":"注释成功","anno_content":anno_content,"rank":rank}), content_type='application/json')
else:
return HttpResponse(json.dumps({"status": "success", "msg":"注释成功","anno_content":anno_content,}), content_type='application/json')
except Exception as e:

BIN
dump.rdb Normal file

Binary file not shown.

View File

@ -506,7 +506,7 @@ function add_annotation(item,file_id, line_num) {
// 获取当前是注释还是问题
function_name="add_annotation(this"+","+file_id+","+line_num+")"
make_button_disable($(item))
// make_button_disable($(item))
var selectValue = $(item).siblings(".put-select").find(".active").html().trim();
var text_context = "#addno-text-" + file_id+"-"+line_num;
@ -519,6 +519,7 @@ function add_annotation(item,file_id, line_num) {
return;
}
make_button_disable($("#issue-anno-submit"))
if (selectValue == "注释") {
// 向addAnnatation中发请求
submit_annotation(file_id, line_num, content);
@ -533,10 +534,11 @@ function add_annotation(item,file_id, line_num) {
deletelocalStorage("issueitem_value");
deletelocalStorage("status_value");
}
make_button_able($(item),function_name)
make_button_able($("#issue-anno-submit"),'add_annotation(this,'+file_id+','+linenum+')')
}
function submit_annotation(file_id, line_num, content) {
make_button_able($(""))
// 因为可能注释或问题没有值的时候不会为该代码块添加html代码所以首先判断
// 然后将注释数+1
$.ajax({
@ -559,7 +561,7 @@ function submit_annotation(file_id, line_num, content) {
$(".source-addno-panel").remove();
// show_annotation(file_id,line_num);
//将注释添加到当前行的上一行
var contenthtml ='<div class="linenum"></div>'+'<div class="sourcecode">'+'<div class="mypre newaddmypre hljs-comment ' + file_id+"_"+line_num + '">'+"//"+ content+'</div>'+'</div>'+'<div class="linestatus"></div>';
var contenthtml ='<div class="linenum"></div>'+'<div class="sourcecode">'+'<div class="mypre newaddmypre hljs-comment ' + file_id+"_"+line_num + '">'+data.anno_content+'</div>'+'</div>'+'<div class="linestatus"></div>';
var html = '<div class="newcodeline newcodelinebox">'+contenthtml+'</div>';
var id=file_id+'_'+"L"+line_num;
$("#"+id).before(html);
@ -1502,7 +1504,7 @@ function inject_addnoPanel_html(item,file_id,linenum) {
'<span class="put-selectspanactive" onclick=\'$(this).siblings("span").removeClass("active"); $(this).addClass("active");addissue('+file_id+','+linenum+');\'>问题</span>'+
'</p>'+
'<textarea id="addno-text-'+file_id+'-'+linenum+'" oninput="Input_Content(this,'+file_id+','+linenum+')" class="put-text" placeholder="输入注释或者问题"> </textarea>'+
'<a href="javascript:void(0)" onclick="add_annotation(this,'+file_id+','+linenum+')" class="btn btn-blue submit fr" id="submit">提交</a>'+
'<a href="javascript:void(0)" onclick="add_annotation(this,'+file_id+','+linenum+')" class="btn btn-blue submit fr" id="issue-anno-submit">提交</a>'+
'</div>'+
'</div>';
$(item).after(html_str)
@ -1532,6 +1534,7 @@ function add_dir_annotation(item, file_id, line_num){
alert("内容不能为空")
return;
}
if (selectValue == "注释") {
// 向addAnnatation中发请求
submit_dir_annotation(file_id, line_num, content);

View File

@ -14,6 +14,8 @@
{# <link rel="stylesheet" type="text/css" href="{% static 'css/jstree.css' %}">#}
<link rel="stylesheet" type="text/css" href="{% static 'css/prettify.css' %}">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
{% comment %} <script src="https://cdn.bootcss.com/jquery/2.1.3/jquery.min.js"></script> {% endcomment %}
{% comment %} <script src="{% static 'js/jquery.min.js' %}"></script> {% endcomment %}
<script src="{% static 'js/jstree.js' %}"></script>
<script src="{% static 'js/run_prettify.js' %}"></script>

View File

@ -1 +1 @@
{"234": 280, "143": 281, "146": 281, "72": 285, "189": 285, "283": 288, "184": 288, "534": 288, "133": 290, "165": 290, "196": 290, "197": 290, "264": 290, "71": 292, "169": 292, "88": 293, "68": 295, "104": 295, "150": 295, "57": 298, "107": 298, "61": 337, "66": 302, "161": 305, "162": 305, "87": 319, "173": 310, "514": 310, "90": 317, "89": 323, "235": 327, "121": 328, "137": 373, "99": 331, "24": 337, "77": 341, "100": 357, "233": 357, "338": 363, "297": 366, "183": 373, "198": 374, "156": 379, "435": 382, "269": 390, "154": 400, "166": 400, "152": 402, "163": 404, "187": 413, "115": 414, "167": 414, "172": 414, "174": 414, "364": 418, "204": 422, "208": 430, "221": 436, "94": 439, "95": 439, "96": 439, "127": 440, "129": 440, "131": 440, "447": 442, "230": 444, "268": 450, "246": 451, "223": 452, "430": 462, "275": 464, "267": 468, "255": 469, "226": 470, "265": 477, "245": 480, "253": 480, "254": 480, "285": 480, "311": 486, "298": 488, "210": 490, "175": 496, "200": 496, "314": 499, "333": 503, "344": 510, "428": 510, "81": 516, "33": 562, "433": 518, "408": 535, "415": 539, "407": 545, "420": 546, "437": 557, "439": 557, "444": 560, "83": 562, "84": 562, "374": 569, "429": 570, "222": 572, "357": 573, "342": 576, "359": 576, "438": 576, "300": 579, "352": 581, "353": 581, "441": 583, "467": 584, "360": 588, "482": 593, "485": 594, "487": 595, "251": 600, "306": 600, "274": 602, "279": 602, "280": 602, "522": 610, "483": 611, "186": 616, "506": 619, "517": 631, "355": 633, "403": 633, "397": 634, "527": 637}
{"234": 280, "143": 281, "146": 281, "72": 285, "189": 285, "283": 288, "547": 285, "549": 285, "184": 288, "534": 288, "133": 290, "165": 290, "196": 290, "197": 290, "264": 290, "71": 292, "169": 292, "88": 293, "64": 295, "68": 295, "104": 295, "150": 295, "57": 298, "107": 298, "61": 337, "66": 302, "161": 305, "162": 305, "87": 319, "173": 310, "514": 310, "90": 317, "89": 323, "235": 327, "121": 328, "137": 373, "99": 331, "24": 337, "77": 341, "100": 357, "233": 357, "338": 363, "297": 366, "183": 373, "198": 374, "156": 379, "435": 382, "269": 390, "542": 392, "154": 400, "166": 400, "152": 402, "163": 404, "187": 413, "115": 414, "167": 414, "172": 414, "174": 414, "364": 418, "204": 422, "208": 430, "221": 436, "94": 439, "95": 439, "96": 439, "127": 440, "129": 440, "131": 440, "447": 442, "230": 444, "268": 450, "246": 451, "223": 452, "557": 460, "430": 462, "275": 464, "267": 468, "255": 469, "226": 470, "265": 477, "245": 480, "253": 480, "254": 480, "285": 480, "548": 480, "311": 486, "298": 488, "210": 490, "175": 496, "200": 496, "314": 499, "333": 503, "344": 510, "428": 510, "81": 516, "33": 562, "433": 518, "408": 535, "415": 539, "407": 545, "420": 546, "437": 557, "439": 557, "444": 560, "83": 562, "84": 562, "374": 569, "429": 570, "560": 570, "222": 572, "357": 573, "342": 576, "359": 576, "438": 576, "300": 579, "352": 581, "353": 581, "441": 583, "467": 584, "360": 588, "482": 593, "485": 594, "487": 595, "251": 600, "306": 600, "274": 602, "279": 602, "280": 602, "522": 610, "483": 611, "541": 614, "186": 616, "506": 619, "517": 631, "355": 633, "403": 633, "397": 634, "527": 637, "464": 640, "523": 640, "238": 643, "544": 643, "546": 643, "553": 648, "554": 648, "555": 648, "526": 650, "414": 651, "416": 651, "535": 651}