forked from k4rtik/beastie
-
Notifications
You must be signed in to change notification settings - Fork 7
/
userdb.py
94 lines (80 loc) · 2.42 KB
/
userdb.py
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#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
from questiondb import questionm
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
closeTime=db.DateTimeProperty(required=True)
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(),
closeTime = datetime.datetime.now()+datetime.timedelta(minutes=30)
)
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 userRemainingTime():
query = userPlay.all()
u = query.filter('user = ', users.get_current_user()).get()
urtime = (u.closeTime-datetime.datetime.now()).seconds
if u.closeTime > datetime.datetime.now():
return urtime
else:
return 0
def boolRemainingTime():
query = userPlay.all()
u = query.filter('user = ', users.get_current_user()).get()
if u.closeTime > datetime.datetime.now():
return True
else:
return False
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())