I have a task at hand in which I have to lay down a rail time table, Now the rail track is straight and I have implemented a Doubly Linked List for the representation of a train terminal, a terminal behind this and a terminal ahead this are represented by the links in the list.
Now I want to implement a train over the tracks laid so far, I am not intrested in implementing a database and all my raw data is in the form of JSON. An example of one terminal in JSON looks like:
{
"stations_array": [{
"vertexId": 0,
"name": "Terminal0",
"lat": "84.2207",
"lng": "74.3884",
"isEndTerminal": true,
"isFunctional": true,
"vertNext": 1,
"vertPrev": null
},
{
"vertexId": 1,
"name": "Terminal1",
"lat": "104.2580",
"lng": "94.4512",
"isEndTerminal": false,
"isFunctional": true,
"vertNext": 2,
"vertPrev": 1
},
{
"vertexId": 2,
"name": "Terminal2",
"lat": "14.1659",
"lng": "04.5632",
"isEndTerminal": false,
"isFunctional": true,
"vertNext": 3,
"vertPrev": 1
}
]
}
And I represent a train in JSON as well, which is as below:
{
"trains_array": [{
"id": 16,
"source": "Terminal0",
"destination": "Terminal2",
"start_time": "06:00",
"days": "daily",
"terminals": [{
"id": 0,
"name": "Terminal0",
"time": "06:00"
},
{
"id": 1,
"name": "terminal1",
"time": "06:12"
},
{
"id": 2,
"name": "Terminal2",
"time": "06:25"
}
]
}]
}
Now the terminals array in the above JSON tells me where the train stops (id being the representation of a foreign key inside the terminal array for each object) and I calculate through code to know which train arrives at what time at which station, which station it stops or omits at. however this whole approach seems a bit hardcoded. I want to know if there is a better way I can represent things here.