import plotly.express as px


import plotly.graph_objects as go


def load_data():
    tips = px.data.tips()
    days = ("Thur", "Fri", "Sat", "Sun")
    return [
        (day, meal, int(((tips["day"] == day) & (tips["time"] == meal)).sum()))
        for day in days
        for meal in ("Lunch", "Dinner")
    ]


def value_table(data):
    return {"columns": ["Day", "Meal", "Bills"], "rows": [list(row) for row in data]}


def make_before(data) -> go.Figure:
    from plotly.subplots import make_subplots

    fig = make_subplots(rows=1, cols=2, shared_yaxes=True, subplot_titles=("Lunch", "Dinner"))
    for column, meal in enumerate(("Lunch", "Dinner"), start=1):
        days, bills = zip(*((day, count) for day, time, count in data if time == meal), strict=True)
        fig.add_trace(go.Bar(x=days, y=bills, showlegend=False), row=1, col=column)
    fig.update_layout(template="simple_white")
    fig.update_yaxes(range=[0, 100], showgrid=False)
    return fig


if __name__ == "__main__":
    print(make_before(load_data()).to_json())
