def GetTable1(a, coursename): problem = coursedb.Get_Course_Problem(coursename) all = [] ID = 1 for item in problem: now = [] now.append(ID) now.append(item[0]) now.append(item[2]) s = "" Knowledge = knowledgedb.Get_Knowledge_BY_Problem(coursename, item[0]) first = True for tmp in Knowledge: if first: first = False else: s += ', ' s += tmp now.append(s) ID += 1 all.append(now) ans = [] for every in all: if a in every[1] or a in every[3]: ans.append(every) return ans
def UpdateProblem(request): if 'course' not in request.session.keys(): messages.success(request, "先选择课程") return HttpResponseRedirect("/teacher/") Map = {} coursename = request.session['course'] if request.method == "POST": query = request.POST.get('query') update = request.POST.get('update') if query != None: optionproblem = request.POST.get('optionproblem') problem = coursedb.Get_Course_Problem(coursename) Map['problem'] = problem Map['knowledges'] = knowledgedb.Get_Course_Knowledge(coursename) Map['optionproblem'] = knowledgedb.Get_a_Course_Problem( coursename, optionproblem) Map['knowledge'] = knowledgedb.Get_Knowledge_BY_Problem( coursename, optionproblem) Map['table'] = GetTable1("", coursename) return render(request, 'problem.html', Map) elif update != None: optionproblem = request.POST.get('optionproblem') score = request.POST.get('score') problem_detail = request.POST.get('problem_detail') knowledges = request.POST.getlist('knowledges') if score == "" or score == None: score = 0 if optionproblem != None and score != None: coursedb.Add_Course_Problem1(coursename, optionproblem, score, problem_detail) knowledgedb.DelProblemKnowledge(coursename, optionproblem) for item in knowledges: knowledgedb.Add_Problem_Knowledge(coursename, optionproblem, item) return HttpResponseRedirect('/problem/')
def UpdateStudentScore(request, studentid): if 'course' not in request.session.keys(): messages.success(request, "先选择课程") return HttpResponseRedirect("/teacher/") Map = {} coursename = request.session['course'] if request.method == "POST": problems = coursedb.Get_Course_Problem(coursename) for item in problems: now = request.POST.get(item[0]) if now != None: coursedb.Add_Course_Problem_Student(coursename, item[0], studentid, now) return HttpResponseRedirect('/student/' + str(studentid) + '/')
def Upload(request): if 'course' not in request.session.keys(): messages.success(request, "先选择课程") return HttpResponseRedirect("/teacher/") Map = {} coursename = request.session['course'] #题目表problemtable 编号 题目 题目总分 problems = coursedb.Get_Course_Problem(coursename) problemtable = [] ID = 1 for item in problems: now = [] now.append(ID) now.append(item[0]) now.append(item[2]) problemtable.append(now) ID += 1 Map['problemtable'] = problemtable #分数表的表头scoretablehead scoretablehead = [] scoretablehead.append('编号') scoretablehead.append('学号') for item in problems: scoretablehead.append(item[0]) scoretablehead.append('总分') Map['scoretablehead'] = scoretablehead #分数表的内容score students = coursedb.Get_Course_Student(coursename) score = coursedb.Get_Course_AllScore(coursename, problems, students) scoretable = [] ID = 1 for item in score: now = [] now.append(ID) now.append(students[ID - 1]) for tmp in item: now.append(tmp) now.append(sum(item)) scoretable.append(now) ID += 1 Map['scoretable'] = scoretable return render(request, 'upload.html', Map)
def Problem(request): if 'course' not in request.session.keys(): messages.success(request, "先选择课程") return HttpResponseRedirect("/teacher/") Map = {} coursename = request.session['course'] problem = coursedb.Get_Course_Problem(coursename) Map['problem'] = problem Map['knowledges'] = knowledgedb.Get_Course_Knowledge(coursename) if len(problem) != 0: Map['optionproblem'] = knowledgedb.Get_a_Course_Problem( coursename, problem[0][0]) Map['knowledge'] = knowledgedb.Get_Knowledge_BY_Problem( coursename, problem[0][0]) Map['table'] = GetTable1("", coursename) if request.method == "POST": if request.POST.get('problem') != None: Map['table'] = GetTable1(request.POST.get('problem'), coursename) return render(request, 'problem.html', Map)
def Knowledge(request): if 'course' not in request.session.keys(): messages.success(request, "先选择课程") return HttpResponseRedirect("/teacher/") Map = {} coursename = request.session['course'] knowledge = knowledgedb.Get_Course_Knowledge(coursename) Map['knowledge'] = knowledge Map['problems'] = coursedb.Get_Course_Problem(coursename) if len(knowledge) != 0: Map['problem'] = knowledgedb.Get_Problem_BY_Knowledge( coursename, knowledge[0]) Map['optionknowledge'] = knowledgedb.Get_a_Course_Knowledge( coursename, knowledge[0]) Map['table'] = GetTable("", coursename) if request.method == "POST": if request.POST.get('knowledge') != None: Map['table'] = GetTable(request.POST.get('knowledge'), coursename) return render(request, 'knowledge.html', Map)
def UpdateKnowledge(request): if 'course' not in request.session.keys(): messages.success(request, "先选择课程") return HttpResponseRedirect("/teacher/") Map = {} coursename = request.session['course'] if request.method == "POST": #a = request.POST.getlist('problems') query = request.POST.get('query') update = request.POST.get('update') if query != None: optionknowledge = request.POST.get('optionknowledge') knowledge = knowledgedb.Get_Course_Knowledge(coursename) Map['knowledge'] = knowledge Map['problems'] = coursedb.Get_Course_Problem(coursename) problem = knowledgedb.Get_Problem_BY_Knowledge( coursename, optionknowledge) Map['problem'] = problem Map['optionknowledge'] = knowledgedb.Get_a_Course_Knowledge( coursename, optionknowledge) #return HttpResponse(Map['knowledge_detail']) Map['table'] = GetTable("", coursename) return render(request, 'knowledge.html', Map) elif update != None: optionknowledge = request.POST.get('optionknowledge') knowledge_detail = request.POST.get('knowledge_detail') problems = request.POST.getlist('problems') if optionknowledge != None and knowledge_detail != None and problems != None: knowledgedb.Add_Course_Knowledge(coursename, optionknowledge, knowledge_detail) knowledgedb.DelKnowledgeProblem(coursename, optionknowledge) for item in problems: knowledgedb.Add_Problem_Knowledge(coursename, item, optionknowledge) return HttpResponseRedirect('/knowledge/')
def StudentID(request, studentid): if 'course' not in request.session.keys(): messages.success(request, "先选择课程") return HttpResponseRedirect("/teacher/") Map = {} coursename = request.session['course'] thisstudent = studentdb.Get_Student_information(studentid) student = [] student.append(thisstudent.studentid) student.append(thisstudent.studentname) student.append(thisstudent.email) student.append(thisstudent.phone) student.append(thisstudent.sex) thisstudentscore = studentdb.Get_Student_Course(studentid, coursename) thisstudentproblem = coursedb.Get_Course_Problem(coursename) table = [] ID = 1 for i in range(len(thisstudentproblem)): now = [] now.append(ID) now.append(thisstudentscore[1][i][0]) tmp = knowledgedb.Get_Knowledge_BY_Problem(coursename, thisstudentscore[1][i][0]) ccc = "" first = True for cnt in tmp: if first: first = False else: ccc += "," ccc += cnt now.append(ccc) now.append(thisstudentscore[1][i][1]) now.append(thisstudentproblem[i][2]) ID += 1 table.append(now) Map['sum'] = thisstudentscore[0] Map['table'] = table Map['student'] = student table1 = [] knowledge = knowledgedb.Get_Course_Knowledge(coursename) ID = 1 for item in knowledge: now = [] now.append(ID) ID += 1 now.append(item) tmp = knowledgedb.Get_Problem_BY_Knowledge(coursename, item) ccc = "" first = True for cnt in tmp: if first: first = False else: ccc += "," ccc += cnt now.append(ccc) now.append( knowledgedb.Get_Knowledge_Score_Student(coursename, item, studentid)) now.append(knowledgedb.Get_Knowledge_Score(coursename, item)) table1.append(now) Map['table1'] = table1 return render(request, 'student.html', Map)
def Index(request): if 'course' not in request.session.keys(): messages.success(request, "先选择课程") return HttpResponseRedirect("/teacher/") Map = {} #总分展示 coursename = request.session['course'] allscore = coursedb.Get_Course_Sum_Score(coursename) if len(allscore) == 0: return render(request, "index.html", Map) allscore.sort() sumscore = coursedb.Get_Course_Scoresum(coursename) score = [] score.append(sumscore) score.append(date.List_Avg(allscore)) score.append(len(allscore)) score.append(allscore[-1]) score.append(allscore[0]) score.append(date.List_Mid(allscore)) score.append(date.List_Std(allscore)) score.append(date.List_Var(allscore)) #十等分 scoreinterval = [] nowscore = int(sumscore + 9) // 10 j = 0 jige = 0 n = len(allscore) for i in range(10): if i == 0: L = 0 else: L = i * nowscore + 1 R = (i + 1) * nowscore if R > sumscore: R = sumscore number = 0 while j < n and allscore[j] <= R: j += 1 number += 1 if i >= 6: jige += number now = [L, R, number] scoreinterval.append(now) if R == sumscore: break score.append('{:.2f}%'.format(100 * jige / n)) Map['score'] = score Map['scoreinterval'] = scoreinterval problems = coursedb.Get_Course_Problem(coursename) if len(problems) == 0: return render(request, "index.html", Map) #小题展示 Map['problems'] = problems selects = problems[0][0] if request.method == 'POST': if request.POST.get('option') != None: selects = request.POST.get('option') Map['selects'] = selects allscore = coursedb.Get_CourseScore_byproblem(coursename, selects) sumscore = coursedb.Get_Course_Problem_Score(coursename, selects) score = [] if len(allscore) != 0: allscore.sort() score.append(sumscore) score.append(date.List_Avg(allscore)) score.append(len(allscore)) score.append(allscore[-1]) score.append(allscore[0]) score.append(date.List_Mid(allscore)) score.append(date.List_Std(allscore)) score.append(date.List_Var(allscore)) Map['score1'] = score #十等分 j = 0 n = len(allscore) scoreinterval = [] number = 0 while j < n and allscore[j] == 0: j += 1 number += 1 scoreinterval.append([0, 0, number]) nowscore = int(sumscore + 9) // 10 for i in range(10): L = i * nowscore + 1 R = (i + 1) * nowscore if R > sumscore: R = sumscore number = 0 while j < n and allscore[j] <= R: j += 1 number += 1 now = [L, R, number] scoreinterval.append(now) if R == sumscore: break Map['scoreinterval1'] = scoreinterval return render(request, "index.html", Map)