Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move chart into components file, grouped bar for pop comparison #16

Merged
merged 2 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions components.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import streamlit as st
from streamlit_echarts import st_echarts
import util


Expand Down Expand Up @@ -49,3 +50,74 @@ def year_slider(year_values):
year_values.index(start_year) : year_values.index(end_year) + 1
]
return selected_range


def claim_type_line_chart(df, animated=True):
if animated:
t = st.session_state["iteration"]
month_list = sorted(list(set(df["year_month"])))
anim_data = df.loc[df["year_month"] <= month_list[t], :]
list_data = [anim_data.columns.to_list()] + anim_data.values.tolist()
else:
list_data = [df.columns.to_list()] + df.values.tolist()
series = list(set(df["claim_type"]))
datasetWithFilters = [
{
"id": f"dataset_{s}",
"fromDatasetId": "dataset_raw",
"transform": {
"type": "filter",
"config": {
"and": [
{"dimension": "claim_type", "=": s},
]
},
},
}
for s in series
]
seriesList = [
{
"type": "line",
"datasetId": f"dataset_{s}",
"showSymbol": False,
"name": s,
"labelLayout": {"moveOverlap": "shiftY"},
"emphasis": {"focus": "series"},
"encode": {
"x": "year_month",
"y": "paid_amount_pmpm",
"label": ["claim_type", "paid_amount_pmpm"],
"itemName": "year_month",
"tooltip": ["paid_amount_pmpm"],
},
}
for s in series
]
option = {
"color": ["#06405C", "#FFCC05", "#66B1E2"],
"dataset": [{"id": "dataset_raw", "source": list_data}] + datasetWithFilters,
"title": {"text": "Paid Amount PMPM by Claim Type"},
"tooltip": {"order": "valueDesc", "trigger": "axis"},
"xAxis": {"type": "category", "nameLocation": "middle"},
"yAxis": {"name": "PMPM"},
"grid": {"right": 140},
"series": seriesList,
}
st_echarts(options=option, height="400px", key="chart")


def pop_grouped_bar(df):
pivoted_df = df.pivot(
index="category", columns="year", values="current_period_pmpm"
).reset_index()
list_data = [pivoted_df.columns.to_list()] + pivoted_df.values.tolist()
option = {
"legend": {},
"tooltip": {},
"dataset": {"source": list_data},
"xAxis": {"type": "category", "data": sorted(list(set(df["category"])))},
"yAxis": {"type": "value"},
"series": [{"type": "bar"} for x in list(set(df["year"]))],
}
st_echarts(options=option)
61 changes: 4 additions & 57 deletions pages/02_financial_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,62 +9,8 @@
import pandas as pd


def claim_type_line_chart(df, animated=True):
if animated:
t = st.session_state["iteration"]
month_list = sorted(list(set(pmpm_claim_type_data["year_month"])))
anim_data = df.loc[df["year_month"] <= month_list[t], :]
list_data = [anim_data.columns.to_list()] + anim_data.values.tolist()
else:
list_data = [df.columns.to_list()] + df.values.tolist()
series = list(set(df["claim_type"]))
datasetWithFilters = [
{
"id": f"dataset_{s}",
"fromDatasetId": "dataset_raw",
"transform": {
"type": "filter",
"config": {
"and": [
{"dimension": "claim_type", "=": s},
]
},
},
}
for s in series
]
seriesList = [
{
"type": "line",
"datasetId": f"dataset_{s}",
"showSymbol": False,
"name": s,
"labelLayout": {"moveOverlap": "shiftY"},
"emphasis": {"focus": "series"},
"encode": {
"x": "year_month",
"y": "paid_amount_pmpm",
"label": ["claim_type", "paid_amount_pmpm"],
"itemName": "year_month",
"tooltip": ["paid_amount_pmpm"],
},
}
for s in series
]
option = {
"color": ["#06405C", "#FFCC05", "#66B1E2"],
"dataset": [{"id": "dataset_raw", "source": list_data}] + datasetWithFilters,
"title": {"text": "Paid Amount PMPM by Claim Type"},
"tooltip": {"order": "valueDesc", "trigger": "axis"},
"xAxis": {"type": "category", "nameLocation": "middle"},
"yAxis": {"name": "PMPM"},
"grid": {"right": 140},
"series": seriesList,
}
st_echarts(options=option, height="400px", key="chart")


year_month_values = sorted(list(set(data.year_months()["year_month"])))

year_values = sorted(list(set([x[:4] for x in year_month_values])))
## --------------------------------- ##
## --- --- ##
Expand Down Expand Up @@ -122,14 +68,14 @@ def claim_type_line_chart(df, animated=True):
month_list = sorted(list(set(pmpm_claim_type_data["year_month"])))
if animate:
while st.session_state["iteration"] < len(month_list):
claim_type_line_chart(pmpm_claim_type_data, True)
comp.claim_type_line_chart(pmpm_claim_type_data, True)
time.sleep(0.05)
st.session_state["iteration"] += 1

if st.session_state["iteration"] < len(month_list) and animate:
st.experimental_rerun()
else:
claim_type_line_chart(pmpm_claim_type_data, False)
comp.claim_type_line_chart(pmpm_claim_type_data, False)


## --------------------------------- ##
Expand Down Expand Up @@ -196,6 +142,7 @@ def claim_type_line_chart(df, animated=True):
test = test.loc[test.year != year_values[0]]
st.table(util.format_df(test))

comp.pop_grouped_bar(test)

## --------------------------------- ##
## Service Category 1
Expand Down