-
Notifications
You must be signed in to change notification settings - Fork 0
/
entry_web.py
99 lines (75 loc) · 3.93 KB
/
entry_web.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
from dataBase import *
import datetime
def updateDB_web(cid, category, amount):
record = userDB(cid = cid,amount = amount, category = category)
record.put()
def makeDailyPie(cid):
sum = {}
records = db.GqlQuery('SELECT * FROM userDB WHERE cid = \'' + cid + '\' AND date = DATE(\'' + str(datetime.datetime.now().date()) + '\')')
for x in records:
if str(x.category) not in sum.keys(): sum[str(x.category)]=0
sum[str(x.category)] = sum[str(x.category)] + int(x.amount)
list = ['food' ,'transport','shopping','entertainment','healthcare','education','others']
for x in list:
if x not in sum.keys():
sum[x] = 0
return sum
def makeWeekPie(cid):
sum = {}
firstday = (datetime.datetime.now() - datetime.timedelta(days = 7)).date()
records = db.GqlQuery('SELECT * FROM userDB WHERE cid = \'' + cid + '\' AND date >= DATE(\'' + str(firstday) + '\')' )
for x in records:
if str(x.category) not in sum.keys(): sum[str(x.category)]=0
sum[str(x.category)] = sum[str(x.category)] + int(x.amount)
list = ['food' ,'transport','shopping','entertainment','healthcare','education','others']
for x in list:
if x not in sum.keys():
sum[x] = 0
return sum
def makeMonthPie(cid):
sum = {}
firstday = datetime.date(int(datetime.datetime.now().year),int(datetime.datetime.now().month),1)
records = db.GqlQuery('SELECT * FROM userDB WHERE cid = \'' + cid + '\' AND date >= DATE(\'' + str(firstday) + '\')' )
for x in records:
if str(x.category) not in sum.keys(): sum[str(x.category)]=0
sum[str(x.category)] = sum[str(x.category)] + int(x.amount)
list = ['food' ,'transport','shopping','entertainment','healthcare','education','others']
for x in list:
if x not in sum.keys():
sum[x] = 0
return sum
def makeYearPie(cid):
sum = {}
firstdate = datetime.date(int(datetime.datetime.now().year),1,1)
records = db.GqlQuery('SELECT * FROM userDB WHERE cid = \'' + cid + '\' AND date >= DATE(\'' + str(firstdate) + '\')' )
for x in records:
if str(x.category) not in sum.keys(): sum[str(x.category)]=0
sum[str(x.category)] = sum[str(x.category)] + int(x.amount)
list = ['food' ,'transport','shopping','entertainment','healthcare','education','others']
for x in list:
if x not in sum.keys():
sum[x] = 0
return sum
def makeDailyTable(cid):
return db.GqlQuery('SELECT * FROM userDB WHERE cid = \'' + cid + '\' AND date = DATE(\'' + str(datetime.datetime.now().date()) + '\')')
def makeWeekTable(cid):
firstday = (datetime.datetime.now() - datetime.timedelta(days = 7)).date()
return db.GqlQuery('SELECT * FROM userDB WHERE cid = \'' + cid + '\' AND date >= DATE(\'' + str(firstday) + '\')' )
def makeMonthTable(cid):
firstday = datetime.date(int(datetime.datetime.now().year),int(datetime.datetime.now().month),1)
return db.GqlQuery('SELECT * FROM userDB WHERE cid = \'' + cid + '\' AND date >= DATE(\'' + str(firstday) + '\')' )
def makeYearTable(cid):
firstdate = datetime.date(int(datetime.datetime.now().year),1,1)
return db.GqlQuery('SELECT * FROM userDB WHERE cid = \'' + cid + '\' AND date >= DATE(\'' + str(firstdate) + '\')' )
def getRecords(value,cid):
sum ={}
prevDate = (datetime.datetime.now() - datetime.timedelta(days = int(value))).date()
records = db.GqlQuery('SELECT * FROM userDB WHERE cid = \'' + cid + '\' AND date >= DATE(\'' + str(prevDate) + '\')' )
for x in records:
if str(x.category) not in sum.keys(): sum[str(x.category)]=0
sum[str(x.category)] = sum[str(x.category)] + int(x.amount)
list = ['food' ,'transport','shopping','entertainment','healthcare','education','others']
for x in list:
if x not in sum.keys():
sum[x] = 0
return {'sum':sum,'records':records}