Merge branch 'VaccineDistributionByZipcode' into pages
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<meta content="width=device-width, initial-scale=1.0" name="viewport" />
|
||||
<title>Batch Codes of Coronavirus 2019 Vaccines</title>
|
||||
<title>Pfizer Vaccine Distribution by ZIP Code</title>
|
||||
<link href="https://cdn.datatables.net/1.13.1/css/jquery.dataTables.css" rel="stylesheet" type="text/css" />
|
||||
<link href="batchCodeTable.css" rel="stylesheet" type="text/css" />
|
||||
<link href="forkMeOnGitHub.css" rel="stylesheet" type="text/css" />
|
||||
@@ -28,14 +28,14 @@
|
||||
|
||||
<body>
|
||||
<span id="forkongithub"><a href="https://github.com/KnollFrank/HowBadIsMyBatch">Fork me on GitHub</a></span>
|
||||
<h1>Batch Codes of Coronavirus 2019 Vaccines</h1>
|
||||
<h1>Pfizer Vaccine Distribution by ZIP Code</h1>
|
||||
<table class="display" id="vaccineDistributionByZipcodeTable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>PROVIDER_NAME</th>
|
||||
<th>ZIPCODE_SHP</th>
|
||||
<th>LOT_NUMBER</th>
|
||||
<th>DOSES_SHIPPED</th>
|
||||
<th>Provider</th>
|
||||
<th>ZIP Code</th>
|
||||
<th>Lot Number</th>
|
||||
<th>Summary</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
|
||||
@@ -1,42 +1,39 @@
|
||||
class VaccineDistributionByZipcodeTableInitializer {
|
||||
|
||||
#tableElement;
|
||||
#table;
|
||||
|
||||
constructor({ tableElement }) {
|
||||
this.#tableElement = tableElement;
|
||||
}
|
||||
|
||||
initialize() {
|
||||
this.#table = this.#createEmptyTable();
|
||||
this.#loadDataIntoTable();
|
||||
this.#createTable();
|
||||
this.#selectInput();
|
||||
}
|
||||
|
||||
#createEmptyTable() {
|
||||
return this.#tableElement.DataTable(
|
||||
#createTable() {
|
||||
this.#tableElement.DataTable(
|
||||
{
|
||||
language:
|
||||
{
|
||||
searchPlaceholder: "Enter Batch Code"
|
||||
},
|
||||
search:
|
||||
{
|
||||
return: false
|
||||
},
|
||||
ajax: 'data/vaccineDistributionByZipcode/VaccineDistributionByZipcode.json',
|
||||
processing: true,
|
||||
deferRender: true,
|
||||
columnDefs:
|
||||
[
|
||||
{
|
||||
searchable: false,
|
||||
targets: [this.#getColumnIndex('DOSES_SHIPPED')]
|
||||
orderable: false,
|
||||
targets: [this.#getColumnIndex('Summary')]
|
||||
},
|
||||
{
|
||||
searchable: true,
|
||||
targets: [
|
||||
this.#getColumnIndex('PROVIDER_NAME'),
|
||||
this.#getColumnIndex('ZIPCODE_SHP'),
|
||||
this.#getColumnIndex('LOT_NUMBER'),
|
||||
this.#getColumnIndex('Provider'),
|
||||
this.#getColumnIndex('ZIP Code'),
|
||||
this.#getColumnIndex('Lot Number'),
|
||||
]
|
||||
},
|
||||
]
|
||||
@@ -45,34 +42,17 @@ class VaccineDistributionByZipcodeTableInitializer {
|
||||
|
||||
#getColumnIndex(columnName) {
|
||||
switch (columnName) {
|
||||
case 'PROVIDER_NAME':
|
||||
case 'Provider':
|
||||
return 0;
|
||||
case 'ZIPCODE_SHP':
|
||||
case 'ZIP Code':
|
||||
return 1;
|
||||
case 'LOT_NUMBER':
|
||||
case 'Lot Number':
|
||||
return 2;
|
||||
case 'DOSES_SHIPPED':
|
||||
case 'Summary':
|
||||
return 3;
|
||||
}
|
||||
}
|
||||
|
||||
#loadDataIntoTable() {
|
||||
// FK-TODO: show "Loading.." message or spinning wheel.
|
||||
fetch('data/vaccineDistributionByZipcode/VaccineDistributionByZipcode.json')
|
||||
.then(response => response.json())
|
||||
.then(json => {
|
||||
this.#setTableRows(json.data);
|
||||
this.#selectInput();
|
||||
});
|
||||
}
|
||||
|
||||
#setTableRows(rows) {
|
||||
this.#table
|
||||
.clear()
|
||||
.rows.add(rows)
|
||||
.draw();
|
||||
}
|
||||
|
||||
#selectInput() {
|
||||
const input = document.querySelector(".dataTables_filter input");
|
||||
input.focus();
|
||||
|
||||
File diff suppressed because one or more lines are too long
15
src/ADRColumnAdder.py
Normal file
15
src/ADRColumnAdder.py
Normal file
@@ -0,0 +1,15 @@
|
||||
import pandas as pd
|
||||
|
||||
class ADRColumnAdder:
|
||||
|
||||
def __init__(self, ADR_by_Batchcode):
|
||||
self.ADR_by_Batchcode = ADR_by_Batchcode
|
||||
|
||||
def addADRColumn(self, vaccineDistributionByZipcode):
|
||||
return pd.merge(
|
||||
vaccineDistributionByZipcode,
|
||||
self.ADR_by_Batchcode,
|
||||
how = 'left',
|
||||
left_on = 'LOT_NUMBER',
|
||||
right_index = True,
|
||||
validate = 'many_to_one')
|
||||
5
src/ADR_by_Batchcode_Table_Factory.py
Normal file
5
src/ADR_by_Batchcode_Table_Factory.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from BatchCodeTableFactory import BatchCodeTableFactory
|
||||
|
||||
def create_ADR_by_Batchcode_Table_4USA(internationalVaersCovid19):
|
||||
batchCodeTable4USA = BatchCodeTableFactory(internationalVaersCovid19).createBatchCodeTableByCountry('United States')
|
||||
return batchCodeTable4USA[['Adverse Reaction Reports']]
|
||||
@@ -163,6 +163,156 @@
|
||||
" minADRsForLethality = 100,\n",
|
||||
" onCountryProcessed = display)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"attachments": {},
|
||||
"cell_type": "markdown",
|
||||
"id": "2d93b511",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Vaccine Distribution by Zipcode"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "cfcbad44",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"vaccineDistributionByZipcode = pd.read_excel(\n",
|
||||
" io = 'tmp/Amended-22-01962-Pfizer-2022-0426-pulled-2022-0823.xlsx',\n",
|
||||
" usecols = ['PROVIDER_NAME', 'ZIPCODE_SHP', 'LOT_NUMBER', 'DOSES_SHIPPED'],\n",
|
||||
" dtype = {'DOSES_SHIPPED': 'int'})\n",
|
||||
"vaccineDistributionByZipcode"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "59c745d2",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from VaccineDistributionByZipcodeSimplifier import VaccineDistributionByZipcodeSimplifier\n",
|
||||
"\n",
|
||||
"vaccineDistributionByZipcode = VaccineDistributionByZipcodeSimplifier.sumDoses(vaccineDistributionByZipcode)\n",
|
||||
"vaccineDistributionByZipcode"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "8cd250f7",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"OVERALL_DOSES_SHIPPED_by_LOT_NUMBER = vaccineDistributionByZipcode.groupby('LOT_NUMBER').agg(OVERALL_DOSES_SHIPPED = pd.NamedAgg(column = 'DOSES_SHIPPED', aggfunc = sum))\n",
|
||||
"OVERALL_DOSES_SHIPPED_by_LOT_NUMBER"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "1a5667be",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from OVERALL_DOSES_SHIPPEDColumnAdder import OVERALL_DOSES_SHIPPEDColumnAdder\n",
|
||||
"\n",
|
||||
"vaccineDistributionByZipcode = OVERALL_DOSES_SHIPPEDColumnAdder(OVERALL_DOSES_SHIPPED_by_LOT_NUMBER).addColumn(vaccineDistributionByZipcode)\n",
|
||||
"vaccineDistributionByZipcode"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "f77505c6",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from ADR_by_Batchcode_Table_Factory import create_ADR_by_Batchcode_Table_4USA\n",
|
||||
"\n",
|
||||
"ADR_by_Batchcode_Table_4USA = create_ADR_by_Batchcode_Table_4USA(internationalVaersCovid19)\n",
|
||||
"ADR_by_Batchcode_Table_4USA"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "99120c77",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from ADRColumnAdder import ADRColumnAdder\n",
|
||||
"\n",
|
||||
"vaccineDistributionByZipcode = ADRColumnAdder(ADR_by_Batchcode_Table_4USA).addADRColumn(vaccineDistributionByZipcode)\n",
|
||||
"vaccineDistributionByZipcode"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "3276cce7",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def summarize(row):\n",
|
||||
" ADRs = row['DOSES_SHIPPED'] / row['OVERALL_DOSES_SHIPPED'] * row['Adverse Reaction Reports']\n",
|
||||
" return f\"{row['DOSES_SHIPPED']} (out of {row['OVERALL_DOSES_SHIPPED']}) shipped doses are statistically responsible for <b>{ADRs:.2f}</b> (out of {row['Adverse Reaction Reports']}) adverse reaction reports\"\n",
|
||||
"\n",
|
||||
"vaccineDistributionByZipcode['Summary'] = vaccineDistributionByZipcode.apply(summarize, axis = 'columns')\n",
|
||||
"vaccineDistributionByZipcode"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "10cf731f",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"vaccineDistributionByZipcode = vaccineDistributionByZipcode[['PROVIDER_NAME', 'ZIPCODE_SHP', 'LOT_NUMBER', 'Summary']]\n",
|
||||
"vaccineDistributionByZipcode"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "0c2020e9",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"vaccineDistributionByZipcode = vaccineDistributionByZipcode.rename(\n",
|
||||
" columns = {\n",
|
||||
" 'PROVIDER_NAME': 'Provider',\n",
|
||||
" 'ZIPCODE_SHP': 'ZIP Code',\n",
|
||||
" 'LOT_NUMBER': 'Lot Number'\n",
|
||||
" })\n",
|
||||
"vaccineDistributionByZipcode"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "f68c72d0",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# vaccineDistributionByZipcode.to_excel('tmp/Amended-22-01962-Pfizer-2022-0426-pulled-2022-0823_sumDoses.xlsx')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "9b8f0b6e",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from IOUtils import IOUtils\n",
|
||||
"\n",
|
||||
"IOUtils.saveDataFrameAsJson(vaccineDistributionByZipcode, '../docs/data/vaccineDistributionByZipcode/VaccineDistributionByZipcode.json')"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
|
||||
16
src/OVERALL_DOSES_SHIPPEDColumnAdder.py
Normal file
16
src/OVERALL_DOSES_SHIPPEDColumnAdder.py
Normal file
@@ -0,0 +1,16 @@
|
||||
import pandas as pd
|
||||
|
||||
# FK-TODO: DRY with ADRColumnAdder
|
||||
class OVERALL_DOSES_SHIPPEDColumnAdder:
|
||||
|
||||
def __init__(self, OVERALL_DOSES_SHIPPED_by_LOT_NUMBER):
|
||||
self.OVERALL_DOSES_SHIPPED_by_LOT_NUMBER = OVERALL_DOSES_SHIPPED_by_LOT_NUMBER
|
||||
|
||||
def addColumn(self, vaccineDistributionByZipcode):
|
||||
return pd.merge(
|
||||
vaccineDistributionByZipcode,
|
||||
self.OVERALL_DOSES_SHIPPED_by_LOT_NUMBER,
|
||||
how = 'left',
|
||||
left_on = 'LOT_NUMBER',
|
||||
right_index = True,
|
||||
validate = 'many_to_one')
|
||||
@@ -4,5 +4,5 @@ import pandas as pd
|
||||
class TestHelper:
|
||||
|
||||
@staticmethod
|
||||
def createDataFrame(index, columns, data, dtypes={}):
|
||||
return pd.DataFrame(index=index, columns=columns, data=data).astype(dtypes)
|
||||
def createDataFrame(columns, data, dtypes={}, **kwargs):
|
||||
return pd.DataFrame(columns=columns, data=data, **kwargs).astype(dtypes)
|
||||
|
||||
@@ -1,103 +0,0 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import pandas as pd\n",
|
||||
"\n",
|
||||
"vaccineDistributionByZipcode = pd.read_excel('tmp/Amended-22-01962-Pfizer-2022-0426-pulled-2022-0823_edited.xlsx')\n",
|
||||
"vaccineDistributionByZipcode"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"len(vaccineDistributionByZipcode['PROVIDER_NAME'].unique())"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"len(vaccineDistributionByZipcode['ZIPCODE_SHP'].unique())"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"vaccineDistributionByZipcode['AWARDEE'].unique()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"vaccineDistributionByZipcode['STATE_SHP'].unique()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"vaccineDistributionByZipcode[vaccineDistributionByZipcode['ZIPCODE_SHP'] == '37801']"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from IOUtils import IOUtils\n",
|
||||
"\n",
|
||||
"IOUtils.saveDataFrameAsJson(vaccineDistributionByZipcode, '../docs/data/vaccineDistributionByZipcode/VaccineDistributionByZipcode.json')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"IOUtils.saveDataFrameAsHtml(vaccineDistributionByZipcode, '../docs/data/vaccineDistributionByZipcode/VaccineDistributionByZipcode.html')"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "howbadismybatch-venv-kernel",
|
||||
"language": "python",
|
||||
"name": "howbadismybatch-venv-kernel"
|
||||
},
|
||||
"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.10.8"
|
||||
},
|
||||
"orig_nbformat": 4
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 2
|
||||
}
|
||||
10
src/VaccineDistributionByZipcodeSimplifier.py
Normal file
10
src/VaccineDistributionByZipcodeSimplifier.py
Normal file
@@ -0,0 +1,10 @@
|
||||
import pandas as pd
|
||||
|
||||
class VaccineDistributionByZipcodeSimplifier:
|
||||
|
||||
@staticmethod
|
||||
def sumDoses(vaccineDistributionByZipcode):
|
||||
return (vaccineDistributionByZipcode
|
||||
.groupby(['PROVIDER_NAME', 'ZIPCODE_SHP', 'LOT_NUMBER'])
|
||||
.agg(DOSES_SHIPPED = pd.NamedAgg(column = 'DOSES_SHIPPED', aggfunc = sum))
|
||||
.reset_index())
|
||||
30
src/VaccineDistributionByZipcodeSimplifierTest.py
Normal file
30
src/VaccineDistributionByZipcodeSimplifierTest.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import unittest
|
||||
from VaccineDistributionByZipcodeSimplifier import VaccineDistributionByZipcodeSimplifier
|
||||
from TestHelper import TestHelper
|
||||
from pandas.testing import assert_frame_equal
|
||||
import pandas as pd
|
||||
|
||||
class VaccineDistributionByZipcodeSimplifierTest(unittest.TestCase):
|
||||
|
||||
def test_sumDoses(self):
|
||||
# Given
|
||||
doses_shipped1 = 300.0
|
||||
doses_shipped2 = 400.0
|
||||
vaccineDistributionByZipcode = TestHelper.createDataFrame(
|
||||
columns = ['PROVIDER_NAME', 'ZIPCODE_SHP', 'LOT_NUMBER', 'DOSES_SHIPPED'],
|
||||
data = [ ['@PHARMACY.COM', '97206-2314', 'FK9893', 300.0],
|
||||
['@PHARMACY.COM - 82ND AVE', '97266-4885', 'FK9893', doses_shipped1],
|
||||
['@PHARMACY.COM - 82ND AVE', '97266-4885', 'FK9893', doses_shipped2],
|
||||
['@PHARMACY.COM - 82ND AVE', '97266-4885', 'FL8095', 200.0]])
|
||||
|
||||
# When
|
||||
vaccineDistributionByZipcodeSimplified = VaccineDistributionByZipcodeSimplifier.sumDoses(vaccineDistributionByZipcode)
|
||||
|
||||
# Then
|
||||
assert_frame_equal(
|
||||
vaccineDistributionByZipcodeSimplified,
|
||||
TestHelper.createDataFrame(
|
||||
columns = ['PROVIDER_NAME', 'ZIPCODE_SHP', 'LOT_NUMBER', 'DOSES_SHIPPED'],
|
||||
data = [ ['@PHARMACY.COM', '97206-2314', 'FK9893', 300.0],
|
||||
['@PHARMACY.COM - 82ND AVE', '97266-4885', 'FK9893', doses_shipped1 + doses_shipped2],
|
||||
['@PHARMACY.COM - 82ND AVE', '97266-4885', 'FL8095', 200.0]]))
|
||||
Reference in New Issue
Block a user