starting PrrByVaccineTableFactoryTest
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,15 @@
|
|||||||
|
class BatchCodeSelectInitializer {
|
||||||
|
|
||||||
|
static initialize({batchCodeSelectElement, batchCodeDetailsElement}) {
|
||||||
|
const batchCodeDetailsView = new BatchCodeDetailsView(batchCodeDetailsElement);
|
||||||
|
batchCodeSelectElement.select2({ minimumInputLength: 4 });
|
||||||
|
batchCodeSelectElement.on(
|
||||||
|
'select2:select',
|
||||||
|
function (event) {
|
||||||
|
const batchcode = event.params.data.id;
|
||||||
|
batchCodeDetailsView.displayBatchCodeDetails(batchcode);
|
||||||
|
GoogleAnalytics.click_batchcode(batchcode);
|
||||||
|
});
|
||||||
|
batchCodeSelectElement.select2('open');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -433,7 +433,7 @@
|
|||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"from SymptomsCausedByVaccines.HtmlUpdater import updateHtmlFile\n",
|
"from SymptomsCausedByVaccines.HtmlUpdater import updateHtmlFile\n",
|
||||||
"from SymptomsCausedByVaccines.Analyzer import Analyzer\n",
|
"from SymptomsCausedByVaccines.PrrByVaccineTableFactory import PrrByVaccineTableFactory\n",
|
||||||
"import pandas as pd"
|
"import pandas as pd"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -444,21 +444,11 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"symptomByVaccine = pd.read_csv(\n",
|
"prrByVaccineAndSymptom = pd.read_csv(\n",
|
||||||
" 'data/ratings-1990-2022.csv',\n",
|
" 'data/prr-ratios-all-vaccines.csv',\n",
|
||||||
" index_col = 'VAX_TYPE',\n",
|
" index_col = 'VAX_TYPE',\n",
|
||||||
" usecols = lambda columnName: columnName != 'Unnamed: 0')\n",
|
" usecols = lambda columnName: columnName != 'Unnamed: 0')\n",
|
||||||
"# symptomByVaccine"
|
"prrByVaccineAndSymptom"
|
||||||
]
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"cell_type": "code",
|
|
||||||
"execution_count": null,
|
|
||||||
"id": "90bde4c8",
|
|
||||||
"metadata": {},
|
|
||||||
"outputs": [],
|
|
||||||
"source": [
|
|
||||||
"symptomByVaccine.loc['COVID19'].sum()"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -468,13 +458,9 @@
|
|||||||
"metadata": {},
|
"metadata": {},
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
"source": [
|
"source": [
|
||||||
"analyzer = Analyzer(symptomByVaccine)\n",
|
|
||||||
"\n",
|
|
||||||
"updateHtmlFile(\n",
|
"updateHtmlFile(\n",
|
||||||
" vaccines = analyzer.getVaccines(),\n",
|
" symptoms = list(prrByVaccineAndSymptom.columns),\n",
|
||||||
" symptoms = analyzer.getSymptoms(),\n",
|
" htmlFile = \"../docs/SymptomsCausedByVaccines/index.html\")"
|
||||||
" htmlFile = \"../docs/SymptomsCausedByVaccines/index.html\",\n",
|
|
||||||
" lastUpdated = dateProvider.getLastUpdatedDataSource())"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -1,18 +0,0 @@
|
|||||||
import pandas as pd
|
|
||||||
|
|
||||||
class Analyzer:
|
|
||||||
|
|
||||||
def __init__(self, symptomByVaccine: pd.DataFrame):
|
|
||||||
self.symptomByVaccine = symptomByVaccine
|
|
||||||
|
|
||||||
def getSymptomsForVaccine(self, vaxType):
|
|
||||||
return self.symptomByVaccine.loc[vaxType]
|
|
||||||
|
|
||||||
def getVaccinesForSymptom(self, symptom):
|
|
||||||
return self.symptomByVaccine[symptom]
|
|
||||||
|
|
||||||
def getVaccines(self):
|
|
||||||
return list(self.symptomByVaccine.index)
|
|
||||||
|
|
||||||
def getSymptoms(self):
|
|
||||||
return list(self.symptomByVaccine.columns)
|
|
||||||
@@ -1,98 +0,0 @@
|
|||||||
import unittest
|
|
||||||
from pandas.testing import assert_series_equal
|
|
||||||
from TestHelper import TestHelper
|
|
||||||
import pandas as pd
|
|
||||||
from SymptomsCausedByVaccines.Analyzer import Analyzer
|
|
||||||
|
|
||||||
class AnalyzerTest(unittest.TestCase):
|
|
||||||
|
|
||||||
def test_getSymptomsForVaccine(self):
|
|
||||||
# Given
|
|
||||||
symptomByVaccine = TestHelper.createDataFrame(
|
|
||||||
columns = ['11-beta-hydroxylase deficiency', '17-hydroxyprogesterone'],
|
|
||||||
data = [ [0.6, 0.4]],
|
|
||||||
index = pd.Index(
|
|
||||||
name = 'VAX_TYPE',
|
|
||||||
data = ['6VAX-F']))
|
|
||||||
|
|
||||||
analyzer = Analyzer(symptomByVaccine)
|
|
||||||
|
|
||||||
# When
|
|
||||||
symptomsForVaccine = analyzer.getSymptomsForVaccine('6VAX-F')
|
|
||||||
|
|
||||||
# Then
|
|
||||||
assert_series_equal(
|
|
||||||
symptomsForVaccine,
|
|
||||||
pd.Series(
|
|
||||||
name = '6VAX-F',
|
|
||||||
data = {
|
|
||||||
'11-beta-hydroxylase deficiency': 0.6,
|
|
||||||
'17-hydroxyprogesterone': 0.4
|
|
||||||
}))
|
|
||||||
|
|
||||||
def test_getVaccinesForSymptom(self):
|
|
||||||
# Given
|
|
||||||
symptomByVaccine = TestHelper.createDataFrame(
|
|
||||||
columns = ['11-beta-hydroxylase deficiency'],
|
|
||||||
data = [ [0.6],
|
|
||||||
[0.3]],
|
|
||||||
index = pd.Index(
|
|
||||||
name = 'VAX_TYPE',
|
|
||||||
data = [
|
|
||||||
'6VAX-F',
|
|
||||||
'ADEN'
|
|
||||||
]))
|
|
||||||
|
|
||||||
analyzer = Analyzer(symptomByVaccine)
|
|
||||||
|
|
||||||
# When
|
|
||||||
vaccinesForSymptom = analyzer.getVaccinesForSymptom('11-beta-hydroxylase deficiency')
|
|
||||||
|
|
||||||
# Then
|
|
||||||
assert_series_equal(
|
|
||||||
vaccinesForSymptom,
|
|
||||||
TestHelper.createSeries(
|
|
||||||
name = '11-beta-hydroxylase deficiency',
|
|
||||||
data = {
|
|
||||||
'6VAX-F': 0.6,
|
|
||||||
'ADEN': 0.3
|
|
||||||
},
|
|
||||||
indexName = 'VAX_TYPE'))
|
|
||||||
|
|
||||||
def test_getVaccines(self):
|
|
||||||
# Given
|
|
||||||
symptomByVaccine = TestHelper.createDataFrame(
|
|
||||||
columns = ['11-beta-hydroxylase deficiency'],
|
|
||||||
data = [ [0.6],
|
|
||||||
[0.3]],
|
|
||||||
index = pd.Index(
|
|
||||||
name = 'VAX_TYPE',
|
|
||||||
data = [
|
|
||||||
'6VAX-F',
|
|
||||||
'ADEN'
|
|
||||||
]))
|
|
||||||
|
|
||||||
analyzer = Analyzer(symptomByVaccine)
|
|
||||||
|
|
||||||
# When
|
|
||||||
vaccines = analyzer.getVaccines()
|
|
||||||
|
|
||||||
# Then
|
|
||||||
self.assertEqual(vaccines, ['6VAX-F', 'ADEN'])
|
|
||||||
|
|
||||||
def test_getSymptoms(self):
|
|
||||||
# Given
|
|
||||||
symptomByVaccine = TestHelper.createDataFrame(
|
|
||||||
columns = ['11-beta-hydroxylase deficiency', '17-hydroxyprogesterone'],
|
|
||||||
data = [ [0.6, 0.4]],
|
|
||||||
index = pd.Index(
|
|
||||||
name = 'VAX_TYPE',
|
|
||||||
data = ['6VAX-F']))
|
|
||||||
|
|
||||||
analyzer = Analyzer(symptomByVaccine)
|
|
||||||
|
|
||||||
# When
|
|
||||||
symptoms = analyzer.getSymptoms()
|
|
||||||
|
|
||||||
# Then
|
|
||||||
self.assertEqual(symptoms, ['11-beta-hydroxylase deficiency', '17-hydroxyprogesterone'])
|
|
||||||
@@ -1,26 +1,16 @@
|
|||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from HtmlTransformerUtil import HtmlTransformerUtil
|
from HtmlTransformerUtil import HtmlTransformerUtil
|
||||||
from DateProvider import DateProvider
|
from DateProvider import DateProvider
|
||||||
from SymptomsCausedByVaccines.HtmlUtils import getVaccineOptions, getSymptomOptions
|
from SymptomsCausedByVaccines.HtmlUtils import getSymptomOptions
|
||||||
from SymptomsCausedByVaccines.OptionsSetter import OptionsSetter
|
from SymptomsCausedByVaccines.OptionsSetter import OptionsSetter
|
||||||
|
|
||||||
|
|
||||||
def updateHtmlFile(vaccines, symptoms, htmlFile, lastUpdated):
|
def updateHtmlFile(symptoms, htmlFile):
|
||||||
_saveOptions(
|
|
||||||
options = getVaccineOptions(vaccines),
|
|
||||||
htmlFile = htmlFile,
|
|
||||||
selectElementId = 'vaccineSelect')
|
|
||||||
|
|
||||||
_saveOptions(
|
_saveOptions(
|
||||||
options = getSymptomOptions(symptoms),
|
options = getSymptomOptions(symptoms),
|
||||||
htmlFile = htmlFile,
|
htmlFile = htmlFile,
|
||||||
selectElementId = 'symptomSelect')
|
selectElementId = 'symptomSelect')
|
||||||
|
|
||||||
saveLastUpdated2HtmlFile(
|
|
||||||
lastUpdated = lastUpdated,
|
|
||||||
htmlFile = htmlFile,
|
|
||||||
lastUpdatedElementId = 'last_updated')
|
|
||||||
|
|
||||||
def _saveOptions(options, htmlFile, selectElementId):
|
def _saveOptions(options, htmlFile, selectElementId):
|
||||||
HtmlTransformerUtil().applySoupTransformerToFile(
|
HtmlTransformerUtil().applySoupTransformerToFile(
|
||||||
file=htmlFile,
|
file=htmlFile,
|
||||||
@@ -32,6 +22,7 @@ def _saveOptions(options, htmlFile, selectElementId):
|
|||||||
options = options),
|
options = options),
|
||||||
'lxml'))
|
'lxml'))
|
||||||
|
|
||||||
|
# FK-TODO: move saveLastUpdated2HtmlFile() to src/BatchCodeTableHtmlUpdater.py
|
||||||
def saveLastUpdated2HtmlFile(lastUpdated, htmlFile, lastUpdatedElementId):
|
def saveLastUpdated2HtmlFile(lastUpdated, htmlFile, lastUpdatedElementId):
|
||||||
def setLastUpdated(soup):
|
def setLastUpdated(soup):
|
||||||
soup.find(id = lastUpdatedElementId).string.replace_with(
|
soup.find(id = lastUpdatedElementId).string.replace_with(
|
||||||
|
|||||||
11
src/SymptomsCausedByVaccines/PrrByVaccineTableFactory.py
Normal file
11
src/SymptomsCausedByVaccines/PrrByVaccineTableFactory.py
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import pandas as pd
|
||||||
|
|
||||||
|
|
||||||
|
class PrrByVaccineTableFactory:
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def getPrrByVaccineTable(prrByVaccineAndSymptom):
|
||||||
|
return pd.DataFrame(
|
||||||
|
columns = ['11-beta-hydroxylase deficiency'],
|
||||||
|
data = [ [prrByVaccineAndSymptom['11-beta-hydroxylase deficiency'].to_dict()]],
|
||||||
|
index = pd.Index(['PrrByVaccine']))
|
||||||
31
src/SymptomsCausedByVaccines/PrrByVaccineTableFactoryTest.py
Normal file
31
src/SymptomsCausedByVaccines/PrrByVaccineTableFactoryTest.py
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
import unittest
|
||||||
|
from pandas.testing import assert_frame_equal
|
||||||
|
from TestHelper import TestHelper
|
||||||
|
import pandas as pd
|
||||||
|
from SymptomsCausedByVaccines.PrrByVaccineTableFactory import PrrByVaccineTableFactory
|
||||||
|
|
||||||
|
class PrrByVaccineTableFactoryTest(unittest.TestCase):
|
||||||
|
|
||||||
|
def test_getPrrByVaccineTable(self):
|
||||||
|
# Given
|
||||||
|
prrByVaccineAndSymptom = TestHelper.createDataFrame(
|
||||||
|
columns = ['11-beta-hydroxylase deficiency'],
|
||||||
|
data = [ [0.6],
|
||||||
|
[0.3]],
|
||||||
|
index = pd.Index(
|
||||||
|
name = 'VAX_TYPE',
|
||||||
|
data = [
|
||||||
|
'6VAX-F',
|
||||||
|
'ADEN'
|
||||||
|
]))
|
||||||
|
|
||||||
|
# When
|
||||||
|
prrByVaccineTable = PrrByVaccineTableFactory.getPrrByVaccineTable(prrByVaccineAndSymptom)
|
||||||
|
|
||||||
|
# Then
|
||||||
|
assert_frame_equal(
|
||||||
|
prrByVaccineTable,
|
||||||
|
TestHelper.createDataFrame(
|
||||||
|
columns = ['11-beta-hydroxylase deficiency'],
|
||||||
|
data = [ [{'6VAX-F': 0.6, 'ADEN': 0.3}]],
|
||||||
|
index = pd.Index(['PrrByVaccine'])))
|
||||||
99
src/data/prr-ratios-all-vaccines.csv
Normal file
99
src/data/prr-ratios-all-vaccines.csv
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user