import plotly.graph_objects as go


def load_data():
    return [
        ("1973-01-01", 2.0),
        ("1974-01-01", 9.5),
        ("1975-01-01", 10.0),
        ("1976-01-01", 11.2),
        ("1977-01-01", 12.0),
        ("1978-01-01", 12.7),
        ("1979-01-01", 13.34),
        ("1979-04-01", 13.84),
        ("1979-07-01", 14.16),
        ("1979-10-01", 14.54),
    ]


def value_table(data):
    return {"columns": ["Date", "Oil price (USD per barrel)"], "rows": [list(row) for row in data]}


def make_before(data) -> go.Figure:
    yearly, quarterly = data[:6], data[6:]
    fig = go.Figure()
    for rows, name, axis in ((yearly, "Annual price", "y"), (quarterly, "Quarterly price", "y2")):
        dates, prices = zip(*rows, strict=True)
        fig.add_trace(go.Scatter(x=dates, y=prices, name=name, yaxis=axis, mode="lines+markers"))
    fig.update_layout(
        template="simple_white",
        xaxis_type="category",
        xaxis_tickangle=-45,
        yaxis={"title": "USD per barrel", "range": [0, 15]},
        yaxis2={"title": "USD per barrel", "overlaying": "y", "side": "right", "range": [13, 14.7]},
    )
    return fig


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