-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
89 lines (63 loc) · 2.42 KB
/
models.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
# coding: utf-8
from google.appengine.ext import db
from datetime import date, datetime
# HOrario de verão
timezone = 2
#Horario Normal
#timezone = 3
def por_count(item):
return item.get('count','')
class RegistraCafe(db.Model):
user = db.UserProperty()
date_creation = db.DateTimeProperty()
@classmethod
def getAll(self, limit=0):
filter = db.GqlQuery("SELECT * FROM RegistraCafe ORDER BY date_creation DESC")
return filter #RegistraCafe.all() #.fetch(100)
@classmethod
def getJaFez(self):
now = datetime.now()
if now.hour-timezone < 12:
start_date = datetime(now.year,now.month,now.day,0,0,0)
end_date = datetime(now.year,now.month,now.day,12,0,0)
else:
start_date = datetime(now.year,now.month,now.day,12,0,0)
end_date = datetime(now.year,now.month,now.day,23,59,0)
#result = RegistraCafe.all().filter("date_creation >=", start_date).filter("date_creation <=", end_date)
result = db.GqlQuery("SELECT * FROM RegistraCafe WHERE date_creation >= :1 AND date_creation <= :2 ", start_date,end_date)
return result.count()
@classmethod
def getQuantidadeCafe(self):
dados = self.getAll()
L = []
for item in dados:
D = {}
#result = RegistraCafe.all().filter('user =',item.user)
result = db.GqlQuery("SELECT * FROM RegistraCafe WHERE user = :1 ",item.user)
email = item.user.email()
D['user_email'] = email
if email == '[email protected]':
D['count'] = 70 + result.count()
elif email == '[email protected]':
D['count'] = 63 + result.count()
elif email == '[email protected]':
D['count'] = 59 + result.count()
elif email == '[email protected]':
D['count'] = 51 + result.count()
elif email == '[email protected]':
D['count'] = 45 + result.count()
elif email == '[email protected]':
D['count'] = 13 + result.count()
elif email == '[email protected]':
D['count'] = 45 + result.count()
else:
D['count'] = result.count()
if not D in L:
L.append(D)
return sorted(L, key=por_count,reverse=True)
@property
def dateTimeText(self):
return self.date_creation.strftime("%d.%m.%Y - %H:%M")
@property
def userName(self):
return self.user.email()