ตารางเวลาคำนวณได้ + หน้ารายละเอียดป้ายขับเคลื่อนด้วยข้อมูล + แผนที่ Leaflet
Schedules — กติกา "จุดนี้ = เวลาจุดอ้างอิง ± n นาที"
- ฟิลด์ derive { from_station_id, offset_min } คำนวณที่ ui/partials/schedules.js (ท่อเดียว) รองรับอ้างจุดข้ามทิศ
- จุดย่อยของ "8 other_stop" ใช้ offsets_min จับคู่ตามลำดับ (เช่น ตลาดสามโก้ = ตลาดท่าช้าง +45 นาที)
- เครื่องมือ resource/tools/derive-times.py + ตาราง resource/data/derive-times.csv (--check / --audit ชี้จุดที่ควรตั้งกฎ)
- แยกตารางเป็นรายสาย: scheduleslist/schedules<route_id>.json และ schedules.json เป็นสารบัญ (โหลดแบบ lazy + cache)
- ตรวจจับวันทำงาน/วันหยุด + schema 3 (weekday/holiday → directions) · ไฟล์ข้อมูลเป็น CRLF ทั้งชุด
- ล้างค่าที่ไม่ใช่ HH:MM ที่ฝังใน times (ทำให้ KPI เพี้ยน) + กันค่าหลอกในตัวสรุปเวลา
UI
- หน้ารายละเอียดป้าย/ตารางเวลา ขับเคลื่อนด้วย JSON (stopDetail.init.js) · จุดขึ้นรถประจำทางอื่นๆ รองรับหลายจุดต่อสาย
- #/stops: แสดง 6 ป้ายแรก + ปุ่ม "แสดงป้ายทั้งหมด" (โหลดรูปเฉพาะที่แสดง) · ชิปสาย → #/routes/<route_id>
- หน้าแรก: ตัดตัวเลือก "ทุกสถานีในจังหวัดนี้" · ตัวกรองจังหวัด/สถานี + ปุ่มแชร์ (share URL)
- การ์ดติดต่อ: ไอคอน/ชื่อ/สีเปลี่ยนตามชนิด URL (Facebook / LINE / เว็บไซต์) + ปุ่มเปิดลิงก์จาก web_url
- รูปรองรับหลายนามสกุล (.jpg → .jpeg → .webp → .png) · ป้าย "ประมาณ" + หมายเหตุสำหรับตารางที่คำนวณ
- หน้าเครดิตเหลือ 3 หมวด · แก้ข้อความหมวดแผนที่ให้ตรงกับข้อมูลจริง
- แผนที่ Leaflet (vendor ในโปรเจกต์ ไม่ใช้ CDN): เส้นทาง + หมุด + ป๊อปอัป · แก้ CSS ที่ทำให้ SVG ยุบ 0x0
เครื่องมือและเอกสาร
- qgis-to-web.py อ่าน .shp ตรง → geojson-web (สร้างใหม่ 10 ไฟล์) + audit-geojson.py ตรวจ 3 ส่วน
- stop-km.py วัดระยะ กม. ตามเส้นจริง → stop-km.json · schedules-editor.html (แก้ทีละไฟล์ · มุมมองตารางแบบ Excel)
- AGENTS.md: กติกา derive · offsets_min · นามสกุลรูป · ชิปสาย · หน้ารายละเอียดป้ายมาจากไหน
This commit is contained in:
1 parent
88311326e6
commit
1cfaeb1526
91 files changed
+7560
-844
No files matched your search
@@ -0,0 +1,85 @@
|
||||
#!/usr/bin/env python3
|
||||
# -*- coding: utf-8 -*-
|
||||
"""แตก resource/data/schedules.json → resource/data/scheduleslist/schedules<route_id>.json (1 ไฟล์ = 1 เส้นทาง)
|
||||
และเขียน schedules.json ให้เป็น "สารบัญ" (index) ชี้ไปไฟล์ย่อย
|
||||
|
||||
ทำไม: ไฟล์เดียวรวม 14 สายอ่านยาก/แก้ยาก และเวลาแก้ทีละสายต้องเปิดทั้งไฟล์ → แยกเป็นไฟล์ต่อสาย
|
||||
|
||||
รูปแบบไฟล์:
|
||||
scheduleslist/schedules101.json = { "schema": 2, "route_id": "101", "generated_from": "schedules.json",
|
||||
"station_order": [...], "directions": [ ... ] } (เนื้อในเหมือนเดิมเป๊ะ)
|
||||
schedules.json (สารบัญ) = { "schema": 2, "index": true, "dir": "scheduleslist/",
|
||||
"routes": [ { "route_id": "101", "file": "schedules101.json", ... } ] }
|
||||
|
||||
รัน: python resource/tools/split-schedules.py # เขียนไฟล์จริง
|
||||
python resource/tools/split-schedules.py --check # ดูผลก่อน ไม่เขียน
|
||||
หมายเหตุ: ถ้า schedules.json เป็นสารบัญอยู่แล้ว คำสั่งนี้จะไม่ทำอะไร (กันเขียนทับไฟล์ย่อย) — ใช้ merge-schedules.py ย้อนกลับ
|
||||
"""
|
||||
import argparse
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
DATA = ROOT / "resource" / "data"
|
||||
LIST_DIR = DATA / "scheduleslist"
|
||||
|
||||
|
||||
def jdump(obj):
|
||||
return json.dumps(obj, ensure_ascii=False, indent=2).replace("\n", "\r\n") + "\r\n"
|
||||
|
||||
|
||||
def main():
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("--check", action="store_true")
|
||||
args = ap.parse_args()
|
||||
|
||||
src = DATA / "schedules.json"
|
||||
if not src.exists():
|
||||
print("ไม่พบ schedules.json"); return 1
|
||||
doc = json.loads(src.read_text(encoding="utf-8"))
|
||||
if doc.get("index") or "directions" not in json.dumps(doc)[:200]:
|
||||
if doc.get("index"):
|
||||
print("schedules.json เป็นสารบัญอยู่แล้ว — ไม่ต้องแตกไฟล์ซ้ำ")
|
||||
print("(ถ้าต้องการย้อนกลับเป็นไฟล์เดียว ใช้ resource/tools/merge-schedules.py)")
|
||||
return 0
|
||||
routes = doc.get("routes") or []
|
||||
if not routes:
|
||||
print("ไม่พบ routes[] ในไฟล์"); return 1
|
||||
|
||||
LIST_DIR.mkdir(exist_ok=True)
|
||||
index_rows = []
|
||||
for r in routes:
|
||||
rid = str(r["route_id"])
|
||||
sub = {
|
||||
"schema": doc.get("schema", 2),
|
||||
"route_id": r["route_id"],
|
||||
"generated_from": "schedules.json",
|
||||
"station_order": r.get("station_order", []),
|
||||
"directions": r.get("directions", []),
|
||||
}
|
||||
fname = "schedules" + rid + ".json"
|
||||
if not args.check:
|
||||
(LIST_DIR / fname).write_text(jdump(sub), encoding="utf-8", newline="")
|
||||
counts = {"n_directions": len(sub["directions"]),
|
||||
"n_stops": sum(len(d.get("stops") or []) for d in sub["directions"]),
|
||||
"n_trips": sum(len(s.get("times") or []) for d in sub["directions"] for s in (d.get("stops") or []))}
|
||||
index_rows.append({"route_id": r["route_id"], "file": fname, **counts})
|
||||
|
||||
index = {
|
||||
"schema": doc.get("schema", 2),
|
||||
"index": True,
|
||||
"note": "สารบัญชี้ไป scheduleslist/schedules<route_id>.json (1 ไฟล์ = 1 เส้นทาง) — แก้ไฟล์ย่อยนั้นโดยตรง หรือใช้ resource/data/schedules-editor.html",
|
||||
"dir": "scheduleslist/",
|
||||
"routes": index_rows,
|
||||
}
|
||||
if not args.check:
|
||||
src.write_text(jdump(index), encoding="utf-8", newline="")
|
||||
print(("ตรวจเท่านั้น: " if args.check else "เขียนแล้ว: ") + f"{len(index_rows)} ไฟล์ใน scheduleslist/ + สารบัญ schedules.json")
|
||||
for row in index_rows:
|
||||
print(f" {row['file']:<26} ทิศ {row['n_directions']:>2} · จุด {row['n_stops']:>2} · เที่ยว {row['n_trips']:>3}")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in new issue
Block a user