-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from minaorangina/android
Android
- Loading branch information
Showing
5 changed files
with
105 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
|
||
function sendBackData (io, { data = [], mode, direction, destination }) { | ||
const origin = direction === 'away' ? process.env.AWAYWARDS_ORIGIN_TRAIN_NAME : process.env.AWAYWARDS_DESTINATION_TRAIN_NAME; | ||
let androidData; | ||
parseTrainData(data) | ||
.then(parsed => { | ||
if (parsed) { | ||
androidData = parsed; | ||
} | ||
io.emit(`${mode}:arrivals`, { androidData, direction, origin, destination, last_updated: new Date().toISOString() }); | ||
}) | ||
.catch(console.error); | ||
} | ||
|
||
function parseTrainData (trainData, mode = 'train') { | ||
return new Promise((resolve) => { | ||
if (trainData.length === 0) { | ||
return resolve(); | ||
} | ||
const mapped = trainData.map(arrival => { | ||
const finalDestination = arrival.destination.location[0].locationName; | ||
return { | ||
std: arrival.std, | ||
etd: arrival.etd, | ||
identifier: `${arrival.std} to ${normaliseStationName(finalDestination, mode)}` | ||
}; | ||
}); | ||
resolve(mapped); | ||
}); | ||
} | ||
function normaliseStationName (stationName, mode) { | ||
if (mode === 'dlr' && stationName.length > 0) { | ||
return stationName.replace(' DLR Station', ''); | ||
} | ||
if (mode === 'train' && stationName !== 'London Bridge') { | ||
return stationName.replace('London ', ''); | ||
} | ||
} | ||
|
||
module.exports = sendBackData; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters