.
[HamExam.git] / framework.py
blob24c699b100fb0dfc22fbecd81447296d41efa3c9
1 import questions, statistic
2 import random as r
4 class Framework:
5 def AskQuestion(self):
6 if self.method == "BadQuestions":
7 #FIXME
8 qid = self.FindBadQuestion()
9 elif self.method == "GoodQuestions":
10 #FIXME
11 qid = self.FindGoodQuestion()
12 elif self.method == "NewQuestions":
13 #FIXME
14 qid = self.FindNewQuestion()
15 else:
16 qid = self.FindAnyQuestion()
18 self.q.AskQuestion (qid)
19 self.id = qid
20 self.question = self.q.question
21 self.answera = self.q.answera
22 self.answerb = self.q.answerb
23 self.answerc = self.q.answerc
24 self.answerd = self.q.answerd
25 self.answercorrect = self.q.answercorrect
26 self.hint = self.q.hint
27 self.correct, self.wrong = self.s.ThisQuestion (self.id)
29 def EvalQuestion(self, answer):
30 if self.q.correct == answer:
31 c = True
32 else:
33 c = False
35 self.s.IncreaseCounter (self.id, c, self.q.RealAnswer(answer))
37 return c
39 def FindAnyQuestion(self):
40 nq = int (r.random()*self.q.nquestions)
41 return self.q.questions[nq][0]
43 def FindNewQuestion(self):
44 nq = r.randint(0,self.s.nnewquestion)
45 return self.s.newquestion[nq]
47 def FindBadQuestion(self):
48 nq = r.randint(0,self.s.nbadquestion)
49 return self.s.badquestion[nq]
51 def FindGoodQuestion(self):
52 nq = r.randint(0,self.s.ngoodquestion)
53 return self.s.goodquestion[nq]
55 def Close(self):
56 self.s.WriteFile()
58 def __init__(self,method="",catalog="TechnikA"):
59 if catalog == "TechnikA":
60 quest = "TechnikA/www.oliver-saal.de/software/afutrainer/download/questions.xml"
61 stat = "TechnikA/DL-A-2007.stat.xml"
62 elif catalog == "TechnikE":
63 quest = "TechnikE/www.oliver-saal.de/software/afutrainer/download/questions.xml"
64 stat = "TechnikE/DL-E-2007.stat.xml"
65 elif catalog == "BetriebAE":
66 quest = "TechnikA/www.oliver-saal.de/software/afutrainer/download/questions.xml"
67 stat = "BetriesAE/FIXMEtat.xml" #FIXME
69 self.q = questions.Questions(filename=quest)
70 self.s = statistic.Statistic(filename=stat)
71 self.method = method