Skip to content

Commit 2252b75

Browse files
authored
Merge pull request #11 from vegraux/updates
Update to Python 3.12
2 parents 4606bf4 + 48f625b commit 2252b75

File tree

7 files changed

+990
-639
lines changed

7 files changed

+990
-639
lines changed

app.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@
1414

1515
from src.utils import SolarPath
1616
from src.items import (
17-
card_month_slider,
17+
create_date_sliders,
1818
create_dropdown_mapstyles,
1919
create_dropdown_timezones,
2020
)
21-
import dash_html_components as html
22-
import dash_core_components as dcc
21+
from dash import html
22+
from dash import dcc
2323

2424
solar = SolarPath()
2525
app = dash.Dash(__name__, external_stylesheets=[dbc.themes.JOURNAL])
2626

27-
YEAR = datetime.datetime.today().year
27+
today = datetime.datetime.today()
2828
layout = html.Div(
2929
[
3030
dbc.Row(dbc.Col(html.H1(id="header", children="Solar path"))),
@@ -61,7 +61,8 @@
6161
),
6262
]
6363
),
64-
dbc.Row(dbc.Col(dbc.Card(card_month_slider, color="light", inverse=False))),
64+
html.Br(),
65+
dbc.Row(dbc.Col(dbc.Card(create_date_sliders(today.month, today.day), color="light", inverse=False))),
6566
dcc.Graph(id="map-fig"),
6667
dcc.Graph(id="sunrise-fig"),
6768
dcc.Graph(id="analemma-fig"),
@@ -90,7 +91,7 @@
9091
)
9192
def update_map_figure(month, day, button, map_style, timezone, location, lat, lon):
9293
solar.update_attributes(lat, lon, location, timezone)
93-
date = f"{YEAR}.{month:0>2}.{day:0>2}"
94+
date = f"{today.year}.{month:0>2}.{day:0>2}"
9495
return solar.create_map(date=date, map_style=map_style)
9596

9697

poetry.lock

+940-597
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ authors = ["vegard ulriksen solberg <vegardsolberg@hotmail.com>"]
66
license = "MIT"
77

88
[tool.poetry.dependencies]
9-
python = "^3.8"
9+
python = "^3.12"
1010
numpy = "*"
1111
plotly = "*"
1212
pandas = "*"
1313
dash = "*"
1414
dash-bootstrap-components = "*"
1515
pvlib = "*"
1616
geopy = "*"
17-
python-dotenv = "^0.19.2"
17+
pydantic-settings = "^2.2.1"
1818

1919
[tool.poetry.dev-dependencies]
2020
pre-commit = "^2.13.0"
@@ -31,7 +31,7 @@ max-line-length = 100
3131

3232
[tool.black]
3333
line-length = 100
34-
target-version = ["py37", "py38"]
34+
target-version = ["py312"]
3535
include = '\.pyi?$'
3636
exclude = '''
3737
/(

src/config.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from pydantic_settings import BaseSettings, SettingsConfigDict
2+
3+
4+
class Config(BaseSettings):
5+
model_config = SettingsConfigDict(env_file='.env', env_file_encoding='utf-8')
6+
token: str

src/items.py

+29-26
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import dash_bootstrap_components as dbc
2-
import dash_core_components as dcc
3-
import dash_html_components as html
2+
from dash import dcc
3+
from dash import html
44
import pytz
55
from geopy.geocoders import Nominatim
66

@@ -26,30 +26,33 @@
2626
11: "nov",
2727
12: "dec",
2828
}
29-
card_month_slider = [
30-
dbc.CardBody(
31-
[
32-
html.H5("Select month and day", className="card-title"),
33-
html.P("Pull the sliders to change month and day", className="card-text"),
34-
dcc.Slider(
35-
id="month-slider",
36-
min=1,
37-
max=12,
38-
step=1,
39-
value=1,
40-
marks={k: month_map[k] for k in range(1, 13)},
41-
),
42-
dcc.Slider(
43-
id="day-slider",
44-
min=1,
45-
max=31,
46-
step=1,
47-
value=1,
48-
marks={k: str(k) for k in range(1, 32)},
49-
),
50-
]
51-
)
52-
]
29+
30+
31+
def create_date_sliders(month: int, day: int) -> list[dbc.CardBody]:
32+
return [
33+
dbc.CardBody(
34+
[
35+
html.H5("Select month and day", className="card-title"),
36+
html.P("Pull the sliders to change month and day", className="card-text"),
37+
dcc.Slider(
38+
id="month-slider",
39+
min=1,
40+
max=12,
41+
step=1,
42+
value=month,
43+
marks={k: month_map[k] for k in range(1, 13)},
44+
),
45+
dcc.Slider(
46+
id="day-slider",
47+
min=1,
48+
max=31,
49+
step=1,
50+
value=day,
51+
marks={k: str(k) for k in range(1, 32)},
52+
),
53+
]
54+
)
55+
]
5356

5457

5558
map_styles_token = [

src/mapbox_token.txt

-1
This file was deleted.

src/utils.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44
55
"""
66
import datetime
7-
import os
87
from typing import List
98

10-
import dotenv
119
import geopy
1210
import numpy as np
1311
import plotly.graph_objects as go
@@ -18,9 +16,10 @@
1816
__author__ = "Vegard Ulriksen Solberg"
1917
__email__ = "vegardsolberg@hotmail.com"
2018

21-
dotenv.load_dotenv(dotenv.find_dotenv())
19+
from src.config import Config
2220
from src.items import LOCATOR, LAT, LON
2321

22+
env = Config()
2423

2524
class SolarPath:
2625
def __init__(self, location=None, lat=None, lon=None, timezone="Europe/Oslo"):
@@ -112,7 +111,7 @@ def create_solarposition_year_data(self) -> pd.DataFrame:
112111
year_range = pd.date_range(
113112
f"01/01/{self.base_year} 00:00:00",
114113
f"31/12/{self.base_year} 23:00:00",
115-
freq="H",
114+
freq="h",
116115
tz=self.timezone,
117116
)
118117
data = solarposition.get_solarposition(year_range, self.lat, self.lon)
@@ -175,7 +174,7 @@ def create_map(self, date: str, map_style: str = "satellite-streets") -> go.Figu
175174
hovertext=self.get_map_hovertext(today_data),
176175
text=hours,
177176
name="Hour of the day",
178-
textfont=dict(family="sans serif", size=18, color="black"),
177+
textfont=dict(size=15, color="black"),
179178
)
180179
)
181180

@@ -194,7 +193,7 @@ def create_map(self, date: str, map_style: str = "satellite-streets") -> go.Figu
194193
height=700,
195194
mapbox=go.layout.Mapbox(
196195
style=map_style,
197-
accesstoken=os.environ["token"],
196+
accesstoken=env.token,
198197
bearing=0,
199198
center=go.layout.mapbox.Center(lat=self.lat, lon=self.lon),
200199
pitch=0,

0 commit comments

Comments
 (0)