-
-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add csv download link to speed, prediction accuracy, service, ridership #935
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
097de4c
add csv download link to speed, prediction accuracy, service, ridership
4b4defe
make DownloadButton data type agnostic
f9fae7e
create strict typing for csv util
cdwhitt 610501b
Merge branch 'main' into add-csv-download-to-widgets
cdwhitt d99a227
lint fixes
cdwhitt c4e1e19
remove unknown typing for data prop
cdwhitt 21a0204
remove unused data types
cdwhitt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fyi:
unknown
should work here instead ofany
and then the linter won't complain.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah in general we should prefer unknown as it throws more warnings whereas any basically disables checks.
Probably should add some linting for prefer unknown