import plotly.graph_objects as go


def load_data():
    return [
        ("Jan", 820, 76, "Original"),
        ("Feb", 800, 74, "Original"),
        ("Mar", 810, 75, "Original"),
        ("Apr", 620, 51, "Replacement"),
        ("May", 600, 49, "Replacement"),
        ("Jun", 610, 50, "Replacement"),
    ]


def value_table(data):
    return {
        "columns": ["Month", "Electricity use (kWh)", "Pump runtime (hours)", "Controller"],
        "rows": [list(row) for row in data],
    }


def pump_energy(data):
    months, energy, _, _ = zip(*data, strict=True)
    return go.Scatter(
        x=months,
        y=energy,
        mode="lines+markers",
        line_color="#356890",
        hovertemplate="%{x}: %{y} kWh<extra></extra>",
    )


def make_before(data) -> go.Figure:
    fig = go.Figure(pump_energy(data))
    fig.update_layout(
        template="simple_white",
        font={"family": "Inter, system-ui, -apple-system, sans-serif", "color": "#1f2937"},
        title="New controller saves electricity by cutting pump runtime",
        yaxis={"title": "Electricity use (kWh)", "range": [550, 860]},
        margin={"l": 86, "r": 24, "t": 56, "b": 54},
    )
    return fig


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