Spaces:
Sleeping
Sleeping
# app/visualisation.py | |
import streamlit as st | |
import pandas as pd | |
import json | |
import altair as alt | |
def show_comparison_chart(bill_file, recommended_plans): | |
""" | |
Visualises current vs recommended plans in a bar chart. | |
""" | |
# Simulate current usage | |
try: | |
if bill_file.name.endswith(".json"): | |
bill_data = json.load(bill_file) | |
else: | |
bill_data = {"lines": 10, "data_usage_gb": 50, "current_cost": 500} | |
except: | |
bill_data = {"lines": 10, "data_usage_gb": 50, "current_cost": 500} | |
current_cost = bill_data["current_cost"] | |
current_lines = bill_data["lines"] | |
data = { | |
"Plan": ["Current Bill"] + list(recommended_plans["plan_name"]), | |
"Cost (Est)": [current_cost] + list(recommended_plans["price_per_line"] * current_lines) | |
} | |
df = pd.DataFrame(data) | |
chart = alt.Chart(df).mark_bar().encode( | |
x=alt.X('Plan', sort=None), | |
y='Cost (Est)', | |
color=alt.condition( | |
alt.datum.Plan == "Current Bill", | |
alt.value('red'), | |
alt.value('green') | |
) | |
).properties( | |
width=600, | |
height=400, | |
title="Cost Comparison: Current vs Recommended Plans" | |
) | |
st.altair_chart(chart, use_container_width=True) | |