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
a5ec0bbd
Commit
a5ec0bbd
authored
Dec 13, 2016
by
Dominik Rosiek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
✉
:)
parent
c6dcfd09
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
77 additions
and
35 deletions
+77
-35
db.py
db.py
+41
-22
measurement_viewer.py
measurement_viewer.py
+5
-3
models.py
models.py
+31
-10
No files found.
db.py
View file @
a5ec0bbd
...
...
@@ -203,7 +203,6 @@ class DDBTable(object):
message
=
yield
gen
.
Task
(
self
.
_dynamodb
(
operation
=
'Scan'
)
.
call
,
TableName
=
self
.
_get_table_name
())
data
=
[
self
.
decode_item
(
item
=
item
)
for
item
in
message
[
'Items'
]]
raise
gen
.
Return
(
data
)
...
...
@@ -339,24 +338,44 @@ class DDBmeasurements(DDBTable):
data
=
self
.
decode_item
(
item
=
message
[
'Item'
])
raise
gen
.
Return
(
data
)
if
__name__
==
'__main__'
:
types
=
DDBtypes
()
types
.
create_table
()
types
.
add
(
1
,
2
,
3
,
4
,
5
)
ioloop
=
IOLoop
.
instance
()
result
=
ioloop
.
run_sync
(
partial
(
types
.
get_all
))
print
(
result
)
measurements
=
DDBmeasurements
()
measurements
.
create_table
()
measurements
.
add
(
1
,
2
,
3
,
4
)
ioloop
=
IOLoop
.
instance
()
result
=
ioloop
.
run_sync
(
partial
(
measurements
.
get_all
))
print
(
result
)
stations
=
DDBstations
()
stations
.
create_table
()
stations
.
add
(
1
,
2
,
3
,
4
)
ioloop
=
IOLoop
.
instance
()
result
=
ioloop
.
run_sync
(
partial
(
stations
.
get_all
))
print
(
result
)
class
DDBlastmeasurements
(
DDBTable
):
TABLE_NAME
=
'lastmeasurements'
KEY_SCHEMA
=
[{
'AttributeName'
:
'station_id'
,
'KeyType'
:
'HASH'
,
},
{
'AttributeName'
:
'pollution_id'
,
'KeyType'
:
'HASH'
,
}]
PROVISIONED_THROUGHPUT
=
{
'ReadCapacityUnits'
:
1
,
'WriteCapacityUnits'
:
1
}
FIELDS
=
{
'station_id'
:
DDBUUIDField
,
'pollution_id'
:
DDBUUIDField
,
'measurement_id'
:
DDBUUIDField
,
}
@
gen
.
coroutine
def
add
(
self
,
measurement
):
data
=
{
'measurement_id'
:
measurement
.
id
,
}
message
=
yield
gen
.
Task
(
self
.
_dynamodb
(
operation
=
'UpdateItem'
)
.
call
,
TableName
=
self
.
_get_table_name
(),
Key
=
self
.
encode_item
(
data
=
{
'station_id'
:
measurement
.
station
.
id
,
'pollution_id'
:
measurement
.
type
.
id
}),
AttributeUpdates
=
self
.
encode_item
(
data
=
data
,
update
=
True
))
raise
gen
.
Return
(
message
)
@
gen
.
coroutine
def
get
(
self
,
station
,
pollution_type
):
message
=
yield
gen
.
Task
(
self
.
_dynamodb
(
operation
=
'GetItem'
)
.
call
,
TableName
=
self
.
_get_table_name
(),
Key
=
self
.
encode_item
(
data
=
{
'station_id'
:
station
.
id
,
'pollution_id'
:
pollution_type
.
id
})
)
data
=
self
.
decode_item
(
item
=
message
[
'Item'
])
raise
gen
.
Return
(
data
)
\ No newline at end of file
measurement_viewer.py
View file @
a5ec0bbd
...
...
@@ -19,10 +19,12 @@ class MainHandler(tornado.web.RequestHandler):
#stations = models.Station.get_all()
#stations = models.Station.getall()
stations
=
yield
models
.
Station
.
get_all
()
pollutions
=
yield
models
.
Type
.
get_all
()
measurement
=
yield
models
.
Measurement
.
get
(
"5c2be10b-5d33-47d7-95fe-b3f6fc29a3af"
)
for
s
in
stations
:
self
.
write
(
"{0} {1} {2} {3} {4}<br />"
.
format
(
s
.
id
,
s
.
city
,
s
.
longitude
,
s
.
latitude
,
s
.
name
))
for
station
in
stations
.
values
():
for
pollution
in
pollutions
.
values
():
measurement
=
yield
models
.
Measurement
.
get_last
(
station
,
pollution
)
self
.
write
(
str
(
measurement
))
# measurement = models.Measurement.getlast(station=s.id)
# self.write("".format())
...
...
models.py
View file @
a5ec0bbd
import
uuid
from
db
import
DDBtypes
,
DDBmeasurements
,
DDBstations
from
db
import
DDBtypes
,
DDBmeasurements
,
DDBstations
,
DDBlastmeasurements
from
functools
import
partial
from
tornado.gen
import
coroutine
...
...
@@ -41,12 +41,14 @@ class Station(DDBobject):
@
classmethod
@
coroutine
def
get_all
(
cls
):
if
not
cls
.
stored
:
data
=
yield
DDBstations
()
.
get_all
()
return_value
=
[]
for
station
in
data
:
return_value
.
append
(
cls
.
from_dict
(
station
))
cls
.
stored
=
{
i
.
id
:
i
for
i
in
return_value
}
return
return_value
return
cls
.
stored
class
Type
(
DDBobject
):
...
...
@@ -69,10 +71,23 @@ class Type(DDBobject):
result
=
yield
DDBtypes
()
.
get
(
type_id
)
return
cls
.
from_dict
(
result
)
@
coroutine
def
save
(
self
):
result
=
yield
(
DDBtypes
()
.
add
(
pollution_type
=
self
)
)
result
=
yield
DDBtypes
()
.
add
(
pollution_type
=
self
)
return
result
@
classmethod
@
coroutine
def
get_all
(
cls
):
if
not
cls
.
stored
:
data
=
yield
DDBtypes
()
.
get_all
()
return_value
=
[]
for
pollution_type
in
data
:
return_value
.
append
(
cls
.
from_dict
(
pollution_type
))
cls
.
stored
=
{
i
.
id
:
i
for
i
in
return_value
}
return
cls
.
stored
class
Measurement
(
DDBobject
):
stored
=
{}
...
...
@@ -105,9 +120,15 @@ class Measurement(DDBobject):
@
coroutine
def
save
(
self
):
result
=
yield
DDBmeasurements
()
.
add
(
measurement
=
self
)
result
=
yield
DDBlastmeasurements
()
.
add
(
measurement
=
self
)
return
result
@
classmethod
@
coroutine
def
get_last
(
self
,
station_id
):
# TODO
pass
def
get_last
(
cls
,
station
,
pollution_type
):
data
=
yield
DDBlastmeasurements
()
.
get
(
station
,
pollution_type
)
return_value
=
yield
cls
.
get
(
measurement_id
=
data
[
'measurement_id'
])
return
return_value
def
__str__
(
self
):
return
"{0} {1} {2} {3} {4}"
.
format
(
self
.
id
,
self
.
station
.
id
,
self
.
type
.
id
,
self
.
value
,
self
.
time
)
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