removing createAndSaveHistogramsForCountries
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -14,13 +14,13 @@ class BatchCodeTableFactory:
|
||||
dataFrame['VAX_LOT']
|
||||
]))
|
||||
|
||||
def createGlobalBatchCodeTable(self, countriesAsList = False):
|
||||
return self._postProcess(SummationTableFactory.createSummationTable(self.dataFrame.groupby('VAX_LOT')), countriesAsList)
|
||||
def createGlobalBatchCodeTable(self):
|
||||
return self._postProcess(SummationTableFactory.createSummationTable(self.dataFrame.groupby('VAX_LOT')))
|
||||
|
||||
def createBatchCodeTableByCountry(self, country, countriesAsList = False):
|
||||
return self._postProcess(self._getBatchCodeTableByCountry(country), countriesAsList)
|
||||
def createBatchCodeTableByCountry(self, country):
|
||||
return self._postProcess(self._getBatchCodeTableByCountry(country))
|
||||
|
||||
def _postProcess(self, batchCodeTable, countriesAsList):
|
||||
def _postProcess(self, batchCodeTable):
|
||||
batchCodeTable = self.companyColumnAdder.addCompanyColumn(batchCodeTable)
|
||||
batchCodeTable = batchCodeTable[
|
||||
[
|
||||
|
||||
@@ -7,17 +7,75 @@ from BatchCodeTableFactory import BatchCodeTableFactory
|
||||
|
||||
class BatchCodeTableFactoryTest(unittest.TestCase):
|
||||
|
||||
def test_createBatchCodeTableByCountry_countriesAsStr(self):
|
||||
self._createBatchCodeTableByCountry(countriesAsList = False)
|
||||
def test_createBatchCodeTableByCountry(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'],
|
||||
[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, 'France']],
|
||||
index = [
|
||||
"1048786",
|
||||
"1048786",
|
||||
"4711",
|
||||
"0815"])
|
||||
dataFrame = SevereColumnAdder.addSevereColumn(dataFrame)
|
||||
batchCodeTableFactory = BatchCodeTableFactory(dataFrame)
|
||||
|
||||
# When
|
||||
batchCodeTable = batchCodeTableFactory.createBatchCodeTableByCountry('France')
|
||||
|
||||
def test_createBatchCodeTableByCountry_countriesAsList(self):
|
||||
self._createBatchCodeTableByCountry(countriesAsList = True)
|
||||
# Then
|
||||
assert_frame_equal(
|
||||
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', '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 = True)
|
||||
|
||||
def test_createGlobalBatchCodeTable(self):
|
||||
self._createGlobalBatchCodeTable(countriesAsList = False)
|
||||
# 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', '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']],
|
||||
index = [
|
||||
"1048786",
|
||||
"1048786",
|
||||
"4711",
|
||||
"0815"])
|
||||
dataFrame = SevereColumnAdder.addSevereColumn(dataFrame)
|
||||
batchCodeTableFactory = BatchCodeTableFactory(dataFrame)
|
||||
|
||||
# When
|
||||
batchCodeTable = batchCodeTableFactory.createGlobalBatchCodeTable()
|
||||
|
||||
def test_createGlobalBatchCodeTable_countriesAsList(self):
|
||||
self._createGlobalBatchCodeTable(countriesAsList = True)
|
||||
# Then
|
||||
assert_frame_equal(
|
||||
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', 'Severe reports', 'Lethality'],
|
||||
data = [ [1, 1, 0, 0, 'PFIZER\BIONTECH', 1/1 * 100, 1/1 * 100],
|
||||
[2, 1, 2, 2, 'MODERNA', 1/2 * 100],
|
||||
[1, 0, 0, 0, 'MODERNA', 0/1 * 100, 0/1 * 100]],
|
||||
index = pd.Index(
|
||||
[
|
||||
'016M20A',
|
||||
'030L20B',
|
||||
'030L20A'
|
||||
],
|
||||
name = 'VAX_LOT')),
|
||||
check_dtype = True)
|
||||
|
||||
def test_createBatchCodeTableByNonExistingCountry(self):
|
||||
# Given
|
||||
@@ -40,83 +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)
|
||||
|
||||
def _createBatchCodeTableByCountry(self, countriesAsList):
|
||||
# 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'],
|
||||
[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, 'France']],
|
||||
index = [
|
||||
"1048786",
|
||||
"1048786",
|
||||
"4711",
|
||||
"0815"])
|
||||
dataFrame = SevereColumnAdder.addSevereColumn(dataFrame)
|
||||
batchCodeTableFactory = BatchCodeTableFactory(dataFrame)
|
||||
|
||||
# When
|
||||
batchCodeTable = batchCodeTableFactory.createBatchCodeTableByCountry('France', countriesAsList)
|
||||
|
||||
# Then
|
||||
france = self._convertCountries(['France'], countriesAsList)
|
||||
assert_frame_equal(
|
||||
batchCodeTable[['Adverse Reaction Reports', 'Deaths', 'Disabilities', 'Life Threatening Illnesses', 'Company', 'Countries', '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]],
|
||||
index = pd.Index(
|
||||
[
|
||||
'030L20B',
|
||||
'030L20A'
|
||||
],
|
||||
name = 'VAX_LOT')),
|
||||
check_dtype = True)
|
||||
|
||||
def _createGlobalBatchCodeTable(self, countriesAsList):
|
||||
# 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', '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']],
|
||||
index = [
|
||||
"1048786",
|
||||
"1048786",
|
||||
"4711",
|
||||
"0815"])
|
||||
dataFrame = SevereColumnAdder.addSevereColumn(dataFrame)
|
||||
batchCodeTableFactory = BatchCodeTableFactory(dataFrame)
|
||||
|
||||
# When
|
||||
batchCodeTable = batchCodeTableFactory.createGlobalBatchCodeTable(countriesAsList)
|
||||
|
||||
# Then
|
||||
assert_frame_equal(
|
||||
batchCodeTable[['Adverse Reaction Reports', 'Deaths', 'Disabilities', 'Life Threatening Illnesses', 'Company', 'Countries', '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', self._convertCountries([], countriesAsList), 1/1 * 100, 1/1 * 100],
|
||||
[2, 1, 2, 2, 'MODERNA', self._convertCountries(['France', 'United Kingdom'], countriesAsList), 2/2 * 100, 1/2 * 100],
|
||||
[1, 0, 0, 0, 'MODERNA', self._convertCountries(['France'], countriesAsList), 0/1 * 100, 0/1 * 100]],
|
||||
index = pd.Index(
|
||||
[
|
||||
'016M20A',
|
||||
'030L20B',
|
||||
'030L20A'
|
||||
],
|
||||
name = 'VAX_LOT')),
|
||||
check_dtype = True)
|
||||
|
||||
def _convertCountries(self, countries, countriesAsList):
|
||||
return ', '.join(countries) if not countriesAsList else countries
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
from CountriesMerger import CountriesMerger
|
||||
from CountriesByBatchcodeProvider import getCountriesByBatchcodeBeforeDeletion
|
||||
from BatchCodeTableFactory import BatchCodeTableFactory
|
||||
|
||||
class BatchCodeTableHavingGuessedCountriesFactory:
|
||||
|
||||
def __init__(self, batchCodeTableFactoryDelegate):
|
||||
self.batchCodeTableFactoryDelegate = batchCodeTableFactoryDelegate
|
||||
self.countriesByBatchcodeBeforeDeletion = getCountriesByBatchcodeBeforeDeletion()
|
||||
|
||||
def createGlobalBatchCodeTable(self, countriesAsList = False):
|
||||
batchCodeTable = self.batchCodeTableFactoryDelegate.createGlobalBatchCodeTable(countriesAsList = True)
|
||||
self._guessCountries(batchCodeTable, countriesAsList)
|
||||
return batchCodeTable
|
||||
|
||||
def createBatchCodeTableByCountry(self, country, countriesAsList = False):
|
||||
batchCodeTable = self.batchCodeTableFactoryDelegate.createBatchCodeTableByCountry(country, countriesAsList = True)
|
||||
self._guessCountries(batchCodeTable, countriesAsList)
|
||||
return batchCodeTable
|
||||
|
||||
def _guessCountries(self, batchCodeTable, countriesAsList):
|
||||
batchCodeTable['Countries'] = CountriesMerger.mergeSrcIntoDst(
|
||||
dst = batchCodeTable['Countries'],
|
||||
src = self.countriesByBatchcodeBeforeDeletion['Countries'])
|
||||
@@ -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(
|
||||
|
||||
@@ -1,18 +1,11 @@
|
||||
from IOUtils import IOUtils
|
||||
import numpy as np
|
||||
from HtmlUtils import getCountries
|
||||
|
||||
|
||||
def createAndSaveBatchCodeTables(
|
||||
internationalVaersCovid19,
|
||||
minADRsForLethality,
|
||||
batchCodeTableFactory,
|
||||
onCountryProcessed = lambda country: None):
|
||||
_createAndSaveBatchCodeTablesForCountries(
|
||||
createBatchCodeTableForCountry = lambda country: batchCodeTableFactory.createBatchCodeTableByCountry(country),
|
||||
countries = getCountries(internationalVaersCovid19),
|
||||
minADRsForLethality = minADRsForLethality,
|
||||
onCountryProcessed = onCountryProcessed)
|
||||
_createAndSaveBatchCodeTableForCountry(
|
||||
createBatchCodeTableForCountry = lambda country: batchCodeTableFactory.createGlobalBatchCodeTable(),
|
||||
country = 'Global',
|
||||
@@ -37,7 +30,6 @@ def _createAndSaveBatchCodeTableForCountry(createBatchCodeTableForCountry, count
|
||||
'Disabilities',
|
||||
'Life Threatening Illnesses',
|
||||
'Company',
|
||||
'Countries',
|
||||
'Severe reports',
|
||||
'Lethality'
|
||||
]]
|
||||
@@ -45,8 +37,3 @@ def _createAndSaveBatchCodeTableForCountry(createBatchCodeTableForCountry, count
|
||||
batchCodeTable,
|
||||
'../docs/data/batchCodeTables/' + country + '.json')
|
||||
onCountryProcessed(country)
|
||||
|
||||
|
||||
def _createAndSaveBatchCodeTablesForCountries(createBatchCodeTableForCountry, countries, minADRsForLethality, onCountryProcessed):
|
||||
for country in countries:
|
||||
_createAndSaveBatchCodeTableForCountry(createBatchCodeTableForCountry, country, minADRsForLethality, onCountryProcessed)
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
import pandas as pd
|
||||
|
||||
|
||||
class CompletedBatchcodeColumnAdder:
|
||||
|
||||
def __init__(self, completeBatchcode):
|
||||
self.completeBatchcode = completeBatchcode
|
||||
|
||||
def addCompletedBatchcodeColumn(self, tableByPartialBatchcode):
|
||||
partialBatchcodeTable = tableByPartialBatchcode.index.to_frame()
|
||||
partialBatchcodeTable['Completed Batchcode'] = partialBatchcodeTable[tableByPartialBatchcode.index.name].map(self.completeBatchcode)
|
||||
return tableByPartialBatchcode.set_index(pd.MultiIndex.from_frame(partialBatchcodeTable))
|
||||
@@ -1,39 +0,0 @@
|
||||
import unittest
|
||||
from TestHelper import TestHelper
|
||||
from pandas.testing import assert_frame_equal
|
||||
import pandas as pd
|
||||
from CompletedBatchcodeColumnAdder import CompletedBatchcodeColumnAdder
|
||||
|
||||
class CompletedBatchcodeColumnAdderTest(unittest.TestCase):
|
||||
|
||||
def test_addCompletedBatchcodeColumn(self):
|
||||
# Given
|
||||
def completeBatchcode(partialBatchcode):
|
||||
if partialBatchcode == '30L20B':
|
||||
return '30L20B_COMPLETION'
|
||||
|
||||
tableByPartialBatchcode = TestHelper.createDataFrame(
|
||||
columns = pd.MultiIndex.from_tuples(
|
||||
names = ['Country', 'Region'],
|
||||
tuples = [['United Kingdom', 'England']]),
|
||||
data = [ [4711]],
|
||||
index = pd.Index(
|
||||
name = 'Batchcode Search Term',
|
||||
data = ['30L20B']))
|
||||
completedBatchcodeColumnAdder = CompletedBatchcodeColumnAdder(completeBatchcode)
|
||||
|
||||
# When
|
||||
dataFrameWithCompletedBatchcodeColumn = completedBatchcodeColumnAdder.addCompletedBatchcodeColumn(tableByPartialBatchcode)
|
||||
|
||||
# Then
|
||||
assert_frame_equal(
|
||||
dataFrameWithCompletedBatchcodeColumn,
|
||||
TestHelper.createDataFrame(
|
||||
columns = pd.MultiIndex.from_tuples(
|
||||
names = ['Country', 'Region'],
|
||||
tuples = [['United Kingdom', 'England']]),
|
||||
data = [ [4711]],
|
||||
index = pd.MultiIndex.from_tuples(
|
||||
names = ['Batchcode Search Term', 'Completed Batchcode'],
|
||||
tuples = [['30L20B', '30L20B_COMPLETION']])))
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
import pandas as pd
|
||||
from CompletedBatchcodeColumnAdder import CompletedBatchcodeColumnAdder
|
||||
from BatchcodeCompletion import BatchcodeCompletion
|
||||
from CountriesColumnAdder import CountriesColumnAdder
|
||||
from BatchCodeTableFactory import BatchCodeTableFactory
|
||||
from InternationalVaersCovid19Provider import getInternationalVaersCovid19
|
||||
|
||||
def getCountriesByCompletedBatchcode(internationalVaersCovid19):
|
||||
result = _readExploration('data/Country By Batchcode Search Term.csv', indexName = 'Batchcode Search Term')
|
||||
result = _addCompletedBatchcodeColumn(result, internationalVaersCovid19)
|
||||
columnName = 'Countries'
|
||||
result = CountriesColumnAdder().addCountriesColumn(result, columnName = columnName)
|
||||
return result[[columnName]].droplevel('Batchcode Search Term')
|
||||
|
||||
def _addCompletedBatchcodeColumn(country_By_Batchcode_Search_Term, internationalVaersCovid19):
|
||||
return CompletedBatchcodeColumnAdder(_getCompleteBatchcode(internationalVaersCovid19)).addCompletedBatchcodeColumn(country_By_Batchcode_Search_Term)
|
||||
|
||||
def _getCompleteBatchcode(internationalVaersCovid19):
|
||||
batchCodeTable = BatchCodeTableFactory(internationalVaersCovid19).createGlobalBatchCodeTable()
|
||||
return BatchcodeCompletion(ADR_by_Batchcode = batchCodeTable).completeBatchcode
|
||||
|
||||
def getCountriesByClickedBatchcode():
|
||||
result = _readExploration('data/Country By Clicked Batchcode.csv', indexName = 'Clicked Batchcode')
|
||||
columnName = 'Countries'
|
||||
result = CountriesColumnAdder().addCountriesColumn(result, columnName = columnName)
|
||||
return result[[columnName]]
|
||||
|
||||
def _readExploration(csvFile, indexName):
|
||||
exploration = pd.read_csv(csvFile, header=[0], index_col=0, skiprows=6, on_bad_lines='warn')
|
||||
exploration.drop(index=indexName, inplace=True)
|
||||
exploration.index.rename(indexName, inplace=True)
|
||||
exploration.drop(columns='Totals', inplace=True)
|
||||
for column in exploration.columns:
|
||||
exploration[column] = exploration[column].astype('int64')
|
||||
return exploration
|
||||
|
||||
def getCountriesByBatchcodeBeforeDeletion():
|
||||
internationalVaersCovid19 = getInternationalVaersCovid19(dataDir = 'VAERS/VAERSBeforeDeletion', years = [2020, 2021, 2022])
|
||||
batchCodeTable = BatchCodeTableFactory(internationalVaersCovid19).createGlobalBatchCodeTable(countriesAsList = True)
|
||||
return batchCodeTable[['Countries']]
|
||||
@@ -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')
|
||||
@@ -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))
|
||||
@@ -6,10 +6,10 @@ from HistogramDescriptionTableFactory import HistogramDescriptionTableFactory
|
||||
|
||||
def createAndSaveGlobalHistograms(symptomByBatchcodeTable):
|
||||
symptomByBatchcodeTable = symptomByBatchcodeTable.assign(COUNTRY = 'Global')
|
||||
createAndSaveHistogramsForCountries(symptomByBatchcodeTable)
|
||||
_createAndSaveHistogramsForCountries(symptomByBatchcodeTable)
|
||||
|
||||
|
||||
def createAndSaveHistogramsForCountries(symptomByBatchcodeTable):
|
||||
def _createAndSaveHistogramsForCountries(symptomByBatchcodeTable):
|
||||
dictByBatchcodeTable = createHistograms(symptomByBatchcodeTable)
|
||||
explodedTable = MultiIndexExploder.explodeMultiIndexOfTable(dictByBatchcodeTable)
|
||||
histogramDescriptionTable = HistogramDescriptionTableFactory.createHistogramDescriptionTable(explodedTable)
|
||||
|
||||
@@ -20,9 +20,8 @@
|
||||
"from BatchCodeTableHtmlUpdater import updateBatchCodeTableHtmlFile\n",
|
||||
"from BatchCodeTablePersister import createAndSaveBatchCodeTables\n",
|
||||
"from SymptomByBatchcodeTableFactory import SymptomByBatchcodeTableFactory\n",
|
||||
"from HistogramFactoryAndPersister import createAndSaveGlobalHistograms, createAndSaveHistogramsForCountries\n",
|
||||
"from BatchCodeTableFactory import BatchCodeTableFactory\n",
|
||||
"from BatchCodeTableHavingGuessedCountriesFactory import BatchCodeTableHavingGuessedCountriesFactory\n"
|
||||
"from HistogramFactoryAndPersister import createAndSaveGlobalHistograms\n",
|
||||
"from BatchCodeTableFactory import BatchCodeTableFactory"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -122,16 +121,6 @@
|
||||
"createAndSaveGlobalHistograms(symptomByBatchcodeTable)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "f8e42955",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"createAndSaveHistogramsForCountries(symptomByBatchcodeTable)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -150,7 +139,7 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"updateBatchCodeTableHtmlFile(internationalVaersCovid19, batchCodeTableHtmlFile=\"../docs/batchCodeTable.html\")"
|
||||
"updateBatchCodeTableHtmlFile(batchCodeTableHtmlFile=\"../docs/batchCodeTable.html\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -161,9 +150,8 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"createAndSaveBatchCodeTables(\n",
|
||||
" internationalVaersCovid19,\n",
|
||||
" minADRsForLethality = 100,\n",
|
||||
" batchCodeTableFactory = BatchCodeTableHavingGuessedCountriesFactory(BatchCodeTableFactory(internationalVaersCovid19)),\n",
|
||||
" batchCodeTableFactory = BatchCodeTableFactory(internationalVaersCovid19),\n",
|
||||
" onCountryProcessed = display)"
|
||||
]
|
||||
},
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
def getCountries(internationalVaersCovid19):
|
||||
return sorted(internationalVaersCovid19['COUNTRY'].dropna().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)
|
||||
@@ -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.sortCountries)
|
||||
'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 sortCountries(countries):
|
||||
return sorted(set(countries.dropna()))
|
||||
Reference in New Issue
Block a user