.
[HamExam.git] / framework.py
blob89cd03105c0cecbe63c1307d54b6b6970119eeda
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 self.s.badquestion.pop (self.s.badquestion.index (qid))
14 elif self.method == "GoodQuestions":
15 if self.loud:
16 print "Good questions"
17 qid = self.FindGoodQuestion()
18 self.s.goodquestion.pop (self.s.goodquestion.index (qid))
19 elif self.method == "NewQuestions":
20 if self.loud:
21 print "New question"
22 qid = self.FindNewQuestion()
23 self.s.newquestion.pop (self.s.newquestion.index (qid))
24 else:
25 qid = self.FindAnyQuestion()
27 if self.loud:
28 print "Question id:",qid
30 self.q.AskQuestion (qid)
31 self.id = qid
32 self.question = self.q.question
33 self.answera = self.q.answera
34 self.answerb = self.q.answerb
35 self.answerc = self.q.answerc
36 self.answerd = self.q.answerd
37 self.answercorrect = self.q.answercorrect
38 self.hint = self.q.hint
39 self.correct, self.wrong, self.correct_successive, self.wrong_successive = self.s.ThisQuestion (self.id)
41 self.time0 = time.time()
43 def EvalQuestion(self, answer):
44 if self.q.correct == answer:
45 c = True
46 else:
47 c = False
49 if self.loud:
50 print "Answer was:",answer
51 print "Correct was:",self.q.correct
53 self.time1 = time.time()
54 dt = self.time1-self.time0
56 tt = self.s.IncreaseCounter (self.id, c, self.q.RealAnswer(answer), dt)
57 if tt == True:
58 self.s.goodquestion.append(self.id)
59 else:
60 self.s.badquestion.append(self.id)
62 return c
64 def Method(self,method="AnyQuestion"):
65 self.method=method
67 def FindAnyQuestion(self):
68 return r.sample(self.q.questions,1)[0]
70 def FindNewQuestion(self):
71 return r.sample(self.s.newquestion,1)[0]
73 def FindBadQuestion(self):
74 return r.sample(self.s.badquestion,1)[0]
76 def FindGoodQuestion(self):
77 return r.sample(self.s.newquestion,1)[0]
79 def Close(self):
80 self.s.WriteFile()
82 def CategorizeQuestions(self):
83 if self.loud:
84 print "Categorize questions"
85 for q in self.q.questions:
86 if not (q[0] in self.s.goodquestion):
87 if not (q[0] in self.s.badquestion):
88 if not (q[0] in self.s.newquestion):
89 self.s.newquestion.append (q[0])
90 if self.loud:
91 print "total, good, bad, new:",len(self.q.questions),len(self.s.goodquestion),len(self.s.badquestion),len(self.s.newquestion)
93 def __init__(self,method="BadQuestions",catalog="TechnikA"):
94 if catalog == "TechnikA":
95 stat = "TechnikA/DL-A-2007.stat.xml"
96 elif catalog == "TechnikE":
97 stat = "TechnikE/DL-E-2007.stat.xml"
98 elif catalog == "BetriebAE":
99 stat = "BetriesAE/FIXMEtat.xml" #FIXME
101 self.question_dir = catalog+"/www.oliver-saal.de/software/afutrainer/download/"
102 self.hint_dir = catalog+"/"
103 quest = self.question_dir + "questions.xml"
105 self.q = questions.Questions(filename=quest)
106 self.s = statistic.Statistic(filename=stat)
107 self.method = method
108 self.CategorizeQuestions()