-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(enrollment): generate event fixtures
from metabase export
- Loading branch information
1 parent
15c4a9e
commit 110305f
Showing
1 changed file
with
132 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import json\n", | ||
"\n", | ||
"def enrollmentevent_fixture(\n", | ||
" transit_agency: int,\n", | ||
" enrollment_flow: int,\n", | ||
" verified_by: str,\n", | ||
" enrollment_datetime: str,\n", | ||
" expiration_datetime: str = None\n", | ||
"):\n", | ||
" return {\n", | ||
" \"model\": \"core.enrollmentevent\",\n", | ||
" \"fields\": {\n", | ||
" \"transit_agency\": transit_agency,\n", | ||
" \"enrollment_flow\": enrollment_flow,\n", | ||
" \"enrollment_method\": \"digital\",\n", | ||
" \"verified_by\": verified_by,\n", | ||
" \"enrollment_datetime\": enrollment_datetime,\n", | ||
" \"expiration_datetime\": expiration_datetime\n", | ||
" }\n", | ||
" }" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"AGENCIES = {\n", | ||
" \"Monterey-Salinas Transit\": {\n", | ||
" \"id\": 1,\n", | ||
" \"flows\": {\n", | ||
" \"senior\": 1,\n", | ||
" \"veteran\": 2,\n", | ||
" \"courtesy_card\": 3,\n", | ||
" }\n", | ||
" },\n", | ||
" \"Sacramento Regional Transit\": {\n", | ||
" \"id\": 2,\n", | ||
" \"flows\": {\n", | ||
" \"senior\": 4,\n", | ||
" \"veteran\": 7\n", | ||
" }\n", | ||
" },\n", | ||
" \"Santa Barbara MTD\": {\n", | ||
" \"id\": 3,\n", | ||
" \"flows\": {\n", | ||
" \"senior\": 5,\n", | ||
" \"mobility_pass\": 6\n", | ||
" }\n", | ||
" },\n", | ||
"}" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"enrollments = []\n", | ||
"\n", | ||
"with open(\"metabase-enrollments.json\", \"r\") as e:\n", | ||
" enrollments.extend(json.load(e))\n", | ||
"\n", | ||
"print(len(enrollments))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"events = []\n", | ||
"\n", | ||
"for enrollment in enrollments:\n", | ||
" agency_name = enrollment[\"Event Properties Transit Agency\"]\n", | ||
" agency = AGENCIES.get(agency_name, {})\n", | ||
"\n", | ||
" flows = agency.get(\"flows\")\n", | ||
" flow_name = enrollment[\"Event Properties Enrollment Flows\"]\n", | ||
" flow = flows.get(flow_name)\n", | ||
"\n", | ||
" event_time = enrollment.get(\"Client Event Time\")\n", | ||
" event_time = event_time.replace(\"/\", \"-\").replace(\",\", \"\")\n", | ||
"\n", | ||
" if flow:\n", | ||
" event = enrollmentevent_fixture(\n", | ||
" agency.get(\"id\"),\n", | ||
" flow,\n", | ||
" enrollment.get(\"Event Properties Eligibility Verifier\"),\n", | ||
" event_time\n", | ||
" )\n", | ||
"\n", | ||
" events.append(event)\n", | ||
"\n", | ||
"with open(\"events.json\", \"w\") as f:\n", | ||
" json.dump(events, f)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.11.10" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |