-
Notifications
You must be signed in to change notification settings - Fork 0
/
controller.py
75 lines (58 loc) · 2.02 KB
/
controller.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
from models import Source, Reading
from google.appengine.ext import db
from utils.id import mk_id
import logging
log = logging.getLogger(__name__)
class controller0( object ):
@classmethod
def register( cls, name, email, uid=None ):
"""
Register a new account.
"""
if uid==None:
_uid = mk_id()
else:
_uid = uid
log.warn( "New registration: Name=%s, email=%s, uid=%s" % ( name, email, uid ) )
newAccount = Source( uid=_uid,
name=name,
email=email )
newAccount.put()
return newAccount.uid
@classmethod
def submit( cls, uid, readingType, readingValue ):
assert isinstance( uid, str )
assert isinstance( readingType, str )
assert isinstance( readingValue, float )
source = cls.getSource( uid )
reading = Reading( readingSource=source,
value=readingValue,
readingType=readingType )
reading.put()
return reading.addtime
@classmethod
def getSource(cls, uid):
assert isinstance( uid, str )
s = Source.all()
s.filter( "uid =", uid )
results = [a for a in s.fetch( limit=1 ) ]
assert len(results) > 0, "Could not find source record."
return results[0]
@classmethod
def _getReadings(cls, uid, readingType ):
"""
Get all the readings of a particular type
"""
source = cls.getSource( uid )
r = Reading.all()
r.filter( "readingSource =", source )
r.filter( "readingType =", readingType )
r.order("-adddate")
return [ re for re in r ]
@classmethod
def getReadings(cls, uid, readingType ):
readings = cls._getReadings( uid, readingType )
results = []
for r in readings:
import pdb
pdb.set_trace()