From 110305f1ebdc514c96f8b65f71fd497892d2a4db Mon Sep 17 00:00:00 2001 From: Kegan Maher Date: Thu, 14 Nov 2024 17:03:35 -0800 Subject: [PATCH] chore(enrollment): generate event fixtures from metabase export --- enrollment-events.ipynb | 132 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) create mode 100644 enrollment-events.ipynb diff --git a/enrollment-events.ipynb b/enrollment-events.ipynb new file mode 100644 index 000000000..9a707b4aa --- /dev/null +++ b/enrollment-events.ipynb @@ -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 +}