| | |
| | | |
| | | def generateVariables(self): |
| | | for key in self.parsedVariables: |
| | | self.varDict[key] = Variable(next(self.variableGenerator[key]), self.parsedVariables[key]['type']) |
| | | self.varDict[key] = Variable( |
| | | next(self.variableGenerator[key]), self.parsedVariables[key]["type"] |
| | | ) |
| | | |
| | | def generateSolutions(self): |
| | | pass |
| | |
| | | return False |
| | | |
| | | def substitute_variables(self, text): |
| | | for key,var in self.varDict.items(): |
| | | text=re.sub ("\/\*\/"+key+"\/\*\/", var.format_as_tex(), text) |
| | | for key, var in self.varDict.items(): |
| | | text = re.sub("\/\*\/" + key + "\/\*\/", var.format_as_tex(), text) |
| | | return text |
| | | |
| | | def substitute_octave(self,text): |
| | | text = re.sub("\^", "**", text) |
| | | text = re.sub(";", "\n", text) |
| | | return text |
| | | def substitute_octave(self, text): |
| | | text = re.sub("\^", "**", text) |
| | | text = re.sub(";", "\n", text) |
| | | return text |
| | | |
| | | def solve(self): |
| | | #a dirty one but it has to be like this ;) |
| | | # a dirty one but it has to be like this ;) |
| | | __retsol = [] |
| | | |
| | | #define variables |
| | | for __varname,__var in self.varDict.items(): |
| | | exec(__varname+"="+str(__var.get_formatted_value())) |
| | | # define variables |
| | | for __varname, __var in self.varDict.items(): |
| | | exec(__varname + "=" + str(__var.get_formatted_value())) |
| | | for __s in self.parsedSolutions: |
| | | __ps = {} |
| | | __ps['correct'] = [] |
| | | __ps['wrong'] = [] |
| | | #for __s in self.parsedSolutions: |
| | | for __corr in __s['correct']: |
| | | for __corrsplit in __corr.split(';'): |
| | | if(__corrsplit.find("=")>=0): |
| | | __ps["correct"] = [] |
| | | __ps["wrong"] = [] |
| | | # for __s in self.parsedSolutions: |
| | | for __corr in __s["correct"]: |
| | | for __corrsplit in __corr.split(";"): |
| | | if __corrsplit.find("=") >= 0: |
| | | exec(self.substitute_octave(__corrsplit)) |
| | | else: |
| | | __result=eval(self.substitute_octave(__corrsplit)) |
| | | __ps['correct'].append(Variable(__result, formatting=__s['type'])) |
| | | for __corr in __s['wrong']: |
| | | for __corrsplit in __corr.split(';'): |
| | | if(__corrsplit.find("=")>=0): |
| | | __result = eval(self.substitute_octave(__corrsplit)) |
| | | __ps["correct"].append(Variable(__result, formatting=__s["type"])) |
| | | for __corr in __s["wrong"]: |
| | | for __corrsplit in __corr.split(";"): |
| | | if __corrsplit.find("=") >= 0: |
| | | exec(self.substitute_octave(__corrsplit)) |
| | | else: |
| | | __result=eval(self.substitute_octave(__corrsplit)) |
| | | __ps['wrong'].append(Variable(__result, formatting=__s['type'])) |
| | | __result = eval(self.substitute_octave(__corrsplit)) |
| | | __ps["wrong"].append(Variable(__result, formatting=__s["type"])) |
| | | __retsol.append(__ps) |
| | | return __retsol |
| | | |
| | | def generate_tex(self, shuffle=True): |
| | | intro=self.substitute_variables(self.introduction) |
| | | sp=[] |
| | | intro = self.substitute_variables(self.introduction) |
| | | sp = [] |
| | | for p in self.subproblems: |
| | | sp.append(self.substitute_variables(p)) |
| | | sol=self.solve() |
| | | soltex=[] |
| | | sol = self.solve() |
| | | soltex = [] |
| | | for s in sol: |
| | | entry={'correct': [i.format_as_tex() for i in s['correct']], 'wrong': [i.format_as_tex() for i in s['wrong']]} |
| | | entry = { |
| | | "correct": [i.format_as_tex() for i in s["correct"]], |
| | | "wrong": [i.format_as_tex() for i in s["wrong"]], |
| | | } |
| | | soltex.append(entry) |
| | | return (intro, sp, soltex) |
| | | |
| | | return intro, sp, soltex |