Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 85ae9a926d
Fetching contributors…

Cannot retrieve contributors at this time

file 71 lines (61 sloc) 1.89 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
#User operations and database

import random
import string
import datetime
from google.appengine.api import users
from google.appengine.ext import db
from google.appengine.api import users

def generateSet():
a = []
for i in range(45):
a.append(i+1)
random.shuffle(a)
return a

class userPlay(db.Model):
user = db.UserProperty(required=True)
questionSet = db.ListProperty(int)
tathvaID = db.StringProperty(required=True)
startTime = db.DateTimeProperty(required=True)
endTime = db.DateTimeProperty

def userPlayExist():
query = userPlay.all()
u = query.filter('user = ', users.get_current_user()).get()
if not u:
return False
else:
return True

def userPlayStart(tid):
if not userPlayExist():
u = userPlay(user = users.get_current_user(),
questionSet = generateSet(),
tathvaID = tid,
startTime = datetime.datetime.now())
u.put()
return u.user.nickname() + u.tathvaID

def userPlayStop():
query = userPlay.all()
u = query.filter('user = ', users.get_current_user()).get()
if not u.endTime:
u.endTime = datetime.datetime.now()
u.put()
return u.user.nickname() + u.tathvaID + str(u.endTime)

def userElapsedTime():
query = userPlay.all()
u = query.filter('user = ', users.get_current_user()).get()
return ((datetime.datetime.now() - u.startTime).microseconds/1000)

def userPermutation(num):
query = userPlay.all()
u = query.filter('user = ', users.get_current_user()).get()
return u.questionSet[num-1]

class userAnswer(db.Model):
user = user = db.UserProperty(required=True)
question = db.IntegerProperty(required=True)
answer = db.StringProperty(required=True)
elapsedTime = db.IntegerProperty(required=True)

def userAnswerSubmit(ques,ans):
a = userAnswer(user = users.get_current_user(),
question = ques,
answer = ans,
elapsedTime = userElapsedTime())
a.put()
return str(ques) + ans + str(userElapsedTime())
Something went wrong with that request. Please try again.