examtest 考试机会
This commit is contained in:
parent
0b49ce1254
commit
cfaf678a0a
Binary file not shown.
|
@ -764,13 +764,14 @@ class ExamTest(models.Model): # 考试表
|
|||
createuser = models.ForeignKey(
|
||||
User, blank=True, null=True, on_delete=models.CASCADE, related_name='kscjr')
|
||||
qrcode = models.CharField(max_length=200, blank=True, null=True)
|
||||
retest_count = models.IntegerField('允许重考次数', default=10)
|
||||
testnum = models.IntegerField('考试机会', default=10)
|
||||
|
||||
|
||||
|
||||
class ExamTestDetail(models.Model): # 考试详情表
|
||||
id = models.AutoField(primary_key=True)
|
||||
testnum = models.IntegerField(default=0) # 做卷次数
|
||||
remainnum = models.IntegerField('剩余次数', default=1)
|
||||
examtest = models.ForeignKey(
|
||||
ExamTest, on_delete=models.CASCADE, null=True, blank=True)
|
||||
user = models.ForeignKey(User, on_delete=models.CASCADE)
|
||||
|
@ -778,7 +779,6 @@ class ExamTestDetail(models.Model): # 考试详情表
|
|||
endtime = models.DateTimeField(null=True, blank=True)
|
||||
took = models.IntegerField(default=0) # 耗时
|
||||
rights = models.IntegerField(default=1) # 正确数
|
||||
ison = models.IntegerField(default=0) # 可参加0/已参加1/
|
||||
passcode = models.IntegerField(default=0) # 是否通过
|
||||
testdetail = JSONField(null=True, blank=True)
|
||||
score = models.FloatField(default=0) # 得分
|
||||
|
|
|
@ -35,6 +35,10 @@
|
|||
<input id="endtime" editable="false" name="endtime" class="easyui-datetimebox" style="width:90%"
|
||||
data-options="label:'最迟参加',currentText:'今天',closeText:'关闭',showSeconds: false,required:true" />
|
||||
</div>
|
||||
<div style="margin-bottom:5px;">
|
||||
<input id="testnum" name="testnum" class="easyui-numberbox" style="width:90%"
|
||||
data-options="label:'考试机会',prompt:'次数',min:1" required=true value="10"/>
|
||||
</div>
|
||||
<div style="margin-bottom:5px;">
|
||||
<label>是否公开</label>
|
||||
<input id="ispublicbutton" class="easyui-switchbutton" data-options="onText:'公开',offText:'不公开'" style="width: 80px;">
|
||||
|
|
|
@ -41,6 +41,10 @@
|
|||
<input id="endtime" editable="false" name="endtime" class="easyui-datetimebox" style="width:90%"
|
||||
data-options="label:'考试结束',currentText:'今天',closeText:'关闭',showSeconds: false,required:true" />
|
||||
</div>
|
||||
<div style="margin-bottom:5px;">
|
||||
<input id="testnum" name="testnum" class="easyui-numberbox" style="width:90%"
|
||||
data-options="label:'考试机会',prompt:'次数',min:1" required=true value="10"/>
|
||||
</div>
|
||||
<div style="margin-bottom:5px;">
|
||||
<label>是否公开</label>
|
||||
<input id="ispublicbutton" class="easyui-switchbutton" data-options="onText:'公开',offText:'不公开'" style="width: 80px;">
|
||||
|
|
|
@ -85,6 +85,9 @@
|
|||
<th style="width:10%">
|
||||
用时(s)
|
||||
</th>
|
||||
<th style="width:8%">
|
||||
考试次数
|
||||
</th>
|
||||
<th style="width:15%">
|
||||
答题详情
|
||||
</th>
|
||||
|
@ -99,18 +102,25 @@
|
|||
<td id="examdlid" style="display:none">{{$value.id}}</td>
|
||||
<td>{{$value.user__name}}</td>
|
||||
<td>{{$value.user__ubelongpart__partname}}</td>
|
||||
{{if $value.ison==0}}
|
||||
<td><font color="orange">可参加</font></td>
|
||||
{{else}}
|
||||
<td><font color="green">已参加</font></td>
|
||||
{{/if}}
|
||||
<td>
|
||||
{{if $value.testnum > 0}}
|
||||
<font color="red">已考</font>
|
||||
{{else}}
|
||||
<font color="red">未考</font>
|
||||
{{/if}}
|
||||
|
||||
{{if $value.remainnum > 0 && state==1}}
|
||||
<font color="orange">-可考</font>
|
||||
{{/if}}
|
||||
|
||||
</td>
|
||||
<td>{{$value.score}}</td>
|
||||
<td>{{$value.starttime}}</td>
|
||||
<td>{{$value.took}}</td>
|
||||
|
||||
<td>{{$value.testnum}}</td>
|
||||
<td><a target="_blank" href="/html/examhistory/{{$value.id}}">点击查看</a></td>
|
||||
{{if $value.passcode==0&&$value.ison==1&&state==1}}
|
||||
<td><button style="background-color: #00ff5a;color: #004eff;" onclick="showzhi(this)">重新发布试卷</button></td>
|
||||
{{if $value.passcode==0&&$value.remainnum==0&&state==1}}
|
||||
<td><button style="background-color: #00ff5a;color: #004eff;" onclick="showzhi(this)">补考一次</button></td>
|
||||
{{else}}
|
||||
<td><font color="green"></font></td>
|
||||
{{/if}}
|
||||
|
@ -168,12 +178,11 @@
|
|||
async: false, // ajax同步使用false
|
||||
success: function (data) {
|
||||
var cjrydetail = data.cjrydetail
|
||||
console.log(cjrydetail)
|
||||
data['yingkrs'] = cjrydetail.length //应考人数
|
||||
var x = 0
|
||||
var y = 0
|
||||
for(var i=0;i<cjrydetail.length;i++){
|
||||
if(cjrydetail[i].ison!=0){
|
||||
if(cjrydetail[i].testnum>0){
|
||||
x = x +1
|
||||
if(cjrydetail[i].passcode==1){
|
||||
y = y +1
|
||||
|
|
|
@ -5018,70 +5018,6 @@ def apitool(req):
|
|||
if created:
|
||||
print(i.partname + '建立默认地图')
|
||||
return JsonResponse({"code":1})
|
||||
elif a == 'panjuan':
|
||||
test = ExamTest.objects.get(id=req.GET.get('test'))
|
||||
answers = ExamPaperDetail.objects.filter(exampaper=test.exampaper).values('id', 'question__right')
|
||||
answersdict = {}
|
||||
for i in answers:
|
||||
answersdict['paperdetail' + str(i['id'])] = i['question__right']
|
||||
panjuanlist = ExamTestDetail.objects.filter(examtest=test)
|
||||
num = 0
|
||||
for obj in panjuanlist:
|
||||
tms = []
|
||||
wrongs = []
|
||||
rights = 0
|
||||
testdetail = obj.testdetail
|
||||
if testdetail:
|
||||
score = 0
|
||||
for i in testdetail: # 判卷
|
||||
iscore = 0
|
||||
i['question__right'] = answersdict['paperdetail'+str(i['id'])]
|
||||
if i['question__type'] == 2:
|
||||
if 'userchecked' in i:
|
||||
if i['userchecked']:
|
||||
if set(i['userchecked']) == set(i['question__right']):
|
||||
iscore = i['score']
|
||||
rights = rights + 1
|
||||
else:
|
||||
miniscore = i['score']/len(i['question__right'])
|
||||
wrongs.append(str(i['question__id']))
|
||||
for x in i['userchecked']:
|
||||
if x in i['question__right']:
|
||||
iscore = iscore + miniscore
|
||||
else:
|
||||
iscore = 0
|
||||
break
|
||||
else:
|
||||
if 'userchecked' in i:
|
||||
if i['userchecked']:
|
||||
if i['userchecked'] == i['question__right']:
|
||||
iscore = i['score']
|
||||
rights = rights + 1
|
||||
else:
|
||||
wrongs.append(str(i['question__id']))
|
||||
i['iscore'] = iscore
|
||||
score = score + iscore
|
||||
tms.append(str(i['question__id']))
|
||||
obj.testdetail = testdetail
|
||||
obj.rights = rights
|
||||
score = round(score,1)
|
||||
obj.score = score
|
||||
obj.ison = 1
|
||||
totalscore = test.totalscore
|
||||
passscore = test.passscore
|
||||
if score >= passscore:
|
||||
passcode = 1
|
||||
else:
|
||||
passcode = 0
|
||||
obj.passcode = passcode
|
||||
if tms:
|
||||
obj.tms = ','+','.join(tms)+','
|
||||
if wrongs:
|
||||
obj.wrongs = ','+','.join(wrongs)+','
|
||||
obj.save()
|
||||
num = num + 1
|
||||
print(str(num) + obj.examtest.name + obj.user.name + '得分' + str(score))
|
||||
return JsonResponse({"code":1})
|
||||
elif a == 'correct_tzzs':
|
||||
updateTzzs()
|
||||
return JsonResponse({"code":1})
|
||||
|
@ -6176,7 +6112,7 @@ def apiexamtest(req):
|
|||
if state == 'close':
|
||||
a = a.filter(state=0)
|
||||
if owner == 'yes':
|
||||
ownerlist = ExamTestDetail.objects.filter(user__userid=userid, examtest__state=1,ison=0).values_list('examtest__id',flat=True)
|
||||
ownerlist = ExamTestDetail.objects.filter(user__userid=userid, examtest__state=1,testnum=0).values_list('examtest__id',flat=True)
|
||||
a = a.filter(Q(id__in=ownerlist)|Q(ispublic=1))
|
||||
a = a.order_by('-id')
|
||||
total = a.count()
|
||||
|
@ -6222,8 +6158,8 @@ def apiexamtest(req):
|
|||
obj.passscore = data['passscore']
|
||||
obj.duration = data['duration']
|
||||
obj.createuser = User.objects.get(userid=userid)
|
||||
if 'retest_count' in data and data['retest_count']:
|
||||
obj.retest_count = data['retest_count']
|
||||
if 'testnum' in data and data['testnum']:
|
||||
obj.testnum = data['testnum']
|
||||
obj.save()
|
||||
obj.qrcode = makeqr_examtest(
|
||||
'https://safeyun.ctcshe.com/miniprogram/examtest?id='+str(obj.id))
|
||||
|
@ -6233,7 +6169,7 @@ def apiexamtest(req):
|
|||
b = []
|
||||
for i in ksry:
|
||||
uobj = User.objects.get(userid=i)
|
||||
ExamTestDetail.objects.create(examtest=obj, user=uobj)
|
||||
ExamTestDetail.objects.create(examtest=obj, user=uobj, remainnum = obj.testnum)
|
||||
b.append(uobj.openid)
|
||||
postdict = {
|
||||
'touser': '',
|
||||
|
@ -6319,8 +6255,8 @@ def apiexamtest(req):
|
|||
obj.ispublic = 1
|
||||
else:
|
||||
obj.ispublic = 0
|
||||
if 'retest_count' in data and data['retest_count']:
|
||||
obj.retest_count = data['retest_count']
|
||||
if 'testnum' in data and data['testnum']:
|
||||
obj.testnum = data['testnum']
|
||||
obj.save()
|
||||
obj.qrcode = makeqr_examtest(
|
||||
'https://safeyun.ctcshe.com/miniprogram/examtest?id='+str(obj.id))
|
||||
|
@ -6330,7 +6266,7 @@ def apiexamtest(req):
|
|||
b = []
|
||||
for i in ksry:
|
||||
uobj = User.objects.get(userid=i)
|
||||
ExamTestDetail.objects.create(examtest=obj, user=uobj)
|
||||
ExamTestDetail.objects.create(examtest=obj, user=uobj, remainnum = obj.testnum)
|
||||
b.append(uobj.openid)
|
||||
postdict = {
|
||||
'touser': '',
|
||||
|
@ -6379,36 +6315,36 @@ def apiexamtest(req):
|
|||
elif a == 'detail2':
|
||||
id = req.GET.get('id')
|
||||
a = ExamTest.objects.filter(id=id).values('id', 'num', 'name', 'starttime', 'endtime', 'duration', 'totalscore',
|
||||
'passscore', 'exampaper__total', 'createtime', 'state', 'exampaper__name', 'createuser__name', 'type', 'qrcode', 'retest_count')[0]
|
||||
'passscore', 'exampaper__total', 'createtime', 'state', 'exampaper__name', 'createuser__name', 'type', 'qrcode', 'testnum')[0]
|
||||
a['notinTime'] = 0
|
||||
if a['starttime'] > datetime.now():
|
||||
a['notinTime'] = 1
|
||||
if 'endtime' in a and a['endtime'] < datetime.now():
|
||||
a['notinTime'] = 1
|
||||
objs = ExamTestDetail.objects.filter(examtest__id=id).order_by('-score','-took').values(
|
||||
'id', 'user__name', 'user__ubelongpart__partname', 'took', 'score', 'ison', 'passcode','starttime', 'testnum')
|
||||
'id', 'user__name', 'user__ubelongpart__partname', 'took', 'score', 'remainnum', 'passcode','starttime', 'testnum')
|
||||
a['cjrydetail'] = list(objs)
|
||||
a['ison'] = 0
|
||||
a['remainnum'] = 0
|
||||
a['testnum'] = 0
|
||||
queryset = ExamTestDetail.objects.filter(examtest__id=id,user__userid=userid)
|
||||
if queryset.exists():
|
||||
a['ison'] = queryset[0].ison
|
||||
a['remainnum'] = queryset[0].remainnum
|
||||
a['testnum'] = queryset[0].testnum
|
||||
return HttpResponse(json.dumps(a, cls=MyEncoder), content_type="application/json")
|
||||
elif a == 'detail':
|
||||
id = req.GET.get('id')
|
||||
a = ExamTest.objects.filter(id=id).values('id', 'num', 'name', 'starttime', 'endtime', 'duration', 'totalscore',
|
||||
'passscore', 'exampaper__total', 'createtime', 'state', 'exampaper__name', 'createuser__name', 'type', 'qrcode', 'retest_count')[0]
|
||||
'passscore', 'exampaper__total', 'createtime', 'state', 'exampaper__name', 'createuser__name', 'type', 'qrcode', 'testnum')[0]
|
||||
a['notinTime'] = 0
|
||||
if a['starttime'] > datetime.now():
|
||||
a['notinTime'] = 1
|
||||
if 'endtime' in a and a['endtime'] < datetime.now():
|
||||
a['notinTime'] = 1
|
||||
a['ison'] = 0
|
||||
a['remainnum'] = 0
|
||||
a['testnum'] = 0
|
||||
queryset = ExamTestDetail.objects.filter(examtest__id=id,user__userid=userid)
|
||||
if queryset.exists():
|
||||
a['ison'] = queryset[0].ison
|
||||
a['remainnum'] = queryset[0].remainnum
|
||||
a['testnum'] = queryset[0].testnum
|
||||
return HttpResponse(json.dumps(a, cls=MyEncoder), content_type="application/json")
|
||||
elif a == 'detailtm':
|
||||
|
@ -6427,7 +6363,7 @@ def apiexamtest(req):
|
|||
a = ExamTest.objects
|
||||
a = a.filter(usecomps__contains=','+companyid + #未关闭的考试
|
||||
',').exclude(nousecomps__contains=','+companyid+',').filter(state=1,endtime__gte=datetime.now())
|
||||
ownerlist = ExamTestDetail.objects.filter(user__userid=userid, examtest__state=1,ison=0).values_list('examtest__id',flat=True)
|
||||
ownerlist = ExamTestDetail.objects.filter(user__userid=userid, examtest__state=1,testnum=0).values_list('examtest__id',flat=True)
|
||||
dknum = a.filter(Q(id__in=ownerlist)|Q(ispublic=1)).count()
|
||||
return JsonResponse({"code":1, "dknum":dknum})
|
||||
|
||||
|
@ -6439,14 +6375,13 @@ def apiexamtestdetail(req):
|
|||
companyid = getcompany(userid)
|
||||
if a == 'dknum':
|
||||
a = ExamTestDetail.objects
|
||||
a = a.filter(user__userid=userid, examtest__state=1,
|
||||
ison=0, examtest__endtime__gte=datetime.now())
|
||||
a = a.filter(user__userid=userid, examtest__state=1, testnum=0 , examtest__endtime__gte=datetime.now())
|
||||
dknum = a.count()
|
||||
return JsonResponse({"code": 1, "dknum": dknum})
|
||||
elif a == 'listdk':
|
||||
a = ExamTestDetail.objects
|
||||
a = a.filter(user__userid=userid, examtest__state=1,
|
||||
ison=0).order_by('-id')
|
||||
testnum=0).order_by('-id')
|
||||
total = a.count()
|
||||
startnum, endnum = fenye(req)
|
||||
a = a[startnum:endnum].values('id', 'examtest__id', 'examtest__name', 'examtest__starttime',
|
||||
|
@ -6462,23 +6397,22 @@ def apiexamtestdetail(req):
|
|||
return HttpResponse(transjson(total, a), content_type="application/json")
|
||||
elif a == 'listyk':
|
||||
a = ExamTestDetail.objects
|
||||
a = a.filter(user__userid=userid).exclude(ison=0)
|
||||
a = a.filter(user__userid=userid).exclude(testnum=0)
|
||||
total = a.count()
|
||||
startnum, endnum = fenye(req)
|
||||
a = a.order_by('-starttime')[startnum:endnum].values('id', 'examtest__id', 'examtest__name', 'starttime', 'examtest__passscore',
|
||||
'examtest__state', 'ison', 'examtest__duration', 'took', 'score', 'passcode')
|
||||
'examtest__state', 'testnum', 'examtest__duration', 'took', 'score', 'passcode', 'remainnum')
|
||||
return HttpResponse(transjson(total, a), content_type="application/json")
|
||||
elif a == 'handtest':
|
||||
data = json.loads(req.body.decode('utf-8'))
|
||||
testid = data['testid']
|
||||
examtestobj = ExamTest.objects.get(id=testid)
|
||||
obj,created = ExamTestDetail.objects.get_or_create(examtest = examtestobj, user__userid=userid,
|
||||
defaults={'examtest': examtestobj,'user':User.objects.get(userid=userid)})
|
||||
defaults={'examtest': examtestobj,'user':User.objects.get(userid=userid), 'remainnum':examtestobj.testnum})
|
||||
starttime = data['starttime']
|
||||
endtime = datetime.now()
|
||||
took = (endtime - datetime.strptime(starttime, '%Y-%m-%d %H:%M:%S')).total_seconds() #计算相差多少秒
|
||||
testdetail = data['sheet']
|
||||
obj.ison = 1
|
||||
obj.testdetail = testdetail
|
||||
obj.save()
|
||||
score = 0
|
||||
|
@ -6519,6 +6453,7 @@ def apiexamtestdetail(req):
|
|||
score = score + iscore
|
||||
tms.append(str(i['question__id']))
|
||||
obj.testnum = obj.testnum + 1
|
||||
obj.remainnum = obj.remainnum - 1 if obj.remainnum >= 1 else 0
|
||||
obj.starttime = starttime
|
||||
obj.endtime = endtime
|
||||
obj.took = took
|
||||
|
@ -6558,7 +6493,7 @@ def apiexamtestdetail(req):
|
|||
a = ExamTest.objects.get(id=id)
|
||||
if a.createuser==user:
|
||||
objss = ExamTestDetail.objects.get(id=examdlid)
|
||||
objss.ison=0
|
||||
objss.remainnum= objss.remainnum + 1
|
||||
objss.save()
|
||||
return JsonResponse({"code":1,"msg":"发布成功!"})
|
||||
else:
|
||||
|
@ -6593,14 +6528,14 @@ def apiexamtestrate(req):
|
|||
'''
|
||||
companyid = req.GET.get('companyid')
|
||||
alltest = ExamTest.objects.filter(usecomps__contains=','+str(companyid)+',').exclude(nousecomps__contains=','+str(companyid)+',')
|
||||
allexamtestdetail = ExamTestDetail.objects.filter(examtest__in=alltest,ison=1)
|
||||
allexamtestdetail = ExamTestDetail.objects.filter(examtest__in=alltest,testnum__gte=1)
|
||||
objs = allexamtestdetail.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()
|
||||
objslist = list(objs)
|
||||
for i in objslist:
|
||||
i['rate'] = objslist.index(i) + 1
|
||||
i['avgscore'] = round(i['totalscore']/i['testnum'],1)
|
||||
orgsCal = allexamtestdetail.filter(score__gt=0,ison__gt=0).values('user__ubelongpart__partid','user__ubelongpart__partname').annotate(totaltest=Count('user__ubelongpart__partid'),avgscore=Avg('score')).order_by('-totaltest','-avgscore')
|
||||
orgsCal = allexamtestdetail.filter(score__gt=0,testnum__gte=1).values('user__ubelongpart__partid','user__ubelongpart__partname').annotate(totaltest=Count('user__ubelongpart__partid'),avgscore=Avg('score')).order_by('-totaltest','-avgscore')
|
||||
allattenduser = allexamtestdetail.values_list('user__userid', flat=True)
|
||||
orgsCallist = list(orgsCal)
|
||||
for i in orgsCallist:
|
||||
|
|
Loading…
Reference in New Issue