예제 #1
0
	def post(self, q_id):
		#TODO check if the question has already been answered by the user, if so, do not post the new answer
		#get the current user, this is important if we are to take an answer for this question
		
		user=users.get_current_user()
		if not user:
			self.redirect(users.create_login_url(self.request.uri))
		#ensure that credential to answer exists
		createDefaultCredential(user)
		#initialize a new AnsweredQuestion
		#aq=AnsweredQuestion()
		#get the id of the Answer which has been selected
		a_id=self.request.get('answer')
		question=None
		answer=None
		try:
			question=dbhelper.fetchQuestion(int(q_id))
			answer=dbhelper.getAnswer(int(a_id))
		except dbhelper.InvalidIdError:
			self.response.out.write("F")
			return
		if answer is not None:
			#then a valid answer has been given for some question
			#aq.user=user.user_id() #put the user name
			#aq.answer=query.get().key #the key id of the answer that has been given by him
			#try:
			#	aq.put() #write it to DB
			#	self.response.out.write("S") #write a flag indicating success
			#except TransactionFailedError: #some bug here
			#	self.response.out.write("F")
			result=insertQuestionAnswered(user,question.key,answer.key)
			self.response.out.write(result)
		else:
			#invalid answer given
			self.response.out.write("F")
예제 #2
0
	def get(self, q_id):
		user=users.get_current_user()
		if not user:
			self.redirect(users.create_login_url(self.request.uri))
		#now the above map gives the p(theta) for the given question
		#need to format data and send it to page
		###############################################
		question=None
		try:
			question=dbhelper.fetchQuestion(int(q_id))
		except InvalidIdError:
			self.response.out.write("No such page") #TODO replace with proper 404 code
			return
		(answers,correctAnswereeThetas,totalAnswereeThetas)=DistributionAnalyzer().analyzeQuestion(question)
		vals={'question':question,'answers':answers,'correctDist':correctAnswereeThetas,'current_user':user}
		template=jinjaEnv.get_template("perform.html")
		self.response.out.write(template.render(vals))
예제 #3
0
 def get(self, q_id):
     global answers, correct_distribution, total_distribution
     q_key = int(q_id)
     c = 0.25  # will have to be made flexible
     calc_a = calc_b = calc_c = 0.0
     try:
         question = dbhelper.fetchQuestion(q_key)
         (answers, correct_distribution, total_distribution) = DistributionAnalyzer().analyzeQuestion(question)
         (calc_a, calc_b, calc_c) = calculateParameters()
         question.a = calc_a
         question.b = calc_b
         question.c = calc_c
     except InvalidIdError:
         self.response.out.write("F")  # a 404 page should not be given here
         return
     if question is not None:
         question.put()
     self.response.out.write("%f,%f,%f" % (calc_a, calc_b, calc_c))
예제 #4
0
 def post(self):
         q_id=self.request.get('qid')
         q_key=int(q_id)
         computation.question=None
         try:
                 computation.question=dbhelper.fetchQuestion(q_key)
         except InvalidIdError:
                 logging.info("Invalid question %s"%q_id)
                 return
         (computation.answers,computation.correct_distribution,computation.total_distribution)=DistributionAnalyzer().analyzeQuestion(computation.question)
         def worker():
                 logging.info("Started parameter calculator task for %s"%q_id)
                 calc_a=calc_b=calc_c=0.0
                 (calc_a,calc_b,calc_c)=computation.calculateParameters()
                 computation.question.a=calc_a
                 computation.question.b=calc_b
                 computation.question.c=calc_c
                 computation.question.put()
         ndb.transaction(worker)
예제 #5
0
	def get(self,q_id):
		#get the current user
		user=users.get_current_user()
		if not user:	#if user object is None i.e. No user can be determined
			#redirect to the user authentication page
			self.redirect(users.create_login_url(self.request.uri))
		question=None
		answers=[]
		try:
			question=dbhelper.fetchQuestion(int(q_id))
			answers=dbhelper.fetchAnswersOf(question)
		except dbhelper.InvalidIdError:
			question=Question(question="Could not find this question") #should ideally redirect to 404 page
		#Values to pass to the View component
		vals={'question':question,'answers':answers,'current_user':user}
		#render to the template
		template=jinjaEnv.get_template('answerQuestion.html')
		#write it to the handler's output stream
		self.response.out.write(template.render(vals))