Merge branch 'remove-countries-from-UI' into pages

This commit is contained in:
frankknoll
2023-04-03 01:21:20 +02:00
21 changed files with 160 additions and 369 deletions

View File

@@ -1,34 +1,22 @@
class GoogleAnalytics {
static click_batchcode(batchcode) {
gtag(
'event',
'click_batchcode',
{
'batchcode': batchcode
});
// FK-TODO: uncomment
// gtag(
// 'event',
// 'click_batchcode',
// {
// 'batchcode': batchcode
// });
}
static view_search_results(search_term) {
gtag(
'event',
'view_search_results',
{
'search_term': search_term
});
}
static countrySelected(country) {
gtag(
"event",
"select_item",
{
item_list_id: "countrySelect",
items: [
{
item_id: country,
}
]
});
// FK-TODO: uncomment
// gtag(
// 'event',
// 'view_search_results',
// {
// 'search_term': search_term
// });
}
}

View File

@@ -1,7 +1,7 @@
class HistoDescrsProvider {
static getHistoDescrs(country, batchcode) {
return fetch(`data/histograms/${country}/${batchcode}.json`)
static getHistoDescrs(batchcode) {
return fetch(`data/histograms/Global/${batchcode}.json`)
.then(response => response.json())
.then(histoDescrs => {
histoDescrs.histograms.sort((histoDescr1, histoDescr2) => histoDescr1.batchcodes.length - histoDescr2.batchcodes.length);

View File

@@ -6,17 +6,17 @@ class HistogramView {
this.#uiContainer = uiContainer
}
displayHistogramView(country, batchcode) {
displayHistogramView(batchcode) {
this
.#loadHistoDescrs(country, batchcode)
.#loadHistoDescrs(batchcode)
.then(histoDescrs => this.#displayHistogramViewForHistoDescrs(histoDescrs));
}
#loadHistoDescrs(country, batchcode) {
#loadHistoDescrs(batchcode) {
const loadingText = document.createTextNode('Loading...');
this.#uiContainer.appendChild(loadingText);
return HistoDescrsProvider
.getHistoDescrs(country, batchcode)
.getHistoDescrs(batchcode)
.then(histoDescrs => {
loadingText.remove();
return histoDescrs;

File diff suppressed because one or more lines are too long

View File

@@ -1,30 +1,21 @@
class BatchCodeTableInitializer {
#heading;
#countrySelect;
#batchCodeTableElement;
#batchCodeTable;
#columnSearch;
constructor({ heading, countrySelect, batchCodeTableElement }) {
this.#heading = heading;
this.#countrySelect = countrySelect;
constructor(batchCodeTableElement) {
this.#batchCodeTableElement = batchCodeTableElement;
}
initialize() {
this.#batchCodeTable = this.#createEmptyBatchCodeTable();
this.#columnSearch = new ColumnSearch(this.#batchCodeTable.column(this.#getColumnIndex('Company')));
this.#countrySelect.addEventListener('change', event => this.#displayCountry());
this.#displayCountry();
this.#display();
this.#initializeHistogramView();
this.#trackSearchWithGoogleAnalytics();
}
#getCountry() {
return UIUtils.getSelectedOption(this.#countrySelect).value;
}
#createEmptyBatchCodeTable() {
return this.#batchCodeTableElement.DataTable(
{
@@ -58,14 +49,13 @@ class BatchCodeTableInitializer {
this.#getColumnIndex('Deaths'),
this.#getColumnIndex('Disabilities'),
this.#getColumnIndex('Life Threatening Illnesses'),
this.#getColumnIndex('Countries'),
this.#getColumnIndex('Severe reports'),
this.#getColumnIndex('Lethality')
]
},
{
orderable: false,
targets: [this.#getColumnIndex('Countries'), this.#getColumnIndex('Company')]
targets: [this.#getColumnIndex('Company')]
},
{
render: (data, type, row) => {
@@ -94,19 +84,16 @@ class BatchCodeTableInitializer {
return 5;
case 'Company':
return 6;
case 'Countries':
return 7;
case 'Severe reports':
return 8;
return 7;
case 'Lethality':
return 9;
return 8;
}
}
#displayCountry() {
this.#heading.textContent = this.#getCountry() == 'Global' ? 'Global Batch Codes' : `Batch Codes for ${this.#getCountry()}`;
#display() {
// FK-TODO: show "Loading.." message or spinning wheel.
fetch(`data/batchCodeTables/${this.#getCountry()}.json`)
fetch(`data/batchCodeTables/Global.json`)
.then(response => response.json())
.then(json => {
this.#_addEmptyControlColumn(json);
@@ -117,7 +104,6 @@ class BatchCodeTableInitializer {
this.#columnSearch.columnContentUpdated();
this.#selectInput();
});
GoogleAnalytics.countrySelected(this.#getCountry());
}
#_addEmptyControlColumn(json) {
@@ -155,7 +141,7 @@ class BatchCodeTableInitializer {
row.child(uiContainer).show();
tr.addClass('shown');
const batchcode = row.data()[thisClassInstance.#getColumnIndex('Batch')];
new HistogramView(uiContainer).displayHistogramView(thisClassInstance.#getCountry(), batchcode);
new HistogramView(uiContainer).displayHistogramView(batchcode);
GoogleAnalytics.click_batchcode(batchcode);
}
});

File diff suppressed because one or more lines are too long

View File

@@ -6,14 +6,7 @@ class BatchCodeTableFactory:
def __init__(self, dataFrame: pd.DataFrame):
self.dataFrame = dataFrame
self.companyColumnAdder = CompanyColumnAdder(dataFrame)
self.countryBatchCodeTable = SummationTableFactory.createSummationTable(
dataFrame.groupby(
[
dataFrame['COUNTRY'],
dataFrame['VAX_LOT']
]))
def createGlobalBatchCodeTable(self):
return self._postProcess(SummationTableFactory.createSummationTable(self.dataFrame.groupby('VAX_LOT')))
@@ -21,7 +14,7 @@ class BatchCodeTableFactory:
return self._postProcess(self._getBatchCodeTableByCountry(country))
def _postProcess(self, batchCodeTable):
batchCodeTable = self.companyColumnAdder.addCompanyColumn(batchCodeTable)
batchCodeTable = CompanyColumnAdder(self.dataFrame).addCompanyColumn(batchCodeTable)
batchCodeTable = batchCodeTable[
[
'Adverse Reaction Reports',
@@ -29,17 +22,22 @@ class BatchCodeTableFactory:
'Disabilities',
'Life Threatening Illnesses',
'Company',
'Countries',
'Severe reports',
'Lethality'
]]
return batchCodeTable.sort_values(by = 'Severe reports', ascending = False)
def _getBatchCodeTableByCountry(self, country):
if country in self.countryBatchCodeTable.index:
return self.countryBatchCodeTable.loc[country]
else:
return self._getEmptyBatchCodeTable()
countryBatchCodeTable = self._getCountryBatchCodeTable()
return countryBatchCodeTable.loc[country] if country in countryBatchCodeTable.index else self._getEmptyBatchCodeTable(countryBatchCodeTable)
def _getEmptyBatchCodeTable(self):
return self.countryBatchCodeTable[0:0].droplevel(0)
def _getCountryBatchCodeTable(self):
return SummationTableFactory.createSummationTable(
self.dataFrame.groupby(
[
self.dataFrame['COUNTRY'],
self.dataFrame['VAX_LOT']
]))
def _getEmptyBatchCodeTable(self, countryBatchCodeTable):
return countryBatchCodeTable[0:0].droplevel(0)

View File

@@ -28,24 +28,24 @@ class BatchCodeTableFactoryTest(unittest.TestCase):
# Then
assert_frame_equal(
batchCodeTable[['Adverse Reaction Reports', 'Deaths', 'Disabilities', 'Life Threatening Illnesses', 'Company', 'Countries', 'Severe reports', 'Lethality']],
batchCodeTable[['Adverse Reaction Reports', 'Deaths', 'Disabilities', 'Life Threatening Illnesses', 'Company', 'Severe reports', 'Lethality']],
TestHelper.createDataFrame(
columns = ['Adverse Reaction Reports', 'Deaths', 'Disabilities', 'Life Threatening Illnesses', 'Company', 'Countries', 'Severe reports', 'Lethality'],
data = [ [2, 1, 2, 2, 'MODERNA', 'France', 2/2 * 100, 1/2 * 100],
[1, 0, 0, 0, 'MODERNA', 'France', 0/1 * 100, 0/1 * 100]],
columns = ['Adverse Reaction Reports', 'Deaths', 'Disabilities', 'Life Threatening Illnesses', 'Company', 'Severe reports', 'Lethality'],
data = [ [2, 1, 2, 2, 'MODERNA', 2/2 * 100, 1/2 * 100],
[1, 0, 0, 0, 'MODERNA', 0/1 * 100, 0/1 * 100]],
index = pd.Index(
[
'030L20B',
'030L20A'
],
name = 'VAX_LOT')),
check_dtype = False)
check_dtype = True)
def test_createGlobalBatchCodeTable(self):
# Given
dataFrame = TestHelper.createDataFrame(
columns = ['DIED', 'L_THREAT', 'DISABLE', 'VAX_TYPE', 'VAX_MANU', 'VAX_LOT', 'VAX_DOSE_SERIES', 'SPLTTYPE', 'HOSPITAL', 'ER_VISIT', 'COUNTRY'],
data = [ [1, 0, 0, 'COVID19', 'PFIZER\BIONTECH', '016M20A', '2', 'GBPFIZER INC2020486806', 0, 0, 'United Kingdom'],
data = [ [1, 0, 0, 'COVID19', 'PFIZER\BIONTECH', '016M20A', '2', 'dummy', 0, 0, None],
[0, 0, 0, 'COVID19', 'MODERNA', '030L20A', '1', 'FRMODERNATX, INC.MOD20224', 0, 0, 'France'],
[1, 1, 1, 'COVID19', 'MODERNA', '030L20B', '1', 'FRMODERNATX, INC.MOD20224', 0, 0, 'France'],
[0, 1, 1, 'COVID19', 'MODERNA', '030L20B', '1', 'FRMODERNATX, INC.MOD20224', 0, 0, 'United Kingdom']],
@@ -62,12 +62,12 @@ class BatchCodeTableFactoryTest(unittest.TestCase):
# Then
assert_frame_equal(
batchCodeTable[['Adverse Reaction Reports', 'Deaths', 'Disabilities', 'Life Threatening Illnesses', 'Company', 'Countries', 'Severe reports', 'Lethality']],
batchCodeTable[['Adverse Reaction Reports', 'Deaths', 'Disabilities', 'Life Threatening Illnesses', 'Company', 'Severe reports', 'Lethality']],
TestHelper.createDataFrame(
columns = ['Adverse Reaction Reports', 'Deaths', 'Disabilities', 'Life Threatening Illnesses', 'Company', 'Countries', 'Severe reports', 'Lethality'],
data = [ [1, 1, 0, 0, 'PFIZER\BIONTECH', 'United Kingdom', 1/1 * 100, 1/1 * 100],
[2, 1, 2, 2, 'MODERNA', 'France, United Kingdom', 2/2 * 100, 1/2 * 100],
[1, 0, 0, 0, 'MODERNA', 'France', 0/1 * 100, 0/1 * 100]],
columns = ['Adverse Reaction Reports', 'Deaths', 'Disabilities', 'Life Threatening Illnesses', 'Company', 'Severe reports', 'Lethality'],
data = [ [1, 1, 0, 0, 'PFIZER\BIONTECH', 1/1 * 100, 1/1 * 100],
[2, 1, 2, 2, 'MODERNA', 2/2 * 100, 1/2 * 100],
[1, 0, 0, 0, 'MODERNA', 0/1 * 100, 0/1 * 100]],
index = pd.Index(
[
'016M20A',
@@ -75,7 +75,7 @@ class BatchCodeTableFactoryTest(unittest.TestCase):
'030L20A'
],
name = 'VAX_LOT')),
check_dtype = False)
check_dtype = True)
def test_createBatchCodeTableByNonExistingCountry(self):
# Given
@@ -98,9 +98,9 @@ class BatchCodeTableFactoryTest(unittest.TestCase):
# Then
assert_frame_equal(
batchCodeTable[['Adverse Reaction Reports', 'Deaths', 'Disabilities', 'Life Threatening Illnesses', 'Company', 'Countries', 'Severe reports', 'Lethality']],
batchCodeTable[['Adverse Reaction Reports', 'Deaths', 'Disabilities', 'Life Threatening Illnesses', 'Company', 'Severe reports', 'Lethality']],
TestHelper.createDataFrame(
columns = ['Adverse Reaction Reports', 'Deaths', 'Disabilities', 'Life Threatening Illnesses', 'Company', 'Countries', 'Severe reports', 'Lethality'],
columns = ['Adverse Reaction Reports', 'Deaths', 'Disabilities', 'Life Threatening Illnesses', 'Company', 'Severe reports', 'Lethality'],
data = [ ],
index = pd.Index([], name = 'VAX_LOT')),
check_dtype = False)

View File

@@ -1,30 +1,14 @@
from bs4 import BeautifulSoup
from HtmlTransformerUtil import HtmlTransformerUtil
from CountryOptionsSetter import CountryOptionsSetter
from DateProvider import DateProvider
from HtmlUtils import getCountryOptions, getCountries
from DateProvider import DateProvider
def updateBatchCodeTableHtmlFile(internationalVaersCovid19, batchCodeTableHtmlFile):
countryOptions = getCountryOptions(getCountries(internationalVaersCovid19))
_saveCountryOptions(countryOptions, batchCodeTableHtmlFile)
def updateBatchCodeTableHtmlFile(batchCodeTableHtmlFile):
_saveLastUpdatedBatchCodeTable(
DateProvider().getLastUpdatedDataSource(),
batchCodeTableHtmlFile)
def _saveCountryOptions(countryOptions, batchCodeTableHtmlFile):
HtmlTransformerUtil().applySoupTransformerToFile(
file=batchCodeTableHtmlFile,
soupTransformer=lambda soup:
BeautifulSoup(
CountryOptionsSetter().setCountryOptions(
html=str(soup),
options=countryOptions),
'lxml'))
def _saveLastUpdatedBatchCodeTable(lastUpdated, batchCodeTableHtmlFile):
def setLastUpdated(soup):
soup.find(id="last_updated").string.replace_with(

View File

@@ -1,28 +1,9 @@
from IOUtils import IOUtils
from BatchCodeTableFactory import BatchCodeTableFactory
import numpy as np
from HtmlUtils import getCountries
def createAndSaveBatchCodeTables(
internationalVaersCovid19,
minADRsForLethality,
onCountryProcessed = lambda country: None):
batchCodeTableFactory = BatchCodeTableFactory(internationalVaersCovid19)
_createAndSaveBatchCodeTablesForCountries(
createBatchCodeTableForCountry = lambda country: batchCodeTableFactory.createBatchCodeTableByCountry(country),
countries = getCountries(internationalVaersCovid19),
minADRsForLethality = minADRsForLethality,
onCountryProcessed = onCountryProcessed)
_createAndSaveBatchCodeTableForCountry(
createBatchCodeTableForCountry = lambda country: batchCodeTableFactory.createGlobalBatchCodeTable(),
country = 'Global',
minADRsForLethality = minADRsForLethality,
onCountryProcessed = onCountryProcessed)
def _createAndSaveBatchCodeTableForCountry(createBatchCodeTableForCountry, country, minADRsForLethality, onCountryProcessed):
batchCodeTable = createBatchCodeTableForCountry(country)
def createAndSaveGlobalBatchCodeTable(minADRsForLethality, batchCodeTableFactory):
batchCodeTable = batchCodeTableFactory.createGlobalBatchCodeTable()
batchCodeTable.index.set_names("Batch", inplace=True)
if minADRsForLethality is not None:
batchCodeTable.loc[
@@ -38,16 +19,7 @@ def _createAndSaveBatchCodeTableForCountry(createBatchCodeTableForCountry, count
'Disabilities',
'Life Threatening Illnesses',
'Company',
'Countries',
'Severe reports',
'Lethality'
]]
IOUtils.saveDataFrameAsJson(
batchCodeTable,
'../docs/data/batchCodeTables/' + country + '.json')
onCountryProcessed(country)
def _createAndSaveBatchCodeTablesForCountries(createBatchCodeTableForCountry, countries, minADRsForLethality, onCountryProcessed):
for country in countries:
_createAndSaveBatchCodeTableForCountry(createBatchCodeTableForCountry, country, minADRsForLethality, onCountryProcessed)
IOUtils.saveDataFrameAsJson(batchCodeTable, '../docs/data/batchCodeTables/Global.json')

View File

@@ -29,17 +29,17 @@ class CountryColumnAdderTest(unittest.TestCase):
assert_frame_equal(
dataFrameWithCountryColumn,
TestHelper.createDataFrame(
columns = ['SPLTTYPE', 'COUNTRY'],
data = [ ['GBPFIZER INC2020486806', 'United Kingdom'],
['FRMODERNATX, INC.MOD20224', 'France'],
['dummy', 'Unknown Country']],
index = pd.Index(
name = 'VAERS_ID',
data = [
"4711",
"0815",
"123"]),
dtypes = {'COUNTRY': 'string'}))
columns = ['SPLTTYPE', 'COUNTRY'],
data = [ ['GBPFIZER INC2020486806', 'United Kingdom'],
['FRMODERNATX, INC.MOD20224', 'France'],
['dummy', None]],
index = pd.Index(
name = 'VAERS_ID',
data = [
"4711",
"0815",
"123"]),
dtypes = {'COUNTRY': 'string'}))
def test_addCountryColumn2(self):
@@ -75,14 +75,14 @@ class CountryColumnAdderTest(unittest.TestCase):
assert_frame_equal(
dataFrameWithCountryColumn,
TestHelper.createDataFrame(
columns = ['VAX_LOT', 'COUNTRY'],
data = [ ['1808982', 'France'],
['EW0175', 'France'],
['EW0176', 'United Kingdom']],
index = pd.Index(
name = 'VAERS_ID',
data = [
2547730,
2547730,
2547744]),
dtypes = {'COUNTRY': 'string'}))
columns = ['VAX_LOT', 'COUNTRY'],
data = [ ['1808982', 'France'],
['EW0175', 'France'],
['EW0176', 'United Kingdom']],
index = pd.Index(
name = 'VAERS_ID',
data = [
2547730,
2547730,
2547744]),
dtypes = {'COUNTRY': 'string'}))

View File

@@ -1,21 +0,0 @@
from bs4 import BeautifulSoup
class CountryOptionsSetter:
def setCountryOptions(self, html, options):
soup = self._setCountryOptions(self._parse(html), self._parseOptions(options))
return str(soup)
def _setCountryOptions(self, soup, options):
countrySelect = soup.find(id = "countrySelect")
countrySelect.clear()
for option in options:
countrySelect.append(option)
return soup
def _parseOptions(self, options):
return [self._parse(option).option for option in options]
def _parse(self, html):
return BeautifulSoup(html, 'lxml')

View File

@@ -1,73 +0,0 @@
import unittest
from CountryOptionsSetter import CountryOptionsSetter
class CountryOptionsSetterTest(unittest.TestCase):
def test_setCountryOptions(self):
# Given
countryOptionsSetter = CountryOptionsSetter()
# When
htmlActual = countryOptionsSetter.setCountryOptions(
html='''
<html>
<body>
<p>Test<p/>
<select id="countrySelect" name="country">
<option value="Global" selected>Global</option>
<option value="Afghanistan">Afghanistan</option>
<option value="Albania">Albania</option>
<option value="Algeria">Algeria</option>
</select>
</body>
</html>
''',
options=[
'<option value="Global" selected>Global</option>',
'<option value="Azerbaijan">Azerbaijan</option>',
'<option value="Bahrain">Bahrain</option>'])
# Then
assertEqualHTML(
htmlActual,
'''
<html>
<body>
<p>Test<p/>
<select id="countrySelect" name="country">
<option value="Global" selected>Global</option>
<option value="Azerbaijan">Azerbaijan</option>
<option value="Bahrain">Bahrain</option>
</select>
</body>
</html>
''')
# adapted from https://stackoverflow.com/questions/8006909/pretty-print-assertequal-for-html-strings
def assertEqualHTML(string1, string2, file1='', file2=''):
u'''
Compare two unicode strings containing HTML.
A human friendly diff goes to logging.error() if they
are not equal, and an exception gets raised.
'''
from bs4 import BeautifulSoup as bs
import difflib
def short(mystr):
max = 20
if len(mystr) > max:
return mystr[:max]
return mystr
p = []
for mystr, file in [(string1, file1), (string2, file2)]:
if not isinstance(mystr, str):
raise Exception(u'string ist not unicode: %r %s' %
(short(mystr), file))
soup = bs(mystr, 'lxml')
pretty = soup.prettify()
p.append(pretty)
if p[0] != p[1]:
for line in difflib.unified_diff(p[0].splitlines(), p[1].splitlines(), fromfile=file1, tofile=file2):
display(line)
display(p[0], ' != ', p[1])
raise Exception('Not equal %s %s' % (file1, file2))

View File

@@ -6,10 +6,6 @@ from HistogramDescriptionTableFactory import HistogramDescriptionTableFactory
def createAndSaveGlobalHistograms(symptomByBatchcodeTable):
symptomByBatchcodeTable = symptomByBatchcodeTable.assign(COUNTRY = 'Global')
createAndSaveHistogramsForCountries(symptomByBatchcodeTable)
def createAndSaveHistogramsForCountries(symptomByBatchcodeTable):
dictByBatchcodeTable = createHistograms(symptomByBatchcodeTable)
explodedTable = MultiIndexExploder.explodeMultiIndexOfTable(dictByBatchcodeTable)
histogramDescriptionTable = HistogramDescriptionTableFactory.createHistogramDescriptionTable(explodedTable)

View File

@@ -18,9 +18,10 @@
"from DateProvider import DateProvider\n",
"from InternationalVaersCovid19Provider import getInternationalVaersCovid19, get_international_VAERSVAX_VAERSSYMPTOMS_Covid19\n",
"from BatchCodeTableHtmlUpdater import updateBatchCodeTableHtmlFile\n",
"from BatchCodeTablePersister import createAndSaveBatchCodeTables\n",
"from BatchCodeTablePersister import createAndSaveGlobalBatchCodeTable\n",
"from SymptomByBatchcodeTableFactory import SymptomByBatchcodeTableFactory\n",
"from HistogramFactoryAndPersister import createAndSaveGlobalHistograms, createAndSaveHistogramsForCountries"
"from HistogramFactoryAndPersister import createAndSaveGlobalHistograms\n",
"from BatchCodeTableFactory import BatchCodeTableFactory"
]
},
{
@@ -120,16 +121,6 @@
"createAndSaveGlobalHistograms(symptomByBatchcodeTable)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f8e42955",
"metadata": {},
"outputs": [],
"source": [
"createAndSaveHistogramsForCountries(symptomByBatchcodeTable)"
]
},
{
"cell_type": "code",
"execution_count": null,
@@ -137,7 +128,7 @@
"metadata": {},
"outputs": [],
"source": [
"internationalVaersCovid19 = getInternationalVaersCovid19(years = years_from_start_of_COVID_vaccination_to_present)\n",
"internationalVaersCovid19 = getInternationalVaersCovid19(dataDir = 'VAERS', years = years_from_start_of_COVID_vaccination_to_present)\n",
"internationalVaersCovid19"
]
},
@@ -148,7 +139,7 @@
"metadata": {},
"outputs": [],
"source": [
"updateBatchCodeTableHtmlFile(internationalVaersCovid19, batchCodeTableHtmlFile=\"../docs/batchCodeTable.html\")"
"updateBatchCodeTableHtmlFile(batchCodeTableHtmlFile=\"../docs/batchCodeTable.html\")"
]
},
{
@@ -158,10 +149,9 @@
"metadata": {},
"outputs": [],
"source": [
"createAndSaveBatchCodeTables(\n",
" internationalVaersCovid19,\n",
"createAndSaveGlobalBatchCodeTable(\n",
" minADRsForLethality = 100,\n",
" onCountryProcessed = display)"
" batchCodeTableFactory = BatchCodeTableFactory(internationalVaersCovid19))"
]
},
{

View File

@@ -1,14 +0,0 @@
def getCountries(internationalVaersCovid19):
return sorted(internationalVaersCovid19['COUNTRY'].unique())
def getCountryOptions(countries):
return ['<option value="Global" selected>Global</option>'] + _getCountryOptions(countries)
def _getCountryOptions(countries):
return [_getCountryOption(country) for country in countries]
def _getCountryOption(country):
return '<option value="{country}">{country}</option>'.format(country=country)

View File

@@ -5,11 +5,11 @@ from VaersDescrReader import VaersDescrReader
from CountryColumnAdder import CountryColumnAdder
def getInternationalVaersCovid19(years):
def getInternationalVaersCovid19(dataDir, years):
internationalVaers = pd.concat(
[
VaersReader.getVaersForYears(years),
VaersReader.getNonDomesticVaers()
VaersReader.getVaersForYears(dataDir, years),
VaersReader.getNonDomesticVaers(dataDir)
])
internationalVaersCovid19 = DataFrameFilter().filterByCovid19(internationalVaers)
return internationalVaersCovid19

View File

@@ -16,7 +16,7 @@ class Splttype2CountryConverter:
lambda splttype:
Splttype2CountryConverter._getCountryNameOfSplttypeOrDefault(
splttype = splttype,
default = 'Unknown Country'))
default = None))
.astype("string"))
@staticmethod

View File

@@ -10,8 +10,7 @@ class SummationTableFactory:
'Adverse Reaction Reports': pd.NamedAgg(column = 'DIED', aggfunc = 'size'),
'Life Threatening Illnesses': pd.NamedAgg(column = 'L_THREAT', aggfunc = 'sum'),
'Disabilities': pd.NamedAgg(column = 'DISABLE', aggfunc = 'sum'),
'Severities': pd.NamedAgg(column = 'SEVERE', aggfunc = 'sum'),
'Countries': pd.NamedAgg(column = 'COUNTRY', aggfunc = SummationTableFactory.countries2str)
'Severities': pd.NamedAgg(column = 'SEVERE', aggfunc = 'sum')
})
summationTable['Severe reports'] = summationTable['Severities'] / summationTable['Adverse Reaction Reports'] * 100
summationTable['Lethality'] = summationTable['Deaths'] / summationTable['Adverse Reaction Reports'] * 100
@@ -22,10 +21,5 @@ class SummationTableFactory:
'Disabilities',
'Life Threatening Illnesses',
'Severe reports',
'Lethality',
'Countries'
'Lethality'
]]
@staticmethod
def countries2str(countries):
return ', '.join(sorted(set(countries)))

View File

@@ -19,9 +19,9 @@ class VaersDescrReader:
def readNonDomesticVaersDescr(self):
return {
'VAERSDATA': self._readVAERSDATA(self.dataDir + "/NonDomesticVAERSDATA.csv"),
'VAERSVAX': self._readVAERSVAX(self.dataDir + "/NonDomesticVAERSVAX.csv"),
'VAERSSYMPTOMS': self._readVAERSSYMPTOMS(self.dataDir + "/NonDomesticVAERSSYMPTOMS.csv")
'VAERSDATA': self._readVAERSDATA(self.dataDir + '/NonDomesticVAERSDATA.csv'),
'VAERSVAX': self._readVAERSVAX(self.dataDir + '/NonDomesticVAERSVAX.csv'),
'VAERSSYMPTOMS': self._readVAERSSYMPTOMS(self.dataDir + '/NonDomesticVAERSSYMPTOMS.csv')
}
def _readVAERSDATA(self, file):
@@ -29,7 +29,7 @@ class VaersDescrReader:
file = file,
usecols = ['VAERS_ID', 'RECVDATE', 'DIED', 'L_THREAT', 'DISABLE', 'HOSPITAL', 'ER_VISIT', 'SPLTTYPE'],
parse_dates = ['RECVDATE'],
date_parser = lambda dateStr: pd.to_datetime(dateStr, format = "%m/%d/%Y"))
date_parser = lambda dateStr: pd.to_datetime(dateStr, format = '%m/%d/%Y'))
DataFrameNormalizer._convertColumnsOfDataFrame_Y_to_1_else_0(
VAERSDATA,
['DIED', 'L_THREAT', 'DISABLE', 'HOSPITAL', 'ER_VISIT'])
@@ -41,8 +41,8 @@ class VaersDescrReader:
usecols = ['VAERS_ID', 'VAX_DOSE_SERIES', 'VAX_TYPE', 'VAX_MANU', 'VAX_LOT'],
dtype =
{
"VAX_DOSE_SERIES": "string",
"VAX_LOT": "string"
'VAX_DOSE_SERIES': 'string',
'VAX_LOT': 'string'
})
DataFrameNormalizer.removeUnknownBatchCodes(VAERSVAX)
DataFrameNormalizer.convertVAX_LOTColumnToUpperCase(VAERSVAX)

View File

@@ -3,23 +3,20 @@ from VaersDescrReader import VaersDescrReader
from VaersDescr2DataFrameConverter import VaersDescr2DataFrameConverter
from SevereColumnAdder import SevereColumnAdder
def getVaersForYears(years):
def getVaersForYears(dataDir, years):
def addCountryColumn(dataFrame):
dataFrame['COUNTRY'] = 'United States'
return dataFrame
return _getVaers(
_getVaersDescrReader().readVaersDescrsForYears(years),
VaersDescrReader(dataDir).readVaersDescrsForYears(years),
addCountryColumn)
def getNonDomesticVaers():
def getNonDomesticVaers(dataDir):
return _getVaers(
[_getVaersDescrReader().readNonDomesticVaersDescr()],
[VaersDescrReader(dataDir).readNonDomesticVaersDescr()],
addCountryColumn = lambda dataFrame: CountryColumnAdder(dataFrame).addCountryColumn(dataFrame))
def _getVaersDescrReader():
return VaersDescrReader(dataDir = "VAERS")
def _getVaers(vaersDescrs, addCountryColumn):
dataFrame = VaersDescr2DataFrameConverter.createDataFrameFromDescrs(vaersDescrs)
dataFrame = addCountryColumn(dataFrame)