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