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
e9237b34
Commit
e9237b34
authored
Jan 03, 2017
by
Dominik Rosiek
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
ssh://gitlab.telemabk.pl/dominik/smogonet
parents
d4cd0a20
3264f707
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
125 additions
and
13 deletions
+125
-13
index.html
index.html
+83
-3
measurement_viewer.py
measurement_viewer.py
+42
-10
No files found.
index.html
View file @
e9237b34
<div
id=
"widget"
>
<!DOCTYPE html>
loading...
<html>
<head>
<meta
charset=
"UTF-8"
>
<style>
body
{
background
:
#FFFFFF
;
font-size
:
1rem
;
font-family
:
"Open Sans"
,
"Arial"
,
"sans-serif"
;
color
:
#003f65
;
width
:
370px
;
padding
:
1px
;
}
#main-box
{
height
:
100%
;
width
:
100%
;
padding
:
1px
;
}
#left-side
{
width
:
100%
;
height
:
70%
;
float
:
left
;
padding
:
1px
;
}
#right-side
{
width
:
100%
;
height
:
30%
;
float
:
right
;
padding
:
1px
;
}
</style>
<body>
<div
id=
"main-box"
>
</div>
<div
id=
"left-side"
style=
"float: center;"
>
Aktualny stan powietrza:
</div>
<div
id=
"right-side"
>
<img
src=
"http://www.free-icons-download.net/images/building-icons-68722.png"
width=
"10%"
height=
"10%"
>
<select
id=
"select-station"
style=
"float: right; display: center; font-weight: normal;"
>
<option
value=
"1"
>
ul. Bujaka
</option>
<option
value=
"2"
>
ul. Bulwarowa
</option>
<option
value=
"3"
>
ul. Złoty Róg
</option>
<option
value=
"4"
>
Al. Krasińskiego
</option>
<option
value=
"5"
>
os. Piastów
</option>
<option
value=
"6"
>
ul. Dietla
</option>
</select>
<div
id=
"value-id"
style=
"padding: center;font-size: 0.7rem"
>
µg/m³
</div>
</div>
</div>
</body>
</html>
<script>
<script>
function
getParams
()
{
var
vars
=
[];
if
(
window
.
location
.
href
.
indexOf
(
'?'
)
!==
-
1
){
var
hashes
=
window
.
location
.
href
.
slice
(
window
.
location
.
href
.
indexOf
(
'?'
)
+
1
).
split
(
'&'
)
for
(
var
i
=
0
;
i
<
hashes
.
length
;
i
++
)
{
var
hash
=
hashes
[
i
].
split
(
'='
);
vars
[
hash
[
0
]]
=
hash
[
1
];
}
}
return
vars
;
}
document
.
addEventListener
(
'DOMContentLoaded'
,
function
(){
document
.
addEventListener
(
'DOMContentLoaded'
,
function
(){
var
xhr
=
new
XMLHttpRequest
();
var
xhr
=
new
XMLHttpRequest
();
parameters
=
getParams
();
console
.
debug
(
parameters
);
xhr
.
onreadystatechange
=
function
()
{
xhr
.
onreadystatechange
=
function
()
{
if
(
xhr
.
readyState
==
XMLHttpRequest
.
DONE
)
{
if
(
xhr
.
readyState
==
XMLHttpRequest
.
DONE
)
{
document
.
getElementById
(
'widget'
).
innerHTML
=
xhr
.
responseHtml
;
console
.
debug
(
xhr
);
document
.
getElementById
(
'widget'
).
innerHTML
=
xhr
.
response
;
}
}
}
}
//xhr.open('GET', 'http://localhost:8090/view', true);
xhr
.
open
(
'GET'
,
'http://smog.telemabk.pl/view'
,
true
);
xhr
.
open
(
'GET'
,
'http://smog.telemabk.pl/view'
,
true
);
xhr
.
send
(
null
);
xhr
.
send
(
null
);
});
});
...
...
measurement_viewer.py
View file @
e9237b34
...
@@ -13,17 +13,49 @@ class MainHandler(tornado.web.RequestHandler):
...
@@ -13,17 +13,49 @@ class MainHandler(tornado.web.RequestHandler):
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
()
last_measurements
=
yield
models
.
Measurement
.
get_all_last
()
response
=
dict
()
for
measurement
in
last_measurements
:
data
=
{
"station_name"
:
measurement
.
station
.
name
,
"type"
:
measurement
.
type
.
shortname
,
"value"
:
measurement
.
value
,
"time"
:
measurement
.
time
}
response
[
measurement
.
id
]
=
data
self
.
set_header
(
'Content-Type'
,
'application/json'
)
self
.
set_header
(
'Content-Type'
,
'application/json'
)
self
.
write
(
json
.
dumps
(
response
))
self
.
write
(
json
.
dumps
(
self
.
get_full_json_response
(
stations
=
stations
,
pollutions
=
pollutions
,
last_measurements
=
last_measurements
)))
def
get_full_json_response
(
self
,
stations
,
pollutions
,
last_measurements
):
result
=
dict
()
result
[
'stations'
]
=
[
self
.
get_station_json_object
(
stations
[
station
])
for
station
in
stations
]
result
[
'pollutions'
]
=
[
self
.
get_pollution_json_object
(
pollutions
[
pollution
])
for
pollution
in
pollutions
]
result
[
'measurements'
]
=
dict
()
for
last_measurement
in
last_measurements
:
result
[
'measurements'
][
last_measurement
.
id
]
=
self
.
get_measurement_json_object
(
last_measurement
)
return
result
def
get_station_json_object
(
self
,
station
):
return
{
"uuid"
:
station
.
id
,
"name"
:
station
.
name
,
"city"
:
station
.
city
,
"longitude"
:
station
.
longitude
,
"latitude"
:
station
.
latitude
}
def
get_pollution_json_object
(
self
,
pollution
):
return
{
"uuid"
:
pollution
.
id
,
"shortname"
:
pollution
.
shortname
,
"longname"
:
pollution
.
longname
,
"description"
:
pollution
.
description
,
"unit"
:
pollution
.
unit
,
"norm"
:
pollution
.
norm
}
def
get_measurement_json_object
(
self
,
measurement
):
return
{
"uuid"
:
measurement
.
id
,
"station"
:
measurement
.
station
.
id
,
"type"
:
measurement
.
type
.
id
,
"value"
:
measurement
.
value
,
"time"
:
measurement
.
time
}
def
make_app
():
def
make_app
():
...
...
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