aboutsummaryrefslogtreecommitdiffhomepage
path: root/scripts/gen-sanpi-table.py
blob: 4cd926db5ccf49a5e24948a53c5a1a5a687a54fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import sys
import json

sys.stdout.reconfigure(encoding="utf-8")

with open(".sanpi-parsed.json", encoding="utf-8") as f:
    data = json.load(f)

members = [(int(c), g, n) for c, g, n in data["members"]]
rows = data["rows"]
for r in rows:
    r["votes"] = {int(k): v for k, v in r["votes"].items()}

# 会派ごとにまとめる(全行で一致していれば1列、分かれていれば議員ごとの列)
groups = {}
for col, g, n in members:
    groups.setdefault(g, []).append((col, n))

cols = []  # (見出し, [(col, name)])
for g, ms in groups.items():
    if len(ms) == 1:
        cols.append((f"{g} {ms[0][1]}", ms))
        continue
    same = True
    for r in rows:
        vals = {r["votes"].get(c) for c, _ in ms}
        vals = {v for v in vals if v in ("〇", "○", "×")}  # 表決に加わらない議員は除外
        if len(vals) > 1:
            same = False
            break
    if same:
        cols.append((g, ms))
    else:
        # 安竹の列は常に表示しつつ、分かれた会派は議員ごとに
        for c, n in ms:
            cols.append((f"{n}({g})", [(c, n)]))

print("| 議案 | 議決結果 | " + " | ".join(h for h, _ in cols) + " |")
print("|---|---|" + "---|" * len(cols))
for r in rows:
    cells = []
    for _, ms in cols:
        vals = [r["votes"].get(c, "") for c, _ in ms]
        real = {v for v in vals if v in ("〇", "○", "×")}
        if len(real) == 1:
            cells.append(next(iter(real)))
        elif not real:
            cells.append("—")
        else:
            cells.append("/".join(v or "—" for v in vals))
    no = r["番号"] or ""
    print(f"| {no} {r['件名'][:40]} | {r['議決結果']} | " + " | ".join(cells) + " |")