Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
DashboardLeaf
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ProjectLeaf
DashboardLeaf
Commits
28b1c3ca
Commit
28b1c3ca
authored
Oct 14, 2020
by
Robert Goldmann
Browse files
Options
Downloads
Patches
Plain Diff
Fixed #9 - new tile: hourly forecast
parent
908d01ec
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/logic/tile/tiles/HourlyForecastTile.html
+78
-0
78 additions, 0 deletions
src/logic/tile/tiles/HourlyForecastTile.html
src/logic/tile/tiles/HourlyForecastTile.py
+64
-0
64 additions, 0 deletions
src/logic/tile/tiles/HourlyForecastTile.py
with
142 additions
and
0 deletions
src/logic/tile/tiles/HourlyForecastTile.html
0 → 100644
+
78
−
0
View file @
28b1c3ca
<style>
.hourlyForecastTile
{
background-color
:
#2F2F2F
;
flex-direction
:
row
;
}
.hourlyForecastTile
.icon
{
font-size
:
10vmin
;
}
.hourlyForecastTile
.content
{
display
:
flex
;
flex-direction
:
row
;
align-items
:
center
;
justify-content
:
space-between
;
width
:
95%
;
height
:
85%
;
}
.hourlyForecastTile
.entry
{
display
:
flex
;
flex-direction
:
column
;
align-items
:
center
;
justify-content
:
space-between
;
flex
:
1
;
height
:
100%
;
}
.hourlyForecastTile
.icon
{
font-size
:
4vmin
;
}
.hourlyForecastTile
.hour
{
font-size
:
1.5vmin
;
}
.hourlyForecastTile
.temperature
{
font-size
:
2vmin
;
font-weight
:
bold
;
}
.hourlyForecastTile
.rain
{
display
:
flex
;
flex-direction
:
row
;
align-items
:
center
;
justify-content
:
space-between
;
font-size
:
1.5vmin
;
}
.hourlyForecastTile
.rain
i
{
font-size
:
3vmin
;
}
.hourlyForecastTile
.rainProbability
{
padding-left
:
1vmin
;
}
.hourlyForecastTile
.windSpeed
{
font-size
:
1.3vmin
;
}
</style>
<div
class=
"hourlyForecastTile"
>
<div
class=
"content"
>
{% for item in data %}
<div
class=
"entry"
>
<div
class=
"hour"
>
{{ item['hour'] }} Uhr
</div>
<i
class=
"wi wi-owm-{{ item['icon'] }} icon"
></i>
<div
class=
"temperature"
style=
"color: {{ item['temperatureColor'] }}"
>
{{ item['temperature'] }}
°
C
</div>
<div
class=
"rain"
>
<i
class=
"wi wi-raindrops"
></i>
<div
class=
"rainProbability"
>
{{ item['rainProbability'] }}
</div>
</div>
<div
class=
"windSpeed"
style=
"color: {{ item['windSpeedColor'] }}"
>
{{ item['windSpeed'] }}
</div>
</div>
{% endfor %}
</div>
</div>
This diff is collapsed.
Click to expand it.
src/logic/tile/tiles/HourlyForecastTile.py
0 → 100644
+
64
−
0
View file @
28b1c3ca
import
os
from
datetime
import
datetime
from
typing
import
Dict
import
pytz
from
flask
import
Blueprint
from
logic
import
Helpers
from
logic.service.ServiceManager
import
ServiceManager
from
logic.tile.Tile
import
Tile
class
HourlyForecastTile
(
Tile
):
EXAMPLE_SETTINGS
=
{
"
lat
"
:
"
51.012825
"
,
"
lon
"
:
"
13.666365
"
,
"
apiKey
"
:
"
myApiKey
"
,
"
timeZone
"
:
"
Europe/Berlin
"
}
def
__init__
(
self
,
uniqueName
:
str
,
settings
:
Dict
,
intervalInSeconds
:
int
):
super
().
__init__
(
uniqueName
,
settings
,
intervalInSeconds
)
def
fetch
(
self
,
pageName
:
str
)
->
Dict
:
weatherService
=
ServiceManager
.
get_instance
().
get_service_by_type_name
(
'
WeatherService
'
)
fetchIntervalInSeconds
=
60
*
10
# query api less often
timeZone
=
pytz
.
timezone
(
self
.
_settings
[
'
timeZone
'
])
# cache key will be determined in service
weatherData
=
weatherService
.
get_data
(
''
,
fetchIntervalInSeconds
,
self
.
_settings
)
hourData
=
[]
hourlyForecast
=
weatherData
[
'
hourly
'
]
for
entry
in
hourlyForecast
[:
12
]:
timestamp
=
entry
[
'
dt
'
]
timestamp
=
datetime
.
utcfromtimestamp
(
timestamp
)
timestamp
=
timeZone
.
fromutc
(
timestamp
)
temperature
=
21.3
icon
=
entry
[
'
weather
'
][
0
][
'
id
'
]
rainProbability
=
entry
[
'
pop
'
]
*
100
windSpeed
=
entry
[
'
wind_speed
'
]
*
3.6
hourData
.
append
({
'
hour
'
:
timestamp
.
strftime
(
'
%H
'
),
'
temperature
'
:
Helpers
.
round_to_decimals
(
temperature
,
1
),
'
temperatureColor
'
:
Helpers
.
determine_color_for_temperature
(
temperature
),
'
icon
'
:
icon
,
'
windSpeed
'
:
f
'
{
Helpers
.
round_to_decimals
(
windSpeed
,
1
)
}
km/h
'
,
'
windSpeedColor
'
:
Helpers
.
determine_color_for_wind
(
windSpeed
),
'
rainProbability
'
:
f
'
{
Helpers
.
round_to_decimals
(
rainProbability
,
0
)
}
%
'
})
return
{
'
hours
'
:
hourData
}
def
render
(
self
,
data
:
Dict
)
->
str
:
return
Tile
.
render_template
(
os
.
path
.
dirname
(
__file__
),
__class__
.
__name__
,
data
=
data
[
'
hours
'
])
def
construct_blueprint
(
self
,
pageName
:
str
,
*
args
,
**
kwargs
):
return
Blueprint
(
f
'
{
pageName
}
_
{
__class__
.
__name__
}
_
{
self
.
get_uniqueName
()
}
'
,
__name__
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment