ตารางเวลาคำนวณได้ + หน้ารายละเอียดป้ายขับเคลื่อนด้วยข้อมูล + แผนที่ 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:
Bkk1234 committed 2026-09-30 03:25:18 +07:00
1 parent 88311326e6
commit 1cfaeb1526
91 files changed
+7560 -844

No files matched your search

+55 -8
View File
@@ -94,11 +94,16 @@
body.appendChild(none);
}
/* มีอย่างน้อย 1 ทิศที่มีตารางจริงไหม — ถ้ามี ห้ามขึ้น "ยังไม่มีข้อมูล" ของทิศที่ว่าง
(จุดเดียวมีได้หลายทิศ · ทิศว่างไม่ควรทำให้การ์ดที่ตารางขึ้นแล้วดูเหมือนไม่มีข้อมูล) */
var hasAny = g.recs.some(function (x) { return (x.departure_times || []).length > 0; });
g.recs.forEach(function (r) {
var times = (r.departure_times || []).slice();
/* ไม่มีเวลาเลย (เช่น สาย 999: departure_times = []) → บอกว่าไม่มีข้อมูล ไม่ต้องมีบรรทัดลอย */
/* ทิศนี้ยังไม่มีเวลา → ข้ามไปเลยถ้าทิศอื่นมีการ์ดข้อมูลอยู่แล้ว */
if (!times.length) {
if (hasAny) return;
var empty = document.createElement('p');
empty.className = 'mu-stop-sub';
empty.textContent = t('route.empty');
@@ -106,15 +111,22 @@
return;
}
/* หัวแถว = ชื่อทิศ (dir_label) → ไม่มีค่อยใช้ dir_note → ไม่มีอีกค่อยบอกว่าอยู่ที่จุดนี้
ทิศที่ไปคนละทางจากจุดเดียวกัน (ป่าโมกไปอ่างทอง / ป่าโมกไปอยุธยา) จึงแยกให้เห็นชัด */
var sub = document.createElement('p');
sub.className = 'mu-stop-sub';
sub.innerHTML = r.direction_note
? esc(r.direction_note) + ' <span class="mu-direction-tag">' + esc(t('check.direction')) + '</span>'
: esc(t('check.atStop')) + ' ' + esc(g.name);
if (r.dir_label) {
sub.innerHTML = esc(r.dir_label) +
(r.direction_note ? ' <span class="mu-direction-tag">' + esc(r.direction_note) + '</span>' : '');
} else if (r.direction_note) {
sub.innerHTML = esc(r.direction_note) + ' <span class="mu-direction-tag">' + esc(t('check.direction')) + '</span>';
} else {
sub.textContent = t('check.atStop') + ' ' + g.name;
}
body.appendChild(sub);
var grid = document.createElement('div');
grid.className = 'mu-time-grid';
grid.className = 'mu-time-grid' + (r.estimated ? ' is-est' : ''); /* เวลาที่คำนวณจากต้นทาง */
var chips = [];
times.forEach(function (tm) {
var c = document.createElement('div');
@@ -124,6 +136,18 @@
chips.push(c);
});
body.appendChild(grid);
if (r.estimated) {
var est = document.createElement('p');
est.className = 'mu-est-note';
/* มาจากกฎ "จุดนี้ = เวลาจุดอ้างอิง ± n นาที" → บอกจุดอ้างอิง + เตือนเรื่องการจราจร */
est.textContent = r.estimateFrom && window.Schedules.offsetLabel
? t('time.derived', {
base: r.estimateFrom.name || ('#' + r.estimateFrom.station_id),
n: Schedules.offsetLabel(r.estimateFrom.offsetMin)
})
: t('time.estimated');
body.appendChild(est);
}
sections.push({ chips: chips, times: times, station: g.name });
if (r.schedule_note) {
@@ -188,11 +212,12 @@
Promise.all([
fetchJSON(DATA + 'routes.json'),
fetchJSON(DATA + 'stations.json'),
fetchJSON(DATA + 'schedules.json')
Schedules.load().then(function (sd) { return Schedules.normSub(sd); })
]).then(function (res) {
var routes = (res[0] || {}).routes || [];
var sts = (res[1] || {}).stations || [];
var recs = (res[2] || {}).schedules || res[2] || [];
if (window.Schedules && Schedules.setStationNames) Schedules.setStationNames(sts); /* ให้ข้อความ "คำนวณจาก ..." มีชื่อจุด */
var recs = window.Schedules ? Schedules.records(res[2]) : ((res[2] || {}).schedules || res[2] || []);
if (!routes.length) return;
var route = routes.filter(function (r) { return String(r.route_id) === want; })[0] ||
@@ -225,6 +250,9 @@
/* จัดกลุ่มตามลำดับจุดจอดของสาย แล้วต่อด้วยจุดที่เหลือ (ถ้ามีข้อมูล) */
var order = (route.station_ids || []).slice();
/* schema 2: ใช้ station_order ที่ตรวจทิศทางมาแล้วจากไฟล์ (ถ้ามี) */
var sched = window.Schedules ? Schedules.route(res[2], rid) : null;
if (sched && sched.station_order.length) order = sched.station_order.slice();
recs.forEach(function (r) {
if (String(r.route_id) === rid && order.indexOf(r.station_id) === -1) order.push(r.station_id);
});
@@ -249,9 +277,28 @@
var desc = $('check-zone-desc');
if (desc) {
var names = groups.map(function (g) { return g.name; });
/* บอกว่า "ตารางวันนี้" เป็นของวันไหน — เฉพาะสายที่มีการแยกตารางตามวัน (service) เท่านั้น
สายอื่นข้อความเหมือนเดิมทุกตัวอักษร */
/* ป้ายบอกว่า "ตารางที่เห็นอยู่นี้เป็นของวันไหน" — ใช้ผลตรวจวันจากตัวอ่านกลาง (ไม่คำนวณเองในหน้านี้) */
var dayLine = '';
if (window.Schedules && Schedules.dayInfo && Schedules.directions) {
var di = Schedules.dayInfo();
var infos = (Schedules.directions(res[2], rid) || []).map(function (d) { return d.service || { from: 'ไม่ระบุ' }; });
var conflict = infos.some(function (x) { return x.conflict; }); /* ทิศเดียวมีทั้งวันทำงาน+วันหยุด */
var unknown = infos.some(function (x) { return x.unknown; }); /* ยังไม่ระบุวันเลย */
var selectedByDay = infos.some(function (x) { return x.from === 'service' || x.from === 'ระบุตรง' || x.from === 'คำในโน้ต'; });
if (unknown) {
dayLine = ' · ' + t('check.dayUnknown');
} else if (conflict) {
dayLine = ' · ' + t('check.dayMixed');
} else if (selectedByDay) {
dayLine = ' · ' + t(di.dayType === 'holiday' ? 'check.dayHoliday' : 'check.dayWeekday') +
' (' + t('check.dayOfWeek') + ' ' + di.weekday_th + ')';
}
}
desc.textContent = 'สาย ' + rid + ' · ' +
(names.length > 1 ? names[0] + ' \u2192 ' + names[names.length - 1] + ' · ' : '') +
groups.length + ' ' + t('check.stopsCount');
groups.length + ' ' + t('check.stopsCount') + dayLine;
}
/* KPI */