コード例 #1
0
 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)
コード例 #2
0
 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)
コード例 #3
0
ファイル: CsvTest.py プロジェクト: raethlein/SimpleSurvey
__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
コード例 #4
0
                            '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)
コード例 #5
0
                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)
コード例 #6
0
ファイル: CsvTest.py プロジェクト: raethlein/SimpleSurvey
__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