def post(self,u_id):
		theta=5.0
		ec=None
		key=int(u_id)
		query=EstimationCredentials.query(EstimationCredentials.key==ndb.Key('EstimationCredentials',key))
		if query.count() == 1:
			ec=query.get()
			theta=ec.estimatedTheta
			if self.request.get("i") == "true":
				#check if incrementable
				if theta+1.0<=10:
					theta=theta+1.0
				else:
					self.response.out.write("F")
					return
			else:
				#check if decrementable
				if theta-1.0>=0:
					theta=theta-1.0
				else:
					self.response.out.write("F")
					return
		else:
			self.response.out.write("F")
			return
		self.setTheta(ec,float(theta))
		self.response.out.write("S")
示例#2
0
	def analyzeQuestion(self,question):
		answers=[]
		try:
			answers=dbhelper.fetchAnswersOf(question)
		except dbhelper.InvalidIdError:
			raise
		#TODO must check answers size
		
		
		correctAnswereeThetas={}
		totalAnswereeThetas={}
		#initialize all possible estimation thetas
		for j in range(0,10,1):
			correctAnswereeThetas[float(j)]=0.0
			totalAnswereeThetas[float(j)]=0.0
		
		for answer in answers:
			#find number of people who gave this answer, make it distinct for user, meaning only one answer by a given user will be tabulated
			query=AnsweredQuestion.query(AnsweredQuestion.answer==ndb.Key('Answer',answer.key.id()),projection=[AnsweredQuestion.user],distinct=True)
			givenAnswers=query.fetch() #who are the people who answered this question?
			for givenAnswer in givenAnswers:
				who=EstimationCredentials.query(EstimationCredentials.user==givenAnswer.user)
				#TODO check if there is only one credential(not implemented just now)
				#find theta of this person
				theta=who.get().estimatedTheta
				totalAnswereeThetas[theta]=totalAnswereeThetas[theta]+1.0
				if answer.correct:
				#increment the specific estimatedTheta counter by 1
					correctAnswereeThetas[theta]=correctAnswereeThetas[theta]+1.0
				
		#normalize correctAnswerrThetas
		for j in range(0,10,1):
			if totalAnswereeThetas[float(j)]!=0: #ensures we don't divide by zero
				correctAnswereeThetas[float(j)]=correctAnswereeThetas[float(j)]/totalAnswereeThetas[float(j)]
		return (answers, correctAnswereeThetas, totalAnswereeThetas)
	def get(self):
		vals={}
		user=users.get_current_user()
		if not user:
			self.redirect(users.create_login_url(self.request.uri))
		else:
			query=EstimationCredentials.query()
			vals['credentials']=query.fetch()
			template=jinjaEnv.get_template('credential.html')
			self.response.out.write(template.render(vals))
示例#4
0
def createDefaultCredential(user, theta=5.0):
	es=None
	query=EstimationCredentials.query(EstimationCredentials.user==user)
	if query.count()==1:
		#already exists, return
		return
	else:
		es=EstimationCredentials()
		es.user=user
	es.estimatedTheta=theta
	es.put()