Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
smogonet
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Dominik Rosiek
smogonet
Commits
8cdd7519
Commit
8cdd7519
authored
Dec 13, 2016
by
Dominik Rosiek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix models for tornado
parent
30ee034e
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
16 deletions
+36
-16
measurement_viewer.py
measurement_viewer.py
+13
-8
models.py
models.py
+22
-8
test_models.py
test_models.py
+1
-0
No files found.
measurement_viewer.py
View file @
8cdd7519
...
...
@@ -7,20 +7,25 @@ import decimal
#import boto.dynamodb2
#from boto.dynamodb2.table import Table
#from time import sleep
from
tornado
import
gen
class
MainHandler
(
tornado
.
web
.
RequestHandler
):
@
gen
.
coroutine
def
get
(
self
):
#stations = self.get_stations()
#stations = models.Station.get_all()
#stations = models.Station.getall()
stations
=
models
.
Station
.
get
(
"b1d12bb6-a3b7-43b8-b6ab-6d6e62cb794e"
,
tornado
.
ioloop
.
IOLoop
.
current
())
for
s
in
stations
:
self
.
write
(
"{0} {1} {2} {3} {4}<br />"
.
format
(
s
[
'station_id'
],
s
[
'city'
],
s
[
'longitude'
],
s
[
'latitude'
],
s
[
'name'
]))
stations
=
yield
models
.
Station
.
get
(
"b1d12bb6-a3b7-43b8-b6ab-6d6e62cb794e"
)
s
=
stations
.
result
()
measurement
=
yield
models
.
Measurement
.
get
(
"5c2be10b-5d33-47d7-95fe-b3f6fc29a3af"
)
m
=
measurement
.
result
()
self
.
write
(
"{0} {1} {2} {3} {4}<br />"
.
format
(
s
.
id
,
s
.
city
,
s
.
longitude
,
s
.
latitude
,
s
.
name
))
for
s
in
stations
:
measurement
=
models
.
Measurement
.
getlast
(
station
=
s
.
id
)
self
.
write
(
""
.
format
())
# measurement = models.Measurement.getlast(station=s.id)
# self.write("".format())
#measurements = self.get_measurements()
...
...
@@ -60,5 +65,5 @@ def make_app():
if
__name__
==
"__main__"
:
app
=
make_app
()
app
.
listen
(
80
)
app
.
listen
(
80
90
)
tornado
.
ioloop
.
IOLoop
.
current
()
.
start
()
models.py
View file @
8cdd7519
...
...
@@ -2,12 +2,14 @@ import uuid
from
db
import
DDBtypes
,
DDBmeasurements
,
DDBstations
from
functools
import
partial
from
tornado.gen
import
coroutine
from
tornado.ioloop
import
IOLoop
class
DDBobject
(
object
):
@
classmethod
@
coroutine
def
from_dict
(
cls
,
data
):
return
cls
(
**
data
)
...
...
@@ -24,14 +26,18 @@ class Station(DDBobject):
self
.
name
=
name
@
classmethod
@
coroutine
def
get
(
cls
,
station_id
):
if
cls
.
stored
.
get
(
station_id
,
None
):
return
cls
.
stored
.
get
(
station_id
)
return
cls
.
from_dict
(
IOLoop
.
instance
()
.
run_sync
(
partial
(
DDBstations
()
.
get
,
station_id
)))
result
=
yield
DDBstations
()
.
get
(
station_id
)
return
cls
.
from_dict
(
result
)
@
coroutine
def
save
(
self
):
return
IOLoop
.
instance
()
.
run_sync
(
partial
(
DDBstations
()
.
add
,
station
=
self
))
result
=
yield
DDBstations
()
.
add
(
station
=
self
)
return
result
class
Type
(
DDBobject
):
...
...
@@ -46,14 +52,17 @@ class Type(DDBobject):
self
.
description
=
description
@
classmethod
@
coroutine
def
get
(
cls
,
type_id
):
if
cls
.
stored
.
get
(
type_id
,
None
):
return
cls
.
stored
.
get
(
type_id
)
return
cls
.
from_dict
(
IOLoop
.
instance
()
.
run_sync
(
partial
(
DDBtypes
()
.
get
,
type_id
)))
result
=
yield
DDBtypes
()
.
get
(
type_id
)
return
cls
.
from_dict
(
result
)
def
save
(
self
):
return
IOLoop
.
instance
()
.
run_sync
(
partial
(
DDBtypes
()
.
add
,
pollution_type
=
self
))
result
=
yield
(
DDBtypes
()
.
add
(
pollution_type
=
self
))
return
result
class
Measurement
(
DDBobject
):
...
...
@@ -67,19 +76,24 @@ class Measurement(DDBobject):
self
.
time
=
time
@
classmethod
@
coroutine
def
get
(
cls
,
measurement_id
):
if
cls
.
stored
.
get
(
measurement_id
,
None
):
return
cls
.
stored
.
get
(
measurement_id
)
data
=
IOLoop
.
instance
()
.
run_sync
(
partial
(
DDBmeasurements
()
.
get
,
measurement_id
)
)
data
=
yield
DDBmeasurements
()
.
get
(
measurement_id
)
data
[
'station'
]
=
Station
.
get
(
data
[
'station_id'
])
station
=
yield
Station
.
get
(
data
[
'station_id'
])
data
[
'station'
]
=
station
.
result
()
del
data
[
'station_id'
]
data
[
'pollution_type'
]
=
Type
.
get
(
data
[
'type_id'
])
pollution_type
=
yield
Type
.
get
(
data
[
'type_id'
])
data
[
'pollution_type'
]
=
pollution_type
.
result
()
del
data
[
'type_id'
]
return
cls
.
from_dict
(
data
)
@
coroutine
def
save
(
self
):
return
IOLoop
.
instance
()
.
run_sync
(
partial
(
DDBmeasurements
()
.
add
,
measurement
=
self
))
result
=
yield
DDBmeasurements
()
.
add
(
measurement
=
self
)
return
result
test_models.py
View file @
8cdd7519
import
models
station
=
models
.
Station
(
1
,
"Kraków"
,
12
,
13
,
"Aleje"
)
station
.
save
()
station2
=
models
.
Station
.
get
(
station
.
id
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment