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