Skip to content

Commit

Permalink
HEA-592 first version of Inventory Dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
enjoki committed Jan 3, 2025
1 parent d8bebad commit c805df1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 19 deletions.
50 changes: 32 additions & 18 deletions apps/viz/dash/inventory_dashboard/app.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import logging

import dash_bootstrap_components as dbc
import plotly.express as px
from dash import dash_table, dcc, html
from dash.dependencies import Input, Output
from django_plotly_dash import DjangoDash
import dash_bootstrap_components as dbc
from datetime import datetime

from .functions import clean_livelihood_data, clean_wealth_group_data

Expand All @@ -15,11 +15,7 @@
logger = logging.getLogger(__name__)

# Dash app
app = DjangoDash(
"Inventory_dashboard",
suppress_callback_exceptions=True,
external_stylesheets=[dbc.themes.BOOTSTRAP]
)
app = DjangoDash("Inventory_dashboard", suppress_callback_exceptions=True, external_stylesheets=[dbc.themes.BOOTSTRAP])
app.title = "HEA Dashboard"

# Layout
Expand All @@ -34,7 +30,7 @@
id="country-dropdown",
options=[{"label": country, "value": country} for country in unique_countries],
placeholder="Select Country(s)",
multi=True,
multi=True,
),
],
style={"flex": "1", "marginRight": "10px"}, # Set flex and spacing
Expand All @@ -48,14 +44,14 @@
multi=True,
),
],
style={"flex": "1"},
style={"flex": "1"},
),
],
style={
"display": "flex",
"display": "flex",
"width": "100%",
"justifyContent": "space-between",
"marginBottom": "20px",
"justifyContent": "space-between",
"marginBottom": "20px",
},
),
html.Div(
Expand Down Expand Up @@ -123,24 +119,37 @@ def update_charts(selected_countries, selected_zones):

# Filter data based on selected livelihood zones
if selected_zones:
filtered_livelihood = filtered_livelihood[filtered_livelihood["livelihood_zone_baseline_label"].isin(selected_zones)]
filtered_livelihood = filtered_livelihood[
filtered_livelihood["livelihood_zone_baseline_label"].isin(selected_zones)
]
filtered_wealth = filtered_wealth[filtered_wealth["livelihood_zone_baseline_label"].isin(selected_zones)]

# Group data for charts
livelihood_grouped = (
filtered_livelihood.groupby(["livelihood_zone_baseline_label", "strategy_type_label"]).size().reset_index(name="Count")
filtered_livelihood.groupby(["livelihood_zone_baseline_label", "strategy_type_label"])
.size()
.reset_index(name="Count")
)
wealth_grouped = (
filtered_wealth.groupby("livelihood_zone_baseline_label")
.size()
.reset_index(name="Wealth Characteristics Count")
)
wealth_grouped = filtered_wealth.groupby("livelihood_zone_baseline_label").size().reset_index(name="Wealth Characteristics Count")
wealth_monthly_grouped = (
filtered_wealth.groupby(["created_month", "livelihood_zone_baseline_label"]).size().reset_index(name="Wealth Characteristics Count")
filtered_wealth.groupby(["created_month", "livelihood_zone_baseline_label"])
.size()
.reset_index(name="Wealth Characteristics Count")
)

wealth_fig = px.bar(
wealth_grouped,
x="livelihood_zone_baseline_label",
y="Wealth Characteristics Count",
title="Wealth Characteristics per Baseline",
labels={"livelihood_zone_baseline_label": "Baseline", "Wealth Characteristics Count": "No. of Wealth Characteristics"},
labels={
"livelihood_zone_baseline_label": "Baseline",
"Wealth Characteristics Count": "No. of Wealth Characteristics",
},
)

livelihood_fig = px.bar(
Expand All @@ -149,7 +158,11 @@ def update_charts(selected_countries, selected_zones):
y="Count",
color="livelihood_zone_baseline_label",
title="Livelihood Strategies per Baseline",
labels={"strategy_type_label": "Strategy Type", "Count": "No. of Livelihood Strategies", "livelihood_zone_baseline_label": "Baseline"},
labels={
"strategy_type_label": "Strategy Type",
"Count": "No. of Livelihood Strategies",
"livelihood_zone_baseline_label": "Baseline",
},
)

# Stacked/multiple column chart for wealth characteristics by month
Expand All @@ -169,6 +182,7 @@ def update_charts(selected_countries, selected_zones):

return zone_options, wealth_fig, livelihood_fig, wealth_monthly_fig, livelihood_grouped.to_dict("records")


# Run the app
if __name__ == "__main__":
app.run_server(debug=True)
2 changes: 1 addition & 1 deletion hea/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
WealthCharacteristicViewSet,
WealthGroupCategoryViewSet,
)
from viz.views import InventoryDashboardView
from viz.views import InventoryDashboardView # noqa

router = routers.DefaultRouter()

Expand Down

0 comments on commit c805df1

Please sign in to comment.