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
f02c58ca
Commit
f02c58ca
authored
Dec 24, 2016
by
Dominik Rosiek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
first tests
parent
bf8cd149
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
112 additions
and
29 deletions
+112
-29
.coverage
.coverage
+1
-0
cron_update_measurements.py
cron_update_measurements.py
+33
-7
pollutions_csv.py
pollutions_csv.py
+0
-2
requirements.txt
requirements.txt
+5
-2
stations_csv.py
stations_csv.py
+0
-2
test_models.py
test_models.py
+73
-16
No files found.
.coverage
0 → 100644
View file @
f02c58ca
This source diff could not be displayed because it is too large. You can
view the blob
instead.
cron_update_measurements.py
View file @
f02c58ca
# -*- coding: utf-8 -*-
# -*- coding: utf-8 -*-
"""
This script is responsible for update measurement values.
"""
from
uuid
import
UUID
from
uuid
import
UUID
import
requests
import
requests
import
time
import
time
from
tornado.ioloop
import
IOLoop
from
tornado.ioloop
import
IOLoop
from
functools
import
partial
from
db
import
DDBstations
,
DDBtypes
from
dateutil.parser
import
parse
from
dateutil.parser
import
parse
import
models
import
models
from
tornado.gen
import
coroutine
from
tornado.gen
import
coroutine
def
get_station_by_id
(
station_id
,
station_data
):
def
get_station_by_id
(
station_id
,
station_data
):
"""
Returns station from dict of stations based on station_id
:param station_id (int):
:param station_data (dict):
:return (Station):
"""
station_id
=
str
(
UUID
(
int
=
int
(
station_id
)))
station_id
=
str
(
UUID
(
int
=
int
(
station_id
)))
return
station_data
[
station_id
]
return
station_data
[
station_id
]
# for station in station_data:
# if str(station['api_station_id']) == station_id:
# result = yield models.Station.get(station['station_id'])
# return result
def
get_type_by_name
(
type_name
,
type_data
):
def
get_type_by_name
(
type_name
,
type_data
):
"""
Returns pollution type from dict of types based on type_name
:param type_name (str):
:param type_data (dict):
:return (Type):
"""
for
type
in
type_data
.
values
():
for
type
in
type_data
.
values
():
if
type
.
shortname
==
type_name
:
if
type
.
shortname
==
type_name
:
return
type
return
type
def
get_timestamp_from_datetime
(
datetime_string
):
def
get_timestamp_from_datetime
(
datetime_string
):
"""
Parses datetime value and return timestamp
:param datetime_string (str):
:return (int):
"""
dt
=
parse
(
datetime_string
)
dt
=
parse
(
datetime_string
)
return
time
.
mktime
(
dt
.
timetuple
())
return
time
.
mktime
(
dt
.
timetuple
())
@
coroutine
@
coroutine
def
main
():
def
main
():
"""
Main function
:return (None):
"""
apiURL
=
"http://powietrze.malopolska.pl/_powietrzeapi/api/dane?act=danemiasta&ci_id=1"
apiURL
=
"http://powietrze.malopolska.pl/_powietrzeapi/api/dane?act=danemiasta&ci_id=1"
r
=
requests
.
get
(
apiURL
)
r
=
requests
.
get
(
apiURL
)
...
@@ -52,5 +79,4 @@ def main():
...
@@ -52,5 +79,4 @@ def main():
value
=
ready_measurement_value
,
time
=
ready_measurement_timestamp
)
value
=
ready_measurement_value
,
time
=
ready_measurement_timestamp
)
yield
measurement
.
save
()
yield
measurement
.
save
()
# ioloop = IOLoop.instance()
IOLoop
.
current
()
.
run_sync
(
main
)
IOLoop
.
current
()
.
run_sync
(
main
)
pollutions_csv.py
View file @
f02c58ca
from
uuid
import
UUID
from
uuid
import
UUID
from
functools
import
partial
import
models
import
models
import
csv
import
csv
...
...
requirements.txt
View file @
f02c58ca
requests
requests
==2.12.4
tornado
==
4.4.2
tornado
==
4.4.2
botocore
==0.65.0
botocore
==0.65.0
tornado-botocore
==0.1.6
tornado-botocore
==0.1.6
nose
==1.3.7
coverage
==4.2
asynctest
==0.9.0
\ No newline at end of file
stations_csv.py
View file @
f02c58ca
from
uuid
import
UUID
from
uuid
import
UUID
from
functools
import
partial
import
models
import
models
import
csv
import
csv
...
...
test_models.py
View file @
f02c58ca
import
models
import
uuid
from
unittest.mock
import
MagicMock
,
patch
station
=
models
.
Station
(
1
,
"Kraków"
,
12
,
13
,
"Aleje"
)
station
.
save
()
from
asynctest
import
CoroutineMock
station2
=
models
.
Station
.
get
(
station
.
id
)
from
models
import
Type
assert
station
.
id
==
station2
.
id
from
tornado.testing
import
AsyncTestCase
,
gen_test
pollution_type
=
models
.
Type
(
shortname
=
"pm2"
,
unit
=
"mg"
,
norm
=
120
,
longname
=
"long_pm2"
,
description
=
"description pm2"
)
class
TypeTest
(
AsyncTestCase
):
pollution_type
.
save
()
def
setUp
(
self
):
pollution_type2
=
models
.
Type
.
get
(
pollution_type
.
id
)
Type
.
stored
=
{}
assert
pollution_type
.
id
==
pollution_type2
.
id
super
(
TypeTest
,
self
)
.
setUp
()
self
.
id
=
uuid
.
uuid4
()
measurement
=
models
.
Measurement
(
station
=
station
,
pollution_type
=
pollution_type
,
value
=
13
,
time
=
124
)
self
.
shortname
=
"test_shortname"
measurement
.
save
()
self
.
unit
=
"test_unit"
measurement2
=
models
.
Measurement
.
get
(
measurement
.
id
)
self
.
norm
=
57
assert
measurement
.
id
==
measurement2
.
id
self
.
longname
=
"test_longname"
\ No newline at end of file
self
.
description
=
"test_description"
self
.
type
=
Type
(
shortname
=
self
.
shortname
,
unit
=
self
.
unit
,
norm
=
self
.
norm
,
longname
=
self
.
longname
,
description
=
self
.
description
,
type_id
=
self
.
id
)
@
gen_test
def
test_init
(
self
):
self
.
assertEqual
(
self
.
type
.
id
,
self
.
id
)
self
.
assertEqual
(
self
.
type
.
shortname
,
self
.
shortname
)
self
.
assertEqual
(
self
.
type
.
unit
,
self
.
unit
)
self
.
assertEqual
(
self
.
type
.
norm
,
self
.
norm
)
self
.
assertEqual
(
self
.
type
.
longname
,
self
.
longname
)
self
.
assertEqual
(
self
.
type
.
description
,
self
.
description
)
@
gen_test
def
test_get_from_storage
(
self
):
Type
.
stored
=
{
self
.
type
.
id
:
self
.
type
}
result
=
yield
Type
.
get
(
self
.
type
.
id
)
self
.
assertEqual
(
result
,
self
.
type
)
@
gen_test
def
test_get
(
self
):
with
patch
(
'models.DDBtypes'
)
as
mock_types
:
mock_types
.
return_value
.
get
=
CoroutineMock
()
mock_types
.
return_value
.
get
.
return_value
=
{
'type_id'
:
self
.
id
,
'shortname'
:
self
.
shortname
,
'unit'
:
self
.
unit
,
'norm'
:
self
.
norm
,
'longname'
:
self
.
longname
,
'description'
:
self
.
description
}
result
=
yield
Type
.
get
(
self
.
type
.
id
)
self
.
assertEqual
(
result
.
id
,
self
.
id
)
self
.
assertEqual
(
result
.
shortname
,
self
.
shortname
)
self
.
assertEqual
(
result
.
unit
,
self
.
unit
)
self
.
assertEqual
(
result
.
norm
,
self
.
norm
)
self
.
assertEqual
(
result
.
longname
,
self
.
longname
)
self
.
assertEqual
(
result
.
description
,
self
.
description
)
# import models
#
# station = models.Station(1, "Kraków", 12, 13, "Aleje")
# station.save()
# station2 = models.Station.get(station.id)
# assert station.id == station2.id
#
# pollution_type = models.Type(shortname="pm2", unit="mg", norm=120, longname="long_pm2", description="description pm2")
# pollution_type.save()
# pollution_type2 = models.Type.get(pollution_type.id)
# assert pollution_type.id == pollution_type2.id
#
# measurement = models.Measurement(station=station, pollution_type=pollution_type, value=13, time=124)
# measurement.save()
# measurement2 = models.Measurement.get(measurement.id)
# assert measurement.id == measurement2.id
\ No newline at end of file
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