-
Notifications
You must be signed in to change notification settings - Fork 2
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
Full data dump export #312
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import { App, s3PutJsonHelper } from '../app'; | ||
import { LowPopulationPostalCodes, PostalCodeCityMappings } from '../../common/model'; | ||
|
||
export async function exportResponses(app: App) { | ||
const responses = await fetchResponses(app); | ||
|
||
await pushResponses(app, responses); | ||
} | ||
|
||
export async function fetchResponses(app: App) { | ||
const responsesResult = await queryResponses(app); | ||
|
||
const postalCodeCityMappings = await app.s3Sources.fetchPostalCodeCityMappings(); | ||
const lowPopulationPostalCodes = await app.s3Sources.fetchLowPopulationPostalCodes(); | ||
|
||
const responses = mapResponses(responsesResult.Items, postalCodeCityMappings, lowPopulationPostalCodes); | ||
|
||
return responses; | ||
} | ||
|
||
interface ResponsesQuery { | ||
response_id: string; | ||
timestamp: string; | ||
participant_id: string; | ||
app_version: string; | ||
country_code: string; | ||
fever: string; | ||
cough: string; | ||
breathing_difficulties: string; | ||
muscle_pain: string; | ||
headache: string; | ||
sore_throat: string; | ||
rhinitis: string; | ||
stomach_issues: string; | ||
sensory_issues: string; | ||
healthcare_contact: string; | ||
general_wellbeing: string; | ||
longterm_medication: string; | ||
smoking: string; | ||
corona_suspicion: string; | ||
age_group: string; | ||
gender: string; | ||
postal_code: string; | ||
duration: string; | ||
abuse_score: string; | ||
} | ||
|
||
export const responsesQuery = ` | ||
SELECT * | ||
FROM | ||
responses | ||
WHERE | ||
country_code = 'FI' | ||
OR | ||
country_code = '' | ||
ORDER BY timestamp ASC | ||
`; | ||
|
||
export async function queryResponses(app: App) { | ||
return app.athenaClient.query<ResponsesQuery>({ | ||
sql: responsesQuery, | ||
db: app.constants.athenaDb, | ||
}); | ||
} | ||
|
||
export function mapResponses( | ||
responses: ResponsesQuery[], | ||
postalCodeCityMappings: PostalCodeCityMappings, | ||
lowPopulationPostalCodes: LowPopulationPostalCodes, | ||
) { | ||
// TODO: Map and filter the responses | ||
const outputs = []; | ||
|
||
for (const response of responses) { | ||
// Normalize postal code | ||
const postal_code = lowPopulationPostalCodes.data[response.postal_code] || response.postal_code; | ||
|
||
// Filter by valid postal areas | ||
// TODO: Use the new `postalcode_areas.json | ||
if (postal_code in postalCodeCityMappings.data) { | ||
// Filter keys | ||
const { response_id, app_version, abuse_score, ...output } = response; | ||
|
||
outputs.push({ | ||
...output, | ||
postal_code, | ||
// Timestamps to be shown to the hour | ||
timestamp: `${response.timestamp.slice(0, 13)}:00:00.000Z`, | ||
// Two age groups, _under 50_ and _over 50_ | ||
age_group: Number(response.age_group) < 50 ? 'under50' : 'over50', | ||
// Two genders, male and female. Other genders coalesce to male | ||
gender: response.gender === 'female' ? 'female' : 'male', | ||
duration: Number(response.duration) || 0, | ||
}); | ||
} | ||
} | ||
|
||
return outputs; | ||
} | ||
|
||
type Responses = ReturnType<typeof mapResponses>; | ||
|
||
export async function pushResponses(app: App, responses: Responses) { | ||
await s3PutJsonHelper(app.s3Client, { | ||
Bucket: app.constants.openDataBucket, | ||
// TODO: | ||
Key: app.constants.responsesFullKey, | ||
Body: { | ||
meta: { | ||
description: 'TODO', | ||
generated: new Date().toISOString(), | ||
link: `https://${app.constants.domainName}/${app.constants.responsesFullKey}`, | ||
}, | ||
data: responses, | ||
}, | ||
}); | ||
} |
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.
I guess there is already a discussion for this decision that I was not aware of, but out of curiosity, why not keep
other
gender asother
?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.
I'm not aware of any discussion on this (which doesn't mean that such doesn't exist), but I'll just refer you the issue this PR is implementing: #231
Translated:
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.
Ohhh :( Looks like that is something defined by tietosuoja requirements.