Skip to content

Commit

Permalink
fix: Update poetry.lock (#28)
Browse files Browse the repository at this point in the history
* chore(poetry): Update poetry.lock

* chore(linting): Fix linting issues
  • Loading branch information
esloch authored May 15, 2023
1 parent a1bc116 commit 74e9ddf
Show file tree
Hide file tree
Showing 3 changed files with 1,150 additions and 1,134 deletions.
39 changes: 25 additions & 14 deletions epi_scanner/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
import pandas as pd
from epi_scanner.model.scanner import EpiScanner
from epi_scanner.settings import EPISCANNER_DATA_DIR, STATES
from epi_scanner.viz import plot_state_map # NOQA F401
from epi_scanner.viz import (
load_map,
plot_pars_map,
plot_series,
plot_series_px,
plot_state_map, # NOQA F401
plot_state_map_altair,
t_weeks,
top_n_cities,
Expand Down Expand Up @@ -148,9 +148,11 @@ async def update_weeks(q: Q):
# title="Number of weeks of Rt > 1 over the last s10 years",
# content=f"![plot]({fig})",
# )
q.page["plot_alt"] = ui.vega_card(box="week_map",
title="Number of weeks of Rt > 1 over the last s10 years",
specification=fig_alt.to_json())
q.page["plot_alt"] = ui.vega_card(
box="week_map",
title="Number of weeks of Rt > 1 over the last s10 years",
specification=fig_alt.to_json(),
)
ttext = await top_n_cities(q, 10)
q.page["wtable"] = ui.form_card(
box="week_table", title="Top 10 cities", items=[ui.text(ttext)]
Expand Down Expand Up @@ -188,6 +190,7 @@ async def update_r0map(q: Q):
)
await q.page.save()


async def on_update_disease(q: Q):
q.client.disease = q.args.disease
q.page["state_header"].title = f"Epi Report for {q.client.disease}"
Expand All @@ -196,6 +199,7 @@ async def on_update_disease(q: Q):
if q.client.city is not None:
await on_update_city(q)


async def on_update_UF(q: Q):
logger.info(
f"client.uf: {q.client.uf}, "
Expand Down Expand Up @@ -247,7 +251,7 @@ async def on_update_city(q: Q):
ui.choice(name=str(y), label=str(y))
for y in q.client.parameters[
q.client.parameters.geocode == int(q.client.city)
].year
].year
]
q.page["years"].items[0].dropdown.choices = years
# q.page['epi_year'].choices = years
Expand Down Expand Up @@ -286,7 +290,6 @@ async def scan_state(q: Q):
q.page["meta"].notification = "Finished scanning!"



def create_layout(q):
"""
Creates the main layout of the app
Expand Down Expand Up @@ -324,7 +327,10 @@ def create_layout(q):
ui.zone(
name="week_zone",
direction=ui.ZoneDirection.ROW,
zones=[ui.zone("week_map",size='65%'), ui.zone("week_table",size='35%')],
zones=[
ui.zone("week_map", size="65%"),
ui.zone("week_table", size="35%"),
],
),
ui.zone(
name="R0_zone",
Expand Down Expand Up @@ -364,7 +370,7 @@ async def load_table(q: Q):
for gc in DATA_TABLE.municipio_geocodigo.unique():
q.client.cities[int(gc)] = q.client.brmap[
q.client.brmap.code_muni.astype(int) == int(gc)
].name_muni.values[0]
].name_muni.values[0]
choices = [
ui.choice(str(gc), q.client.cities[gc])
for gc in DATA_TABLE.municipio_geocodigo.unique()
Expand All @@ -382,14 +388,18 @@ async def update_analysis(q):
syear = 2010
eyear = 2022
img = await plot_series(
q, int(q.client.city), f"{syear}-01-01", f"{eyear}-12-31")
q, int(q.client.city), f"{syear}-01-01", f"{eyear}-12-31"
)
else:
syear = eyear = q.client.epi_year
img = await plot_series(
q, int(q.client.city), f"{syear}-01-01", f"{eyear}-12-31")
q, int(q.client.city), f"{syear}-01-01", f"{eyear}-12-31"
)

q.page["ts_plot"] = ui.markdown_card(
box="analysis", title=f"{q.client.disease} Weekly Cases", content=f"![plot]({img})"
box="analysis",
title=f"{q.client.disease} Weekly Cases",
content=f"![plot]({img})",
)
await q.page.save()
q.page["ts_plot_px"] = ui.frame_card(
Expand Down Expand Up @@ -474,9 +484,10 @@ def add_sidebar(q):
name="disease",
label="Select disease",
required=True,
choices=[ui.choice("dengue", "Dengue"),
ui.choice("chikungunya", "Chikungunya")
],
choices=[
ui.choice("dengue", "Dengue"),
ui.choice("chikungunya", "Chikungunya"),
],
trigger=True,
),
ui.dropdown(
Expand Down
41 changes: 22 additions & 19 deletions epi_scanner/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import uuid
from pathlib import Path

import geopandas as gpd
import altair as alt
import geopandas as gpd
import gpdvega # NOQA
import matplotlib.pyplot as plt
import pandas as pd
Expand Down Expand Up @@ -41,9 +41,7 @@ async def t_weeks(q: Q):
await q.page.save()


async def plot_state_map(
q, themap: gpd.GeoDataFrame, column=None
):
async def plot_state_map(q, themap: gpd.GeoDataFrame, column=None):
ax = themap.plot(
column=column,
legend=True,
Expand All @@ -60,20 +58,25 @@ async def plot_state_map(


async def plot_state_map_altair(q: Q, themap: gpd.GeoDataFrame, column=None):
spec = alt.Chart(themap).mark_geoshape(
).encode(
color=alt.Color(f'{column}:Q',
sort="ascending",
scale=alt.Scale(scheme='viridis'), # , domain = [-0.999125,41.548309]),
legend=alt.Legend(title="Weeks",
orient='bottom',
tickCount=10,
)
),
tooltip=['name_muni', column + ':N']
).properties(
width=600,
height=400
spec = (
alt.Chart(themap)
.mark_geoshape()
.encode(
color=alt.Color(
f"{column}:Q",
sort="ascending",
scale=alt.Scale(
scheme="viridis"
), # , domain = [-0.999125,41.548309]),
legend=alt.Legend(
title="Weeks",
orient="bottom",
tickCount=10,
),
),
tooltip=["name_muni", column + ":N"],
)
.properties(width=600, height=400)
)
return spec

Expand Down Expand Up @@ -104,7 +107,7 @@ def get_year_map(year: int, themap: gpd.GeoDataFrame, pars: pd.DataFrame):


async def plot_pars_map(
q, themap: gpd.GeoDataFrame, year: int, state: str, column="R0"
q, themap: gpd.GeoDataFrame, year: int, state: str, column="R0"
):
map_pars = get_year_map(year, q.client.weeks_map, q.client.parameters)
ax = themap.plot(alpha=0.3)
Expand Down
Loading

0 comments on commit 74e9ddf

Please sign in to comment.