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
274b5ab8
Commit
274b5ab8
authored
Dec 04, 2016
by
Dominik Rosiek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
successful adds to database
parent
90106a46
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
14 deletions
+20
-14
db.py
db.py
+20
-14
No files found.
db.py
View file @
274b5ab8
import
logging
import
logging
import
time
import
re
import
re
import
six
import
six
import
uuid
import
uuid
...
@@ -81,8 +84,8 @@ class DDBUUIDField(DDBField):
...
@@ -81,8 +84,8 @@ class DDBUUIDField(DDBField):
class
DDBTable
(
object
):
class
DDBTable
(
object
):
TABLE_NAME
=
''
TABLE_NAME
=
'
measurements
'
REGION_NAME
=
'
us-west-2
'
REGION_NAME
=
'
eu-central-1
'
KEY_SCHEMA
=
[]
KEY_SCHEMA
=
[]
LOCAL_SECONDARY_INDEXES
=
[]
LOCAL_SECONDARY_INDEXES
=
[]
GLOBAL_SECONDARY_INDEXES
=
[]
GLOBAL_SECONDARY_INDEXES
=
[]
...
@@ -190,32 +193,35 @@ class DDBTable(object):
...
@@ -190,32 +193,35 @@ class DDBTable(object):
class
DDBmeasurements
(
DDBTable
):
class
DDBmeasurements
(
DDBTable
):
TABLE_NAME
=
'measurements'
TABLE_NAME
=
'measurements'
KEY_SCHEMA
=
[{
KEY_SCHEMA
=
[{
'AttributeName'
:
'measurement_id'
,
'AttributeName'
:
'sid'
,
'KeyType'
:
'HASH'
,
'KeyType'
:
'Number'
,
},{
'AttributeName'
:
'tid'
,
'KeyType'
:
'Number'
,
}]
}]
PROVISIONED_THROUGHPUT
=
{
PROVISIONED_THROUGHPUT
=
{
'ReadCapacityUnits'
:
1
,
'ReadCapacityUnits'
:
1
,
'WriteCapacityUnits'
:
1
'WriteCapacityUnits'
:
1
}
}
FIELDS
=
{
FIELDS
=
{
'
measurement_id'
:
DDBUUID
Field
,
'
sid'
:
DDBInt
Field
,
't
ype_
id'
:
DDBIntField
,
'tid'
:
DDBIntField
,
'
station_id'
:
DDBIntField
,
'
time'
:
DDBIntField
}
}
@
gen
.
coroutine
@
gen
.
coroutine
def
update
(
self
,
measurement_id
,
type_id
,
station_id
):
def
update
(
self
,
measurement_id
,
type_id
,
station_id
):
message
=
yield
gen
.
Task
(
self
.
_dynamodb
(
operation
=
'UpdateItem'
)
.
call
,
message
=
yield
gen
.
Task
(
self
.
_dynamodb
(
operation
=
'UpdateItem'
)
.
call
,
TableName
=
self
.
_get_table_name
(),
TableName
=
self
.
_get_table_name
(),
Key
=
self
.
encode_item
(
data
=
{
'
measurement_id'
:
measurement
_id
}),
Key
=
self
.
encode_item
(
data
=
{
'
tid'
:
type_id
,
'sid'
:
station
_id
}),
AttributeUpdates
=
self
.
encode_item
(
data
=
{
't
ype_id'
:
type_id
,
'station_id'
:
station_id
},
update
=
True
))
AttributeUpdates
=
self
.
encode_item
(
data
=
{
't
ime'
:
time
.
time
()
},
update
=
True
))
raise
gen
.
Return
(
message
)
raise
gen
.
Return
(
message
)
@
gen
.
coroutine
@
gen
.
coroutine
def
get
(
self
,
measurement_id
,
type_id
,
station_id
):
def
get
(
self
,
tid
=
1
,
sid
=
1
):
message
=
yield
gen
.
Task
(
self
.
_dynamodb
(
operation
=
'GetItem'
)
.
call
,
message
=
yield
gen
.
Task
(
self
.
_dynamodb
(
operation
=
'GetItem'
)
.
call
,
TableName
=
self
.
_get_table_name
(),
TableName
=
self
.
_get_table_name
(),
Key
=
self
.
encode_item
(
data
=
{
'
measurement_id'
:
measurement_
id
}))
Key
=
self
.
encode_item
(
data
=
{
'
tid'
:
tid
,
'sid'
:
s
id
}))
data
=
self
.
decode_item
(
item
=
message
[
'Item'
])
data
=
self
.
decode_item
(
item
=
message
[
'Item'
])
raise
gen
.
Return
(
data
)
raise
gen
.
Return
(
data
)
...
@@ -227,12 +233,12 @@ if __name__ == '__main__':
...
@@ -227,12 +233,12 @@ if __name__ == '__main__':
measurements
.
create_table
()
measurements
.
create_table
()
# You still can run code synchronous if required
# You still can run code synchronous if required
measurements
.
update
_
(
measurement_id
=
measurement_id
,
station_id
=
1
,
type_id
=
1
)
measurements
.
update
(
measurement_id
=
measurement_id
,
station_id
=
1
,
type_id
=
7
)
# run asynchronous with callback
# run asynchronous with callback
measurements
.
get
_
(
measurement_id
=
measurement_id
,
callback
=
print
)
measurements
.
get
(
)
# You even can run methods wrapped with @coroutine synchronously
# You even can run methods wrapped with @coroutine synchronously
ioloop
=
IOLoop
.
instance
()
ioloop
=
IOLoop
.
instance
()
result
=
ioloop
.
run_sync
(
partial
(
measurements
.
get
,
measurement_id
=
measurement_id
))
result
=
ioloop
.
run_sync
(
partial
(
measurements
.
get
,
sid
=
1
,
tid
=
7
))
print
(
result
)
print
(
result
)
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