File size: 1,281 Bytes
ec8033f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# 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)