Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
robswc committed May 9, 2024
2 parents 93f5cdd + 4ef872d commit e34c4ab
Show file tree
Hide file tree
Showing 12 changed files with 285 additions and 178 deletions.
21 changes: 21 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.PHONY: setup
.PHONY: build
.PHONY: lint
.PHONY: test

setup:
@which python3 > /dev/null 2>&1 || (echo "Python is not installed on the system. Please install Python and try again." && exit 1)
python3 -m venv .venv
.venv/bin/pip install -r app/requirements.txt

build:
@which docker > /dev/null 2>&1 || (echo "Docker is not installed on the system. Please install Docker and try again." && exit 1)
docker build -t nadocast-ui .

lint:
.venv/bin/mypy --install-types
.venv/bin/mypy app --ignore-missing-imports --config-file=pyproject.toml
.venv/bin/black app

test:
.venv/bin/pytest app
37 changes: 20 additions & 17 deletions app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,28 @@
# available_pages = [page for page in available_pages if page["name"] != "Home"]
available_pages = [page for page in available_pages if page["name"] != "Map"]

app.layout = html.Div([
dbc.NavbarSimple(
children=[
dbc.NavItem(dbc.NavLink("Home", href="/")),
dbc.NavItem(dbc.NavLink("Data", href="/data")),
dbc.NavItem(dbc.NavLink("Map", href="/map")),
],
brand=html.Img(
src="/assets/nadocast-ui-logo.png", height=64,
app.layout = html.Div(
[
dbc.NavbarSimple(
children=[
dbc.NavItem(dbc.NavLink("Home", href="/")),
dbc.NavItem(dbc.NavLink("Data", href="/data")),
dbc.NavItem(dbc.NavLink("Map", href="/map")),
],
brand=html.Img(
src="/assets/nadocast-ui-logo.png",
height=64,
),
brand_href="/",
color="black",
dark=True,
className="mb-3",
),
brand_href="/",
color="black",
dark=True,
className='mb-3'
),
dash.page_container
])
dash.page_container,
]
)

server = app.server

if __name__ == '__main__':
if __name__ == "__main__":
app.run(debug=True)
85 changes: 52 additions & 33 deletions app/pages/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,60 @@
import dash
from dash import html, dcc, callback, Input, Output

from utils.data import get_forecasts, download_forecast, create_probabilities_df, list_forecasts
from utils.data import (
get_forecasts,
download_forecast,
create_probabilities_df,
list_forecasts,
)
from utils.ui import input_group
import dash_bootstrap_components as dbc

dash.register_page(__name__)

TZ_OPTIONS = [
{
'label': '0z',
'value': 0},
{
'label': '12z',
'value': 12},
{
'label': '14z',
'value': 14},
{"label": "0z", "value": 0},
{"label": "12z", "value": 12},
{"label": "14z", "value": 14},
]

layout = dbc.Container([
html.H1('Get Forecast'),
input_group(component_id='date', label='Date', value=datetime.datetime.now(), input_type='date'),
input_group(component_id='hour', label='Hour', value=0, input_type='dropdown', options=TZ_OPTIONS),
dbc.Button('Get Forecast', id='get-forecast', className='w-100'),
html.Div(id='forecast-output'),
html.H1("All Forecasts"),
html.Div(id='all-forecasts'),
dbc.Button('Refresh', id='get-all-forecasts', className='w-100'),
])
layout = dbc.Container(
[
html.H1("Get Forecast"),
input_group(
component_id="date",
label="Date",
value=datetime.datetime.now(),
input_type="date",
),
input_group(
component_id="hour",
label="Hour",
value=0,
input_type="dropdown",
options=TZ_OPTIONS,
),
dbc.Button("Get Forecast", id="get-forecast", className="w-100"),
html.Div(id="forecast-output"),
html.H1("All Forecasts"),
html.Div(id="all-forecasts"),
dbc.Button("Refresh", id="get-all-forecasts", className="w-100"),
]
)


@callback(
Output('forecast-output', 'children'),
Input('get-forecast', 'n_clicks'),
Input('date', 'date'),
Input('hour', 'value'),
Output("forecast-output", "children"),
Input("get-forecast", "n_clicks"),
Input("date", "date"),
Input("hour", "value"),
)
def get_forecast(n_clicks, date: str, hour: int):
if n_clicks is None:
return ''
return ""

# get a datetime object from date string, it will come in like this '2024-05-07T15:34:23.565221'
date = datetime.datetime.strptime(date.split('T')[0], '%Y-%m-%d')
date = datetime.datetime.strptime(date.split("T")[0], "%Y-%m-%d")
print(f"Selected Date {date} Hour {hour}")

probas = create_probabilities_df(date, hour, 1)
Expand All @@ -53,17 +65,24 @@ def get_forecast(n_clicks, date: str, hour: int):


@callback(
Output('all-forecasts', 'children'),
Input('get-all-forecasts', 'n_clicks'),
Output("all-forecasts", "children"),
Input("get-all-forecasts", "n_clicks"),
)
def get_all_forecasts(n_clicks):
forecast_files = list_forecasts(path='storage/fips_probabilities', recursive=True)
forecast_files = list_forecasts(path="storage/fips_probabilities", recursive=True)
forecasts = []
for f in forecast_files:
forecasts.append(
html.Tr([
html.Td(f),
html.Td(dbc.Button("View", href=f"/map/{f.split('/')[-1].split('.')[0]}"))
], className='d-flex justify-content-between align-items-center')
html.Tr(
[
html.Td(f),
html.Td(
dbc.Button(
"View", href=f"/map/{f.split('/')[-1].split('.')[0]}"
)
),
],
className="d-flex justify-content-between align-items-center",
)
)
return html.Table(forecasts)
4 changes: 2 additions & 2 deletions app/pages/empty_map.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import dash
from dash import dcc

dash.register_page(__name__, path_template='/map', name='Map')
dash.register_page(__name__, path_template="/map", name="Map")


def layout():
return dcc.Location(pathname='/map/today', refresh=True, id='redirect')
return dcc.Location(pathname="/map/today", refresh=True, id="redirect")
12 changes: 5 additions & 7 deletions app/pages/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from dash import html, dcc
import dash_bootstrap_components as dbc

dash.register_page(__name__, path_template='/', name='Home')
dash.register_page(__name__, path_template="/", name="Home")


def get_readme_from_github():
Expand All @@ -14,17 +14,15 @@ def get_readme_from_github():
raw = response.text

# remove any images within the markdown
raw = raw.split('\n')
raw = raw.split("\n")
new_raw = []
for line in raw:
if not line.startswith('!['):
if not line.startswith("!["):
new_raw.append(line)
raw = '\n'.join(new_raw)
raw = "\n".join(new_raw)

return raw


def layout():
return dbc.Container([
dbc.Card(dcc.Markdown(get_readme_from_github()), body=True)
])
return dbc.Container([dbc.Card(dcc.Markdown(get_readme_from_github()), body=True)])
Loading

0 comments on commit e34c4ab

Please sign in to comment.