|
|
@@ -645,29 +645,19 @@ export async function apiGetKeyIntersections() {
|
|
|
|
|
|
export async function apiGetTrafficTimeSpace(opts = {}) {
|
|
|
await delay(300)
|
|
|
- const { speed = 15, cycle = 120, band = 40, totalTime = 1800 } = opts
|
|
|
- const intersections = opts.intersections || DB.timeSpaceData.intersections
|
|
|
- const rawDistances = opts.distances || DB.timeSpaceData.distances
|
|
|
- // 将不均匀的物理距离归一化为等间距,保证绿波带视觉对齐
|
|
|
- const step = 500
|
|
|
- const distances = rawDistances.map((_, i) => i * step)
|
|
|
- const maxDist = distances[distances.length - 1]
|
|
|
- const waveData = [], greenData = []
|
|
|
-
|
|
|
- for (let t = 0; t <= totalTime; t += cycle) {
|
|
|
- const upKmh = 45 + Math.random() * 10 // 45-55 km/h 随机
|
|
|
- const downKmh = 45 + Math.random() * 10
|
|
|
- const upSpd = upKmh / 3.6 // 转 m/s
|
|
|
- const downSpd = downKmh / 3.6
|
|
|
- const ds = t + cycle / 2
|
|
|
- waveData.push({ yBottom: 0, yTop: maxDist, xBL: t, xBR: t + band, xTL: t + maxDist / upSpd, xTR: t + maxDist / upSpd + band, label: Math.round(upKmh) + 'km/h', direction: 'up', speed: Math.round(upKmh) })
|
|
|
- waveData.push({ yBottom: maxDist, yTop: 0, xBL: ds, xBR: ds + band, xTL: ds + maxDist / downSpd, xTR: ds + maxDist / downSpd + band, label: Math.round(downKmh) + 'km/h', direction: 'down', speed: Math.round(downKmh) })
|
|
|
- distances.forEach(y => {
|
|
|
- greenData.push({ y, start: t + y / upSpd, end: t + y / upSpd + band })
|
|
|
- greenData.push({ y, start: ds + (maxDist - y) / downSpd, end: ds + (maxDist - y) / downSpd + band })
|
|
|
- })
|
|
|
- }
|
|
|
- return ok({ intersections, distances, waveData, greenData })
|
|
|
+ return ok({
|
|
|
+ roadSegments: [
|
|
|
+ { name: '交叉口A', distanceNext: 450, offset: 0 },
|
|
|
+ { name: '交叉口B', distanceNext: 669, offset: 50 },
|
|
|
+ { name: '交叉口C', distanceNext: 1050, offset: 0 },
|
|
|
+ { name: '交叉口D', distanceNext: 0, offset: 0 }
|
|
|
+ ],
|
|
|
+ speedKmh: 38.9,
|
|
|
+ cycle: 100,
|
|
|
+ greenDuration: 40,
|
|
|
+ bandwidth: 31.5,
|
|
|
+ scanLineStart: Math.round(Math.random() * 100) / 100
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
// ═══════════════════════════════════════════════════════════════════════
|