-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdatabase.py~
108 lines (98 loc) · 3.19 KB
/
database.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
from pymongo import Connection
import math
import unicodedata
Connection = Connection('localhost',27017)
db=Connection.admin
res=db.authenticate('admin','pwd')
Accounts = db.Accounts
AccountsSchedules = db.AccountSchedules
GlobalSchedules = db.GlobalSchedules
databases = [Accounts,AccountsSchedules,GlobalSchedules]
def verifyUser(username,password):
if(Accounts.find({'username':username,'password':password}).count() != 0):
return True
return False
def addUser(username,password):
if(verifyUser(username,password)):
return False
Accounts.insert({'username':username,'password':password,'times':[]})
return True
def addUserTime(username, day, timeStart, timeEnd):
if(AccountsSchedules.find({'username':username,'day':day}).count() == 0):
a=[]
for i in range(24):
a.append(0)
AccountsSchedules.insert({'username':username,'day':day,'times':a})
currentUser = AccountsSchedules.find_one({'username':username,'day':day})['times']
while(timeStart < timeEnd):
currentUser[timeStart] = 1
timeStart = timeStart + 1
AccountsSchedules.update({'username':username,'day':day},{"$set":{'times':currentUser}})
def getAllUser(username):
a =[]
days =[]
times=[]
for x in AccountsSchedules.find({'username':username}):
days.append(x['day'])
times.append(x['times'])
a.append(days)
a.append(times)
return a
def getAllSchedules():
a = []
days = []
times = []
for x in AccountsSchedules.find({'username':username}):
days.append(x['day'])
times.append(x['times'])
a.append(days)
a.append(times)
return a
def addGlobalTime(day, timeStart, timeEnd):
if(GlobalSchedules.find({'day':day}).count() == 0):
a=[]
for i in range(24):
a.append(0)
GlobalSchedules.insert({'day':day,'times':a})
currentDay = GlobalSchedules.find_one({'day':day})['times']
while(timeStart < timeEnd):
currentDay[timeStart] = currentDay[timeStart] + 1
timeStart = timeStart + 1
GlobalSchedules.update({'day':day}, {"$set": {'times':currentDay}})
def getGlobalDataForTime(day, timeStart):
if(GlobalSchedules.find({"day":day}).count() == 0):
return 0
currentDay = GlobalSchedules.find_one({'day':day})['times']
return currentDay[timeStart]
def getUserDataForTime(username, day, startTime):
if(AccountsSchedules.find({'username':username,'day':day}).count() == 0):
return 0
current = AccountsSchedules.find_one({'username':username,'day':day})['times']
return current[startTime]
def clearDatabases():
for x in databases:
x.drop()
def timesToString(array):
string = ""
start = 0
end = 0
index = 0
toCount = False
for x in array:
if x == 1 and toCount == False:
toCount = True
start = index
end = index
elif x == 1:
end = index
elif toCount:
string = string + str(start) + "-" + str(end) + ", "
toCount = False
index = index + 1
return string
def arrToString(array):
x = []
for i in array:
x.append(timesToString(i))
return x
#clearDatabases()