Commit f5b90da8 authored by Dominik Rosiek's avatar Dominik Rosiek

soft cache ftw

parent 1dbe5473
...@@ -2,12 +2,8 @@ import logging ...@@ -2,12 +2,8 @@ import logging
import re import re
import six import six
import uuid
from functools import partial
from tornado import gen from tornado import gen
from tornado.ioloop import IOLoop
from tornado_botocore import Botocore from tornado_botocore import Botocore
...@@ -213,8 +209,8 @@ class DDBstations(DDBTable): ...@@ -213,8 +209,8 @@ class DDBstations(DDBTable):
'KeyType': 'HASH', 'KeyType': 'HASH',
}] }]
PROVISIONED_THROUGHPUT = { PROVISIONED_THROUGHPUT = {
'ReadCapacityUnits': 1, 'ReadCapacityUnits': 20,
'WriteCapacityUnits': 1 'WriteCapacityUnits': 5
} }
FIELDS = { FIELDS = {
'station_id': DDBUUIDField, 'station_id': DDBUUIDField,
...@@ -258,8 +254,8 @@ class DDBtypes(DDBTable): ...@@ -258,8 +254,8 @@ class DDBtypes(DDBTable):
'KeyType': 'HASH', 'KeyType': 'HASH',
}] }]
PROVISIONED_THROUGHPUT = { PROVISIONED_THROUGHPUT = {
'ReadCapacityUnits': 1, 'ReadCapacityUnits': 20,
'WriteCapacityUnits': 1 'WriteCapacityUnits': 5
} }
FIELDS = { FIELDS = {
'type_id': DDBUUIDField, 'type_id': DDBUUIDField,
...@@ -303,8 +299,8 @@ class DDBmeasurements(DDBTable): ...@@ -303,8 +299,8 @@ class DDBmeasurements(DDBTable):
'KeyType': 'HASH', 'KeyType': 'HASH',
}] }]
PROVISIONED_THROUGHPUT = { PROVISIONED_THROUGHPUT = {
'ReadCapacityUnits': 1, 'ReadCapacityUnits': 50,
'WriteCapacityUnits': 1 'WriteCapacityUnits': 5
} }
FIELDS = { FIELDS = {
'measurement_id': DDBUUIDField, 'measurement_id': DDBUUIDField,
...@@ -350,8 +346,8 @@ class DDBlastmeasurements(DDBTable): ...@@ -350,8 +346,8 @@ class DDBlastmeasurements(DDBTable):
'KeyType': 'HASH', 'KeyType': 'HASH',
}] }]
PROVISIONED_THROUGHPUT = { PROVISIONED_THROUGHPUT = {
'ReadCapacityUnits': 1, 'ReadCapacityUnits': 50,
'WriteCapacityUnits': 1 'WriteCapacityUnits': 5
} }
FIELDS = { FIELDS = {
'station_id': DDBUUIDField, 'station_id': DDBUUIDField,
......
...@@ -11,15 +11,11 @@ class MainHandler(tornado.web.RequestHandler): ...@@ -11,15 +11,11 @@ class MainHandler(tornado.web.RequestHandler):
def get(self): def get(self):
stations = yield models.Station.get_all() stations = yield models.Station.get_all()
pollutions = yield models.Type.get_all() pollutions = yield models.Type.get_all()
last_measurements = yield models.Measurement.get_all_last()
for station in stations.values(): for measurement in last_measurements:
for pollution in pollutions.values():
try:
self.write("\n")
measurement = yield models.Measurement.get_last(station, pollution)
self.write(str(measurement)) self.write(str(measurement))
except: self.write("\n")
pass
def make_app(): def make_app():
......
...@@ -91,6 +91,7 @@ class Type(DDBobject): ...@@ -91,6 +91,7 @@ class Type(DDBobject):
class Measurement(DDBobject): class Measurement(DDBobject):
stored = {} stored = {}
last_measurements = {}
def __init__(self, station, pollution_type, value, time, measurement_id=None): def __init__(self, station, pollution_type, value, time, measurement_id=None):
self.id = measurement_id or str(uuid.uuid4()) self.id = measurement_id or str(uuid.uuid4())
...@@ -115,7 +116,9 @@ class Measurement(DDBobject): ...@@ -115,7 +116,9 @@ class Measurement(DDBobject):
data['pollution_type'] = pollution_type data['pollution_type'] = pollution_type
del data['type_id'] del data['type_id']
return cls.from_dict(data) return_value = cls.from_dict(data)
cls.stored[return_value.id] = return_value
return return_value
@coroutine @coroutine
def save(self): def save(self):
...@@ -130,5 +133,18 @@ class Measurement(DDBobject): ...@@ -130,5 +133,18 @@ class Measurement(DDBobject):
return_value = yield cls.get(measurement_id=data['measurement_id']) return_value = yield cls.get(measurement_id=data['measurement_id'])
return return_value return return_value
@classmethod
@coroutine
def get_all_last(cls):
data = yield DDBlastmeasurements().get_all()
return_value = []
cls.last_measurements = None
for measurement in data:
get = yield cls.get(measurement['measurement_id'])
return_value.append(get)
cls.last_measurements = return_value
return cls.last_measurements
def __str__(self): def __str__(self):
return "{0} {1} {2} {3} {4}".format(self.id, self.station.id, self.type.id, self.value, self.time) return "{0} {1} {2} {3} {4}".format(self.id, self.station.id, self.type.id, self.value, self.time)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment