-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add csv download link to speed, prediction accuracy, service, ridersh…
…ip (#935) * add csv download link to speed, prediction accuracy, service, ridership * make DownloadButton data type agnostic * create strict typing for csv util * lint fixes * remove unknown typing for data prop * remove unused data types --------- Co-authored-by: Casey Whittaker <[email protected]>
- Loading branch information
Showing
18 changed files
with
170 additions
and
78 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
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,61 @@ | ||
import { flatten } from 'lodash'; | ||
import type { Location } from '../types/charts'; | ||
import type { DeliveredTripMetrics, TimePredictionWeek } from '../types/dataPoints'; | ||
|
||
const directionAbbrs = { | ||
northbound: 'NB', | ||
southbound: 'SB', | ||
eastbound: 'EB', | ||
westbound: 'WB', | ||
inbound: 'IB', | ||
outbound: 'OB', | ||
}; | ||
|
||
type GetCsvFilenameOptions = { | ||
datasetName: string; | ||
startDate: string; | ||
endDate?: string; | ||
line?: string; | ||
location?: Location; | ||
includeBothStopsForLocation?: boolean | undefined; | ||
}; | ||
|
||
export function getCsvFilename(options: GetCsvFilenameOptions) { | ||
const { datasetName, startDate, endDate, line, location, includeBothStopsForLocation } = options; | ||
// CharlesMGH-SB_dwells_20210315.csv | ||
// CentralSquareCambridge-MelneaCassWashington_traveltimesByHour-weekday_20200101-20201231.csv | ||
// BostonUniversityWest-EB_headways_20161226-20170328.csv | ||
const fromStop = location?.from.replace(/[^A-z]/g, ''); | ||
const toStop = location?.to.replace(/[^A-z]/g, ''); | ||
const dir = location && directionAbbrs[location.direction]; | ||
|
||
//Location does not exist on all widgets - in that case, 'where' will just be the name of the line | ||
const where = location ? `${fromStop}-${includeBothStopsForLocation ? toStop : dir}` : line; | ||
const what = datasetName; | ||
const date1 = startDate.replaceAll('-', ''); | ||
const date2 = endDate ? `-${endDate.replaceAll('-', '')}` : ''; | ||
const when = `${date1}${date2}`; | ||
|
||
return `${where}_${what}_${when}.csv`; | ||
} | ||
|
||
export const addAccuracyPercentageToData = (data: TimePredictionWeek[]) => { | ||
const predictionsList = flatten(data.map(({ prediction }) => prediction)); | ||
|
||
const newData = predictionsList.map((item) => { | ||
const accuracyPercentage = (item?.num_accurate_predictions / item?.num_predictions) * 100; | ||
return { ...item, accuracy_percentage: accuracyPercentage.toFixed(1) }; | ||
}); | ||
|
||
return newData; | ||
}; | ||
|
||
export const addMPHToSpeedData = (data: DeliveredTripMetrics[]) => { | ||
const newData = data.map((item) => { | ||
const hours = item.total_time / 3600; | ||
const mph = item.miles_covered / hours; | ||
return { ...item, miles_per_hour: mph.toFixed(1) }; | ||
}); | ||
|
||
return newData; | ||
}; |
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
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
Oops, something went wrong.