Skip to content
Snippets Groups Projects
Commit e4562acd authored by Niklas Schrötler's avatar Niklas Schrötler
Browse files

FahrplanPanel: Implemented grouping stops of the same tour

Also cleaned up superfluous code
parent 821183f4
No related branches found
No related tags found
No related merge requests found
...@@ -21,8 +21,10 @@ type Route = { ...@@ -21,8 +21,10 @@ type Route = {
stops: { stops: {
name: string, name: string,
arrival: Date, arrival: Date,
delay?: number delay?: number,
}[] countdown: number
}[],
countdown: number
} }
const FahrplanPanel = (props: {definition: FahrplanPanelDefinition}) => { const FahrplanPanel = (props: {definition: FahrplanPanelDefinition}) => {
...@@ -44,12 +46,11 @@ const FahrplanPanel = (props: {definition: FahrplanPanelDefinition}) => { ...@@ -44,12 +46,11 @@ const FahrplanPanel = (props: {definition: FahrplanPanelDefinition}) => {
} }
// Find existing route with same uid // Find existing route with same uid
const existing_ind = newRoutes.findIndex(r => r.uid === departure.lineref.identifier) const existing_ind = newRoutes.findIndex(r => r.uid === departure.key)
// Pre-compute values that will be needed regardless // Pre-compute values that will be needed regardless
const delay = stringToDelay(departure.delay); const delay = stringToDelay(departure.delay);
const arrival = processArrival(departure.sched_date, departure.time); const arrival = processArrival(departure.sched_date, departure.time);
console.log(arrival)
if(existing_ind === -1) { if(existing_ind === -1) {
// If it does not exist, create a new route // If it does not exist, create a new route
...@@ -61,21 +62,27 @@ const FahrplanPanel = (props: {definition: FahrplanPanelDefinition}) => { ...@@ -61,21 +62,27 @@ const FahrplanPanel = (props: {definition: FahrplanPanelDefinition}) => {
{ {
name: departure.internal.stop, name: departure.internal.stop,
arrival, arrival,
delay delay,
countdown: parseInt(departure.countdown)
} }
] ],
countdown: parseInt(departure.countdown)
}) })
} else { } else {
// If it doesn't, just add a stop to the existing route // If it doesn't, just add a stop to the existing route
newRoutes[existing_ind].stops.push({ newRoutes[existing_ind].stops.push({
name: departure.internal.stop, name: departure.internal.stop,
arrival, arrival,
delay: stringToDelay(departure.delay) delay: stringToDelay(departure.delay),
countdown: parseInt(departure.countdown)
}) })
newRoutes[existing_ind].stops = newRoutes[existing_ind].stops.sort((a, b) => a.countdown - b.countdown)
} }
} }
// Sort the output // Sort the output
newRoutes = newRoutes.sort((a, b) => a.countdown - b.countdown)
// Write to the display // Write to the display
setRoutes(newRoutes); setRoutes(newRoutes);
...@@ -150,42 +157,18 @@ async function getStopData(stop: string): Promise<StationResponse> { ...@@ -150,42 +157,18 @@ async function getStopData(stop: string): Promise<StationResponse> {
} }
function stringToDelay(input: string): number | undefined { function stringToDelay(input: string): number | undefined {
try { const delay = parseInt(input);
const delay = parseInt(input); if(delay === 0) {
if(delay === 0) { return undefined;
return undefined; }
} if(delay === Number.NaN) {
return delay; console.warn("While parsing delay, the string was not interpretable as number", input);
} catch (e) {
console.warn("While parsing delay, the string was not interpretable", input);
return undefined; return undefined;
} }
return delay;
} }
function processArrival(date: string, time: string): Date { function processArrival(date: string, time: string): Date {
const d_parts = date.split("."); const d_parts = date.split(".");
console.log(date, time, "to", `${d_parts[2]}-${d_parts[1]}-${d_parts[0]} ${time}`);
return new Date(`${d_parts[2]}-${d_parts[1]}-${d_parts[0]} ${time}`); return new Date(`${d_parts[2]}-${d_parts[1]}-${d_parts[0]} ${time}`);
} }
// function sortData(data: any) {
// for (var i = 0; i < data.length; ++i) {
// data[i]['stops'] = data[i]['stops'].sort(sortFn);
// data[i]['timeValue'] = data[i]['stops'][0]['timeValue'];
// }
// return data.sort(sortFn);
// }
//
// function sortFn(a: any, b: any) {
// return a['timeValue'] - b['timeValue'];
// }
//
// function calcDateValue(_year: string, _month: string, _day: string, _hour: string, _minute: string): number {
// const year = parseInt(_year) * 12 * 31 * 24 * 60;
// const month = parseInt(_month) * 31 * 24 * 60;
// const day = parseInt(_day) * 24 * 60;
// const hour = parseInt(_hour) * 60;
// const minute = parseInt(_minute);
// return year+month+day+hour+minute;
// }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment