.
[HamExam.git] / framework.py
blob1e24ae911ca87e630510140cd06193d836ba4cc0
1 import questions, statistic
2 import random as r
3 import time
5 class Framework:
6 def AskQuestion(self):
7 if self.method == "BadQuestions":
8 print "Bad question"
9 qid = self.FindBadQuestion()
10 elif self.method == "GoodQuestions":
11 print "Good questions"
12 qid = self.FindGoodQuestion()
13 elif self.method == "NewQuestions":
14 print "New qurstion"
15 qid = self.FindNewQuestion()
16 else:
17 qid = self.FindAnyQuestion()
19 self.q.AskQuestion (qid)
20 self.id = qid
21 self.question = self.q.question
22 self.answera = self.q.answera
23 self.answerb = self.q.answerb
24 self.answerc = self.q.answerc
25 self.answerd = self.q.answerd
26 self.answercorrect = self.q.answercorrect
27 self.hint = self.q.hint
28 self.correct, self.wrong, self.correct_successive, self.wrong_successive = self.s.ThisQuestion (self.id)
30 self.time0 = time.time()
32 def EvalQuestion(self, answer):
33 if self.q.correct == answer:
34 c = True
35 else:
36 c = False
38 print "Answer was:",answer
39 print "Correct was:",self.q.correct
41 self.time1 = time.time()
42 dt = self.time1-self.time0
44 self.s.IncreaseCounter (self.id, c, self.q.RealAnswer(answer), dt)
46 return c
48 def Method(self,method="AnyQuestion"):
49 self.method=method
51 def FindAnyQuestion(self):
52 return r.sample(self.q.questions,1)[0]
54 def FindNewQuestion(self):
55 return r.sample(self.s.newquestion,1)[0]
57 def FindBadQuestion(self):
58 return r.sample(self.s.badquestion,1)[0]
60 def FindGoodQuestion(self):
61 return r.sample(self.s.newquestion,1)[0]
63 def Close(self):
64 self.s.WriteFile()
66 def CategorizeQuestions(self):
67 print "Categorize questions"
68 for q in self.q.questions:
69 if not (q[0] in self.s.goodquestion):
70 if not (q[0] in self.s.badquestion):
71 if not (q[0] in self.s.newquestion):
72 self.s.newquestion.append (q[0])
73 print "total, good, bad, new:",len(self.q.questions),len(self.s.goodquestion),len(self.s.badquestion),len(self.s.newquestion)
75 def __init__(self,method="BadQuestions",catalog="TechnikA"):
76 if catalog == "TechnikA":
77 stat = "TechnikA/DL-A-2007.stat.xml"
78 elif catalog == "TechnikE":
79 stat = "TechnikE/DL-E-2007.stat.xml"
80 elif catalog == "BetriebAE":
81 stat = "BetriesAE/FIXMEtat.xml" #FIXME
83 self.question_dir = catalog+"/www.oliver-saal.de/software/afutrainer/download/"
84 self.hint_dir = catalog+"/"
85 quest = self.question_dir + "questions.xml"
87 self.q = questions.Questions(filename=quest)
88 self.s = statistic.Statistic(filename=stat)
89 self.method = method
90 self.CategorizeQuestions()