handtest 防止出现多条记录

This commit is contained in:
caoqianming 2020-02-21 11:04:40 +08:00
parent 5633ffec4d
commit ec7b0d0854
2 changed files with 3 additions and 2 deletions

Binary file not shown.

View File

@ -6084,6 +6084,8 @@ def apiexamtestdetail(req):
elif a == 'handtest':
data = json.loads(req.body.decode('utf-8'))
testid = data['testid']
obj,created = ExamTestDetail.objects.get_or_create(examtest__id=testid, user__userid=userid,
defaults={'examtest': ExamTest.objects.get(id=testid),'user':User.objects.get(userid=userid)})
starttime = data['starttime']
endtime = datetime.now()
took = (endtime - datetime.strptime(starttime, '%Y-%m-%d %H:%M:%S')).total_seconds() #计算相差多少秒
@ -6120,8 +6122,6 @@ def apiexamtestdetail(req):
i['iscore'] = iscore
score = score + iscore
tms.append(str(i['question__id']))
obj,created = ExamTestDetail.objects.get_or_create(examtest__id=testid, user__userid=userid,
defaults={'examtest': ExamTest.objects.get(id=testid),'user':User.objects.get(userid=userid)})
obj.testnum = obj.testnum + 1
obj.starttime = starttime
obj.endtime = endtime
@ -6192,6 +6192,7 @@ def apiexamtestrate(req):
'''
companyid = req.GET.get('companyid')
alltest = ExamTest.objects.filter(usecomps__contains=','+str(companyid)+',').exclude(nousecomps__contains=','+str(companyid)+',')
print(alltest)
objs = ExamTestDetail.objects.filter(examtest__in=alltest,ison=1).values('user__userid','user__name','user__headimgurl','user__ubelongpart__partname').annotate(totalscore=Sum('score'),totaltook=Sum('took'),testnum=Count('user__userid')).order_by('-totalscore','totaltook')
total = objs.count()
with open('ratedata.dat','wb') as f: