# /// script
# requires-python = ">=3.14"
# dependencies = [
#     "matplotlib>=3.11.0",
#     "numpy>=2.5.0",
#     "python-dateutil>=2.9.0.post0",
# ]
# ///

# INSTRUCTIONS:
# - Modify SAVE_TO, TITLE and POINTS below
# - Run using `uv run /path/to/system-graph.py`

SAVE_TO = "/tmp/graph.png"

TITLE = "INX"  # title of the graph
POINTS = [  # list of date points. Accepts most date formats
    "2025-01-01",
    "2025-12-30",
    "2026-02-06",
    "2026-02-10",
]

# TITLE = "Erisatis"
# POINTS = [
#    "December 13, 2025",
#    "December 13, 2025",
#    "December 31, 2025",
#    "January 15, 2026",
#    "January 16, 2026",
#    "January 18, 2026",
#    "January 24, 2026",
#    "January 27, 2026",
#    "January 31, 2026",
#    "February 17, 2026",
#    "March 4, 2026",
#    "May 7, 2026",
# ]

import matplotlib.pyplot as plt
import numpy as np
from dateutil.parser import parse as parse_date
from matplotlib.dates import ConciseDateFormatter

# Number of Y-axis ticks. Heuristic is all if <= 15, else 10 evenly spaced
NUM_TICKS = len(POINTS) if len(POINTS) <= 15 else 10

points_converted = [np.datetime64(parse_date(point)) for point in POINTS]

day = np.timedelta64(1, "D")


def main() -> None:
    fig, ax = plt.subplots(figsize=(10, 5), layout="constrained")
    ax.set_xlabel("Time")
    ax.set_ylabel("Headmates")
    ax.set_title(TITLE)

    dates = np.arange(points_converted[0], np.datetime64("today") + day, day)

    raw_data = np.empty(len(dates))

    for index, date in enumerate(dates):
        if date in points_converted:
            raw_data[index] = points_converted.count(date)

    data = np.cumsum(raw_data)

    ax.plot(dates, data)

    ax.set_yticks(np.linspace(1, len(POINTS), NUM_TICKS, dtype=np.int32))

    ax.xaxis.set_major_formatter(ConciseDateFormatter(ax.xaxis.get_major_locator()))

    plt.savefig(SAVE_TO)


if __name__ == "__main__":
    main()
