def giveAnswer(self): self.setHeaders([{'type': 'CONTENT-TYPE', 'value': 'application/json'}]) jsonBody = self.readPayload() isCorrect = ExerciseHandler.checkAnswer(jsonBody['questionId'], jsonBody['answer']) parameters = urlparse.parse_qs(urlparse.urlparse(self.path).query) UserHandler.setQuestionAnswer(parameters['user'][0], parameters['questionNumber'][0], jsonBody['answer'], isCorrect)
def giveAnswer(self): self.setHeaders([{ 'type': 'CONTENT-TYPE', 'value': 'application/json' }]) jsonBody = self.readPayload() isCorrect = ExerciseHandler.checkAnswer(jsonBody['questionId'], jsonBody['answer']) parameters = urlparse.parse_qs(urlparse.urlparse(self.path).query) UserHandler.setQuestionAnswer(parameters['user'][0], parameters['questionNumber'][0], jsonBody['answer'], isCorrect)
__author__ = "Benjamin" import ExerciseHandler ExerciseHandler.setCsvPath("./exercises.csv") ExerciseHandler.readCsv() for ex in ExerciseHandler.exercises: print str(ex.id) + " " + ex.exerciseText for corAnswer in ex.correctAnswers: print corAnswer for wrongAnswer in ex.wrongAnswers: print wrongAnswer
'isCorrect': answeredExercise['isCorrect'] }) question = { 'exercise': exercise.exerciseText, 'correctAnswers': exercise.correctAnswers, 'answeredCorrectlyCounter': answeredCorrectlyCounter, 'answeredCounter': answeredCounter, 'answers': answers } questions.append(question) self.wfile.write(json.dumps(questions)) if __name__ == '__main__': exercisesPath = "./exercises.csv" ExerciseHandler.setCsvPath(exercisesPath) ExerciseHandler.readCsv() print "Read exercises from " + exercisesPath httpServer = BaseHTTPServer.HTTPServer myServer = httpServer((HOST_NAME, PORT), MyHandler) print time.asctime(), "Server Starts - %s:%s" % (HOST_NAME, PORT) try: myServer.serve_forever() except KeyboardInterrupt: pass myServer.server_close() print time.asctime(), "Server Stops - %s:%s" % (HOST_NAME, PORT)
for answeredExercise in user.questionAnswerMap: if answeredExercise['id'] == exercise.id: answeredCounter += 1 if answeredExercise['isCorrect'] == True: answeredCorrectlyCounter += 1 answers.append({'user': user.userName, 'answer': answeredExercise['answer'], 'isCorrect': answeredExercise['isCorrect']}) question = {'exercise': exercise.exerciseText, 'correctAnswers': exercise.correctAnswers, 'answeredCorrectlyCounter': answeredCorrectlyCounter, 'answeredCounter': answeredCounter, 'answers': answers} questions.append(question) self.wfile.write(json.dumps(questions)) if __name__ == '__main__': exercisesPath = "./exercises.csv" ExerciseHandler.setCsvPath(exercisesPath) ExerciseHandler.readCsv() print "Read exercises from " + exercisesPath httpServer = BaseHTTPServer.HTTPServer myServer = httpServer((HOST_NAME, PORT), MyHandler) print time.asctime(), "Server Starts - %s:%s" % (HOST_NAME, PORT) try: myServer.serve_forever() except KeyboardInterrupt: pass myServer.server_close() print time.asctime(), "Server Stops - %s:%s" % (HOST_NAME, PORT)
__author__ = 'Benjamin' import ExerciseHandler ExerciseHandler.setCsvPath("./exercises.csv") ExerciseHandler.readCsv() for ex in ExerciseHandler.exercises: print str(ex.id) + " " + ex.exerciseText for corAnswer in ex.correctAnswers: print corAnswer for wrongAnswer in ex.wrongAnswers: print wrongAnswer