跳到正文
DEV Community· Waxime Studio·· 1 小時前AI 評分21

StillDeep Transport 示範項目如何在售票前選擇鐵路轉乘方案

How I choose a rail connection before selling the ticket

AI 導讀

StillDeep Transport 示範項目按各路段參考票價總和選擇鐵路路線;票價相同時,依次以較少路段及較短距離作取捨。系統另會核實班次能否接駁,並在售票畫面標示轉車站,將兩段行程放入同一購物車。

正文

Waxime Studio

A direct train makes the ticket screen easy. Pick a departure, choose a fare, and add a seat if the train has assigned seating. When I built the StillDeep Transport demo, I wanted the same screen to handle a trip that crosses two lines. The first thing I had to decide was what “best route” should mean at a ticket desk.

Choosing where to change trains

Several lines in the demo meet at more than one station. Before I look at individual departures, I compare possible routes by adding the reference fares of their legs. When those totals tie, the engine prefers fewer legs. If there’s still a tie, it prefers the shorter distance.

That order matters. A short route on the map can still be a more expensive trip. And two routes with the same fare can ask very different things of a passenger carrying luggage. Using leg count to break the tie makes the choice predictable at the counter.

Turning the route into a trip someone can buy

Once I have the route, I need departures that actually connect. Think of a first train that arrives at 13:20 and a second that leaves at 13:10. Both trains serve the right stations, but the passenger can’t make that trip. Finding the transfer station and finding a usable pair of trains are separate checks.

I wanted the result to be easy to verify at the counter. The screen shows where the passenger changes trains and puts both legs in the same cart. The screenshot shows a trip from the North Station to Mont-aux-Bleuets with a change at Central Station.

StillDeep Transport ticket desk showing two trains in one cart and a transfer at Central Station

If you’re building an interface for a similar system, try the same origin and destination against departures that leave before and after the arrival of the first train. The map can look identical in both cases. The ticket screen should only offer the connection the passenger can catch.

See the transfer screen and the rest of the StillDeep Transport demo write-up.

Adapted from my original development notes and screenshots with AI assistance.

來源:DEV Community · dev.to