def doOutput(self): if "showinput" in self.pld: # valeur sans importance self.fb.showinput = True if "failure" in self.pld and not self.fb.success: self.fb.addFeedback(self.pld["failure"]) if "taboo" in self.pld and checktaboo(self.pld["taboo"], "student"): self.fb.adddiv( "ftaboo", " la liste des mots taboo " + self.pld["taboo"] + ". Raté !\n <br>Ces mots ne doivent pas apparaitre dans votre solution !\n" ) self.fb.success = False if "needed" in self.pld and checkneeded(self.pld["needed"], "student"): #~ self.fb.addFeedback(" la liste des mots obligatoires :"+self.pld["needed"]+". Raté !\n") #~ self.fb.addFeedback(" ces mots doivent apparaitres dans votre solution !\n") self.fb.adddiv( "fneeded", "la liste des mots obligatoires :" + self.pld["needed"] + ". Raté !\n <br>ces mots doivent apparaitres dans votre solution !\n" ) self.fb.success = False output(100 if self.fb.success else 0, self.fb.feedback())
def grade(cls, context, answers): """Grade the answers according to context, exiting the script through sandboxio.output().""" grader = cls(context, answers) ret = grader.compile() if ret[0]: # Student compilation failed: feedback = "Compilation error:<br/><br/><pre><code>" + ret[ 2] + "</code></pre>" sandboxio.output(0, feedback) taboos = grader.taboo() if taboos: feedback = "These words are disallowed an cannot be used: " + str( taboos) sandboxio.output(-1, feedback) tests = grader.run_tests() if tests: grade, feedback = cls.parse_tests_result(tests) sandboxio.output(grade, feedback) junit = grader.run_junit() if junit: grade, feedback = junit feedback = ( "<pre><code>%s</code></pre>" % feedback.replace("[36m", "").replace("[34m", "").replace( "[32m", "").replace("[31m", "").replace("[0m", "")) sandboxio.output(grade, feedback) print( "Both of the keys 'stdout_tests' and 'junit' are missing. At least one must be " "present for the Grader to be able to grade the student's answer.", file=sys.stderr) sys.exit(1)
def grade(cls, context, answers): """Grade the answers according to context, exiting the script through sandboxio.output().""" grader = cls(context, answers) path = grader.context["student_file"] with open(path, "w+") as f: f.write(grader.code) taboos = grader.taboo() if taboos: feedback = "These words are disallowed an cannot be used: " + str(taboos) sandboxio.output(-1, feedback) tests = grader.run_tests() if tests: grade, feedback = cls.parse_tests_result(tests) sandboxio.output(grade, feedback) unit = grader.run_unittest() if unit: grade, feedback = unit feedback = ( "<pre><code>%s</code></pre>" % feedback ) sandboxio.output(grade, feedback) print("Both of the keys 'stdout_tests' and 'unittest' are missing. At least one must be " "present for the Grader to be able to grade the student's answer.", file=sys.stderr) sys.exit(1)
from pltest_doc import PlRunner dic = get_context() if "pltest" not in dic and "pltest1" not in dic: print("No pltest neither pltest1-n defined change template", file=sys.stderr) sys.exit(1) if 'stopfirsterror' in dic: stop=bool(dic['stopfirsterror']) else: stop=False student = get_answers()['answer'] outstr="" if "pltest" in dic: pltest = dic['pltest'] tester = PlRunner(student,pltest) a, b = tester.runpltest(1) else: a,b= True, "" i=1 while "pltest"+str(i) in dic and (a or stop ) : outstr += b testi = PlRunner(student,dic["pltest"+str(i)]) a, b = testi.runpltest(i+1) i=i+1 outstr += b if "feedback" in dic: # FIXME feedback devrai être un dictionnaire. outstr += dic["feedback"] output(a,outstr)
format_feedback = format_analysis('warning', feedback, maxattempt - nbattempt, lang) else: if nbattempt < maxattempt: format_feedback = format_analysis('retry', feedback, maxattempt - nbattempt, lang) else: format_feedback = format_analysis('fail', feedback, 0, lang) dic['form'] = dic[ 'form0'] + "\n <div style='width:100%;height:200px;'></div>" if 'style' in dic: dic['form'] += """ <style> {} </style> """.format(dic['style']) if 'links' in dic: dic['form'] += dic['links'] if 'script' in dic: dic['form'] += """ <script> {} </script> """.format(dic['script']) output(score, format_feedback, dic)
answer of the student. The function should return a tuple (int, feedback) where int is the grade between [0, 100].""" missing_grade_stderr = """\ 'evalfunc' did not return a tuple (int, feedback) where int is the grade between [0, 100].""" if __name__ == "__main__": if len(sys.argv) < 5: msg = ( "Sandbox did not call grader properly:\n" + "Usage: python3 grader.py [input_json] [output_json] [answer_file] [" "feedback_file]") print(msg, file=sys.stderr) sys.exit(1) dic = get_context() answers = get_answers() if 'evalfunc' in dic: exec(dic['evalfunc'], globals()) grade = evalfunc(dic, answers) else: print(missing_evaluator_stderr, file=sys.stderr) sys.exit(1) if len(grade) < 2 or type(grade[0]) is not int or type( grade[1]) is not str: print(missing_grade_stderr, file=sys.stderr) sys.exit(1) output(grade[0], grade[1], dic)
# generation of the form for index in indices: if index < len(question[1]): context['goods'].append(str(index)) context['form'] +='<input type="checkbox" name="c_' + \ str(index) + '" value="' + str(index) + '" id="form_' + \ str(index) + '">' + question[1][index] + "<br />" else: context['bads'].append(str(index)) context['form'] +='<input type="checkbox" name="c_' + \ str(index) + '" value="' + str(index) + '" id="form_' + \ str(index) + '">' + \ question[2][index - len(question[1])] + "<br />" output(-1, "", context) if len(context['grade_questions']) == len(context['indices_questions']): grade = 0 for g in context['grade_questions']: grade += g grade = grade // len(context['grade_questions']) context['form'] = '' context['text'] = '' feedback = "Vous avez obtenu <b>" + str( grade) + "%</b> de réussite à votre QCM." output(grade, feedback, context) output(-1, "THAT SHOULD NEVER HAPPEN !!!!", context)
#!/usr/bin/env python3 # coding: utf-8 import sys, jsonpickle from sandboxio import output, get_context, get_answers missing_evaluator_stderr = """\ The key 'evaluator' was not found in the context. When using this grader, the PL must declare a script inside a key 'evaluator'. This script have access to every variable declared in the PL and its 'before' script. It should declare a variable 'grade' which should contain a tuple (int, feedback) where int is the grade between [0, 100].""" missing_grade_stderr = """\ 'evaluator' did not declare the variable 'grade'. The script have access to every variable declared in the PL and its 'before' script. It should declare a variable 'grade' which should contain a tuple (int, feedback) where int is the grade between [0, 100].""" if __name__ == "__main__": if len(sys.argv) < 5: msg = ( "Sandbox did not call grader properly:\n" + "Usage: python3 grader.py [input_json] [output_json] [answer_file] [feedback_file]" ) print(msg, file=sys.stderr) sys.exit(1) dic = get_context() studentdic = get_answers() dic["text"] = " Passez à l'exercice suivant " dic["form"] = "" output(100, " Merci de votre réponse ", dic)
dic = get_context() if "plsoluce" not in dic: print("No plsoluce in dic necessary for this template " , file=sys.stderr) sys.exit(1) if "soluce" not in dic and not os.exist("soluce.py"): print("No soluce or file soluce.py necessary for this template " , file=sys.stderr) sys.exit(1) if "soluce" in dic: with open("soluce.py","w") as sol: sol.write(dic['soluce']) lestest=[] for i,line in enumerate(dic['plsoluce'].split("\n")): if line != "" : # problem with finishing empty line if len(line.split('|')) != 2 : print(" to many | ",len(line.split('|')) ,"in test line ",i,": ", str(beurkl), file=sys.stderr) sys.exit(1) lestest.append(line.split('|')) student = get_answers()['answer'] with open("student.py","w") as sf: sf.write(student) import feedback2 fb=feedback2.FeedBack() ret=runsolucetests(lestest,fb) output(ret, fb.render())
It should declare a variable 'grade' which should contain a tuple (int, feedback) where int is the grade between [0, 100].""" if __name__ == "__main__": if len(sys.argv) < 5: msg = ( "Sandbox did not call grader properly:\n" + "Usage: python3 grader.py [input_json] [answer_jsonfile] [output_json] [feedback_file]" ) print(msg, file=sys.stderr) sys.exit(1) dic = get_context() dic['response'] = get_answers() if 'evaluator' in dic: glob = {} dic['StopEvaluatorExec'] = StopEvaluatorExec exec(add_try_clause(dic['evaluator'], StopEvaluatorExec), dic) exec("", glob) for key in glob: if key in dic and dic[key] == glob[key]: del dic[key] else: print(missing_evaluator_stderr, file=sys.stderr) sys.exit(1) if 'grade' not in dic: print(missing_grade_stderr, file=sys.stderr) sys.exit(1) output(dic['grade'][0], dic['grade'][1], dic)
f.close() grade = 0 ok = 0 not_ok = 0 for good in context['goods']: if good in answers: ok += 1 else: not_ok += 1 for bad in context['bads']: if bad in answers: not_ok += 1 else: ok += 1 grade = 100*ok // (ok+not_ok) if grade != 100: if not_ok > 1: feedback = "Non, il y a malheuresement " + str(not_ok) + " erreurs" else: feedback = "Non, il y a une erreur" else: feedback = "Bravo, c'est correct !" output(grade, feedback)
# Here dic = get_context() truc = get_answers() # {'answer':value } pas que form_answer with open("basic.c","w") as basic: basic.write(truc["answer"]) # print(truc["answer"], file=sys.stderr) basic.close() from graderC import graderI, graderII assert('tests' in dic), "Your exercice should defined tests inside a tests pl markup environement.%s %s"%(str(dic), str(dic['dic'])) dico_tests = eval( dic['tests'] ) if (len(dico_tests) == 0): print("Your exercice do not define any test ! You shoul add at least one test.", file=sys.stderr) sys.exit(1) if len(dico_tests[0]) not in [3, 4]: print("Your tests do not appear to be valid with the available graders.", file=sys.stderr) sys.exit(1) if len(dico_tests[0]) == 3: assert('solution' in dic), "If your tests do not provide excepted outputs, please provide a teacher solution." dic = graderII(dico_tests, dic) else: dic = graderI(dico_tests, dic) output(dic['success']*100, dic['feedback'], dic)
('uncrosedfalse' in dic and dic['uncrosedfalse'])) grade = (100 * a) / t dic['evaluation'] = grade if "feedback" in dic: import jinja2 if dic["feedback"] == "show": dic['form'] = createshowanswer(dic['pairs'], studentdic) if a == t: if 'success' in dic["feedback"]: outstr = jinja2.Template( dic["feedback"]['success']).render(dic) else: outstr = '<div class="btn-success"> Bravo ! </div>' else: if 'failure' in dic["feedback"]: outstr = jinja2.Template( dic["feedback"]['failure']).render(dic) else: outstr = '<div class="btn-danger"> Raté ! ' + str( a) + "/" + str(t) + '</div>' if "try" not in dic: dic["try"] = 1 else: dic["try"] += 1 if "noretry" in dic: if dic["try"] > int(dic["noretry"]): dic["text"] = " Passez à l'exercice suivant " dic["form"] = "" output(grade, outstr, dic)