56 lines
2 KiB
Python
56 lines
2 KiB
Python
"""Lignes de données factices pour construire les diagrammes sans base."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from datetime import date, timedelta
|
|
|
|
from shortstats.web import chart_catalog, chart_config, charts
|
|
from shortstats.web.chart_catalog import FIELDS
|
|
|
|
A, B, C = "UC" + "a" * 22, "UC" + "b" * 22, "UC" + "c" * 22
|
|
|
|
ALL_X = [k for k in FIELDS if k != "theme"]
|
|
|
|
ALL_Y = ALL_X + ["count"]
|
|
|
|
|
|
def fake_rows(cfg: chart_config.ChartConfig, n: int = 40) -> list[tuple]:
|
|
"""Lignes plausibles pour n'importe quelle combinaison de données."""
|
|
def value(key, i):
|
|
kind = chart_catalog.field(key).kind
|
|
if key == "count":
|
|
return 1
|
|
if key == "title":
|
|
return f"Short n°{i}"
|
|
if key == "channel":
|
|
return ["Chaîne principale", "Chaîne secondaire"][i % 2]
|
|
if key == "theme":
|
|
return ["Apothecary Diaries", "applepie", "Frieren"][i % 3]
|
|
if key == "weekday":
|
|
return chart_catalog.WEEKDAYS[i % 7]
|
|
if key == "publish_hour":
|
|
return (i * 5) % 24
|
|
if kind == "T":
|
|
return date(2026, 6, 1) + timedelta(days=i * 3)
|
|
return (i + 1) * 137 if key != "like_rate" else 1.5 + i / 10
|
|
rows = []
|
|
for i in range(n):
|
|
row = [f"vid{i:08d}", f"Short n°{i}", value(cfg.x, i), value(cfg.y, i)]
|
|
if cfg.color:
|
|
row.append(value(cfg.color, i))
|
|
rows.append(tuple(row))
|
|
return rows
|
|
|
|
|
|
def multi_rows(cfg, n=30, names=("Chaîne A", "Chaîne B")):
|
|
base = fake_rows(chart_config.ChartConfig(x=cfg.x, y="views"), n)
|
|
out = []
|
|
for i, r in enumerate(base):
|
|
extras = tuple(None if (i + j) % 7 == 0 else (r[3] or 1) * (j + 2) for j in range(len(cfg.y_more)))
|
|
out.append((r[0], r[1], r[2], r[3], names[i % len(names)], *extras))
|
|
return out
|
|
|
|
|
|
def _scatter():
|
|
cfg = chart_config.validate_config({"x": "views", "y": "likes", "type": "scatter", "split_channels": False})
|
|
return charts.build(cfg, fake_rows(cfg))
|