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 { class GoogleAnalytics {
static click_batchcode(batchcode) { static click_batchcode(batchcode) {
gtag( // FK-TODO: uncomment
'event', // gtag(
'click_batchcode', // 'event',
{ // 'click_batchcode',
'batchcode': batchcode // {
}); // 'batchcode': batchcode
// });
} }
static view_search_results(search_term) { static view_search_results(search_term) {
gtag( // FK-TODO: uncomment
'event', // gtag(
'view_search_results', // 'event',
{ // 'view_search_results',
'search_term': search_term // {
}); // 'search_term': search_term
} // });
static countrySelected(country) {
gtag(
"event",
"select_item",
{
item_list_id: "countrySelect",
items: [
{
item_id: country,
}
]
});
} }
} }

View File

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

View File

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

File diff suppressed because one or more lines are too long

View File

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

File diff suppressed because one or more lines are too long

View File

@@ -6,13 +6,6 @@ class BatchCodeTableFactory:
def __init__(self, dataFrame: pd.DataFrame): def __init__(self, dataFrame: pd.DataFrame):
self.dataFrame = dataFrame self.dataFrame = dataFrame
self.companyColumnAdder = CompanyColumnAdder(dataFrame)
self.countryBatchCodeTable = SummationTableFactory.createSummationTable(
dataFrame.groupby(
[
dataFrame['COUNTRY'],
dataFrame['VAX_LOT']
]))
def createGlobalBatchCodeTable(self): def createGlobalBatchCodeTable(self):
return self._postProcess(SummationTableFactory.createSummationTable(self.dataFrame.groupby('VAX_LOT'))) return self._postProcess(SummationTableFactory.createSummationTable(self.dataFrame.groupby('VAX_LOT')))
@@ -21,7 +14,7 @@ class BatchCodeTableFactory:
return self._postProcess(self._getBatchCodeTableByCountry(country)) return self._postProcess(self._getBatchCodeTableByCountry(country))
def _postProcess(self, batchCodeTable): def _postProcess(self, batchCodeTable):
batchCodeTable = self.companyColumnAdder.addCompanyColumn(batchCodeTable) batchCodeTable = CompanyColumnAdder(self.dataFrame).addCompanyColumn(batchCodeTable)
batchCodeTable = batchCodeTable[ batchCodeTable = batchCodeTable[
[ [
'Adverse Reaction Reports', 'Adverse Reaction Reports',
@@ -29,17 +22,22 @@ class BatchCodeTableFactory:
'Disabilities', 'Disabilities',
'Life Threatening Illnesses', 'Life Threatening Illnesses',
'Company', 'Company',
'Countries',
'Severe reports', 'Severe reports',
'Lethality' 'Lethality'
]] ]]
return batchCodeTable.sort_values(by = 'Severe reports', ascending = False) return batchCodeTable.sort_values(by = 'Severe reports', ascending = False)
def _getBatchCodeTableByCountry(self, country): def _getBatchCodeTableByCountry(self, country):
if country in self.countryBatchCodeTable.index: countryBatchCodeTable = self._getCountryBatchCodeTable()
return self.countryBatchCodeTable.loc[country] return countryBatchCodeTable.loc[country] if country in countryBatchCodeTable.index else self._getEmptyBatchCodeTable(countryBatchCodeTable)
else:
return self._getEmptyBatchCodeTable()
def _getEmptyBatchCodeTable(self): def _getCountryBatchCodeTable(self):
return self.countryBatchCodeTable[0:0].droplevel(0) 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 # Then
assert_frame_equal( 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( 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 = [ [2, 1, 2, 2, 'MODERNA', 'France', 2/2 * 100, 1/2 * 100], data = [ [2, 1, 2, 2, 'MODERNA', 2/2 * 100, 1/2 * 100],
[1, 0, 0, 0, 'MODERNA', 'France', 0/1 * 100, 0/1 * 100]], [1, 0, 0, 0, 'MODERNA', 0/1 * 100, 0/1 * 100]],
index = pd.Index( index = pd.Index(
[ [
'030L20B', '030L20B',
'030L20A' '030L20A'
], ],
name = 'VAX_LOT')), name = 'VAX_LOT')),
check_dtype = False) check_dtype = True)
def test_createGlobalBatchCodeTable(self): def test_createGlobalBatchCodeTable(self):
# Given # Given
dataFrame = TestHelper.createDataFrame( dataFrame = TestHelper.createDataFrame(
columns = ['DIED', 'L_THREAT', 'DISABLE', 'VAX_TYPE', 'VAX_MANU', 'VAX_LOT', 'VAX_DOSE_SERIES', 'SPLTTYPE', 'HOSPITAL', 'ER_VISIT', 'COUNTRY'], 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'], [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'], [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']], [0, 1, 1, 'COVID19', 'MODERNA', '030L20B', '1', 'FRMODERNATX, INC.MOD20224', 0, 0, 'United Kingdom']],
@@ -62,12 +62,12 @@ class BatchCodeTableFactoryTest(unittest.TestCase):
# Then # Then
assert_frame_equal( 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( 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 = [ [1, 1, 0, 0, 'PFIZER\BIONTECH', 'United Kingdom', 1/1 * 100, 1/1 * 100], data = [ [1, 1, 0, 0, 'PFIZER\BIONTECH', 1/1 * 100, 1/1 * 100],
[2, 1, 2, 2, 'MODERNA', 'France, United Kingdom', 2/2 * 100, 1/2 * 100], [2, 1, 2, 2, 'MODERNA', 2/2 * 100, 1/2 * 100],
[1, 0, 0, 0, 'MODERNA', 'France', 0/1 * 100, 0/1 * 100]], [1, 0, 0, 0, 'MODERNA', 0/1 * 100, 0/1 * 100]],
index = pd.Index( index = pd.Index(
[ [
'016M20A', '016M20A',
@@ -75,7 +75,7 @@ class BatchCodeTableFactoryTest(unittest.TestCase):
'030L20A' '030L20A'
], ],
name = 'VAX_LOT')), name = 'VAX_LOT')),
check_dtype = False) check_dtype = True)
def test_createBatchCodeTableByNonExistingCountry(self): def test_createBatchCodeTableByNonExistingCountry(self):
# Given # Given
@@ -98,9 +98,9 @@ class BatchCodeTableFactoryTest(unittest.TestCase):
# Then # Then
assert_frame_equal( 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( 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 = [ ], data = [ ],
index = pd.Index([], name = 'VAX_LOT')), index = pd.Index([], name = 'VAX_LOT')),
check_dtype = False) check_dtype = False)

View File

@@ -1,30 +1,14 @@
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from HtmlTransformerUtil import HtmlTransformerUtil from HtmlTransformerUtil import HtmlTransformerUtil
from CountryOptionsSetter import CountryOptionsSetter
from DateProvider import DateProvider from DateProvider import DateProvider
from HtmlUtils import getCountryOptions, getCountries
from DateProvider import DateProvider from DateProvider import DateProvider
def updateBatchCodeTableHtmlFile(internationalVaersCovid19, batchCodeTableHtmlFile): def updateBatchCodeTableHtmlFile(batchCodeTableHtmlFile):
countryOptions = getCountryOptions(getCountries(internationalVaersCovid19))
_saveCountryOptions(countryOptions, batchCodeTableHtmlFile)
_saveLastUpdatedBatchCodeTable( _saveLastUpdatedBatchCodeTable(
DateProvider().getLastUpdatedDataSource(), DateProvider().getLastUpdatedDataSource(),
batchCodeTableHtmlFile) 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 _saveLastUpdatedBatchCodeTable(lastUpdated, batchCodeTableHtmlFile):
def setLastUpdated(soup): def setLastUpdated(soup):
soup.find(id="last_updated").string.replace_with( soup.find(id="last_updated").string.replace_with(

View File

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

View File

@@ -32,7 +32,7 @@ class CountryColumnAdderTest(unittest.TestCase):
columns = ['SPLTTYPE', 'COUNTRY'], columns = ['SPLTTYPE', 'COUNTRY'],
data = [ ['GBPFIZER INC2020486806', 'United Kingdom'], data = [ ['GBPFIZER INC2020486806', 'United Kingdom'],
['FRMODERNATX, INC.MOD20224', 'France'], ['FRMODERNATX, INC.MOD20224', 'France'],
['dummy', 'Unknown Country']], ['dummy', None]],
index = pd.Index( index = pd.Index(
name = 'VAERS_ID', name = 'VAERS_ID',
data = [ data = [

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): def createAndSaveGlobalHistograms(symptomByBatchcodeTable):
symptomByBatchcodeTable = symptomByBatchcodeTable.assign(COUNTRY = 'Global') symptomByBatchcodeTable = symptomByBatchcodeTable.assign(COUNTRY = 'Global')
createAndSaveHistogramsForCountries(symptomByBatchcodeTable)
def createAndSaveHistogramsForCountries(symptomByBatchcodeTable):
dictByBatchcodeTable = createHistograms(symptomByBatchcodeTable) dictByBatchcodeTable = createHistograms(symptomByBatchcodeTable)
explodedTable = MultiIndexExploder.explodeMultiIndexOfTable(dictByBatchcodeTable) explodedTable = MultiIndexExploder.explodeMultiIndexOfTable(dictByBatchcodeTable)
histogramDescriptionTable = HistogramDescriptionTableFactory.createHistogramDescriptionTable(explodedTable) histogramDescriptionTable = HistogramDescriptionTableFactory.createHistogramDescriptionTable(explodedTable)

View File

@@ -18,9 +18,10 @@
"from DateProvider import DateProvider\n", "from DateProvider import DateProvider\n",
"from InternationalVaersCovid19Provider import getInternationalVaersCovid19, get_international_VAERSVAX_VAERSSYMPTOMS_Covid19\n", "from InternationalVaersCovid19Provider import getInternationalVaersCovid19, get_international_VAERSVAX_VAERSSYMPTOMS_Covid19\n",
"from BatchCodeTableHtmlUpdater import updateBatchCodeTableHtmlFile\n", "from BatchCodeTableHtmlUpdater import updateBatchCodeTableHtmlFile\n",
"from BatchCodeTablePersister import createAndSaveBatchCodeTables\n", "from BatchCodeTablePersister import createAndSaveGlobalBatchCodeTable\n",
"from SymptomByBatchcodeTableFactory import SymptomByBatchcodeTableFactory\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)" "createAndSaveGlobalHistograms(symptomByBatchcodeTable)"
] ]
}, },
{
"cell_type": "code",
"execution_count": null,
"id": "f8e42955",
"metadata": {},
"outputs": [],
"source": [
"createAndSaveHistogramsForCountries(symptomByBatchcodeTable)"
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
@@ -137,7 +128,7 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "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" "internationalVaersCovid19"
] ]
}, },
@@ -148,7 +139,7 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"updateBatchCodeTableHtmlFile(internationalVaersCovid19, batchCodeTableHtmlFile=\"../docs/batchCodeTable.html\")" "updateBatchCodeTableHtmlFile(batchCodeTableHtmlFile=\"../docs/batchCodeTable.html\")"
] ]
}, },
{ {
@@ -158,10 +149,9 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"createAndSaveBatchCodeTables(\n", "createAndSaveGlobalBatchCodeTable(\n",
" internationalVaersCovid19,\n",
" minADRsForLethality = 100,\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 from CountryColumnAdder import CountryColumnAdder
def getInternationalVaersCovid19(years): def getInternationalVaersCovid19(dataDir, years):
internationalVaers = pd.concat( internationalVaers = pd.concat(
[ [
VaersReader.getVaersForYears(years), VaersReader.getVaersForYears(dataDir, years),
VaersReader.getNonDomesticVaers() VaersReader.getNonDomesticVaers(dataDir)
]) ])
internationalVaersCovid19 = DataFrameFilter().filterByCovid19(internationalVaers) internationalVaersCovid19 = DataFrameFilter().filterByCovid19(internationalVaers)
return internationalVaersCovid19 return internationalVaersCovid19

View File

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

View File

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

View File

@@ -19,9 +19,9 @@ class VaersDescrReader:
def readNonDomesticVaersDescr(self): def readNonDomesticVaersDescr(self):
return { return {
'VAERSDATA': self._readVAERSDATA(self.dataDir + "/NonDomesticVAERSDATA.csv"), 'VAERSDATA': self._readVAERSDATA(self.dataDir + '/NonDomesticVAERSDATA.csv'),
'VAERSVAX': self._readVAERSVAX(self.dataDir + "/NonDomesticVAERSVAX.csv"), 'VAERSVAX': self._readVAERSVAX(self.dataDir + '/NonDomesticVAERSVAX.csv'),
'VAERSSYMPTOMS': self._readVAERSSYMPTOMS(self.dataDir + "/NonDomesticVAERSSYMPTOMS.csv") 'VAERSSYMPTOMS': self._readVAERSSYMPTOMS(self.dataDir + '/NonDomesticVAERSSYMPTOMS.csv')
} }
def _readVAERSDATA(self, file): def _readVAERSDATA(self, file):
@@ -29,7 +29,7 @@ class VaersDescrReader:
file = file, file = file,
usecols = ['VAERS_ID', 'RECVDATE', 'DIED', 'L_THREAT', 'DISABLE', 'HOSPITAL', 'ER_VISIT', 'SPLTTYPE'], usecols = ['VAERS_ID', 'RECVDATE', 'DIED', 'L_THREAT', 'DISABLE', 'HOSPITAL', 'ER_VISIT', 'SPLTTYPE'],
parse_dates = ['RECVDATE'], 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( DataFrameNormalizer._convertColumnsOfDataFrame_Y_to_1_else_0(
VAERSDATA, VAERSDATA,
['DIED', 'L_THREAT', 'DISABLE', 'HOSPITAL', 'ER_VISIT']) ['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'], usecols = ['VAERS_ID', 'VAX_DOSE_SERIES', 'VAX_TYPE', 'VAX_MANU', 'VAX_LOT'],
dtype = dtype =
{ {
"VAX_DOSE_SERIES": "string", 'VAX_DOSE_SERIES': 'string',
"VAX_LOT": "string" 'VAX_LOT': 'string'
}) })
DataFrameNormalizer.removeUnknownBatchCodes(VAERSVAX) DataFrameNormalizer.removeUnknownBatchCodes(VAERSVAX)
DataFrameNormalizer.convertVAX_LOTColumnToUpperCase(VAERSVAX) DataFrameNormalizer.convertVAX_LOTColumnToUpperCase(VAERSVAX)

View File

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