refactoring
This commit is contained in:
@@ -439,8 +439,8 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from SymptomsCausedByVaccines.HtmlUpdater import updateHtmlFile\n",
|
||||
"from SymptomsCausedByVaccines.PrrByVaccineBySymptomFactory import PrrByVaccineBySymptomFactory\n",
|
||||
"from SymptomsCausedByVaccines.PrrByVaccineBySymptomTransformer import PrrByVaccineBySymptomTransformer\n",
|
||||
"from src.SymptomsCausedByVaccines.PrrSeriesFactory import PrrSeriesFactory\n",
|
||||
"from src.SymptomsCausedByVaccines.PrrSeriesTransformer import PrrSeriesTransformer\n",
|
||||
"from SymptomsCausedByVaccines.ProportionalReportingRatiosPersister import saveProportionalReportingRatios\n",
|
||||
"import os\n",
|
||||
"import pandas as pd"
|
||||
@@ -467,10 +467,21 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"prrByVaccineBySymptom = PrrByVaccineBySymptomFactory.getPrrByVaccineBySymptom(prrByVaccineAndSymptom)\n",
|
||||
"prrByVaccineBySymptom = PrrSeriesFactory.getPrrByVaccineBySymptom(prrByVaccineAndSymptom)\n",
|
||||
"prrByVaccineBySymptom"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "0f247c64",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"prrBySymptomByVaccine = PrrSeriesFactory.getPrrBySymptomByVaccine(prrByVaccineAndSymptom)\n",
|
||||
"prrBySymptomByVaccine"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -478,10 +489,21 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"prrByVaccineBySymptomWithoutZeroPrrs = PrrByVaccineBySymptomTransformer.removeNonZeroPrrs(prrByVaccineBySymptom)\n",
|
||||
"prrByVaccineBySymptomWithoutZeroPrrs = PrrSeriesTransformer.filterByNonZeroPrrs(prrByVaccineBySymptom)\n",
|
||||
"prrByVaccineBySymptomWithoutZeroPrrs"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "f07203e4",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"prrBySymptomByVaccineWithHighPrrs = PrrSeriesTransformer.filterByHighPrrs(prrBySymptomByVaccine)\n",
|
||||
"prrBySymptomByVaccineWithHighPrrs"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -491,7 +513,19 @@
|
||||
"source": [
|
||||
"saveProportionalReportingRatios(\n",
|
||||
" prrByVaccineBySymptomWithoutZeroPrrs,\n",
|
||||
" directory = os.path.normpath(os.getcwd() + '/../docs/data/ProportionalReportingRatios/'))"
|
||||
" directory = os.path.normpath(os.getcwd() + '/../docs/data/ProportionalReportingRatios/symptoms'))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "fac4b34f",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"saveProportionalReportingRatios(\n",
|
||||
" prrBySymptomByVaccineWithHighPrrs,\n",
|
||||
" directory = os.path.normpath(os.getcwd() + '/../docs/data/ProportionalReportingRatios/vaccines'))"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
class PrrByVaccineBySymptomFactory:
|
||||
|
||||
@staticmethod
|
||||
def getPrrByVaccineBySymptom(prrByVaccineAndSymptom):
|
||||
return prrByVaccineAndSymptom.apply(lambda prrByVaccine: prrByVaccine.to_dict())
|
||||
@@ -1,32 +0,0 @@
|
||||
import unittest
|
||||
from pandas.testing import assert_series_equal
|
||||
from TestHelper import TestHelper
|
||||
import pandas as pd
|
||||
from SymptomsCausedByVaccines.PrrByVaccineBySymptomFactory import PrrByVaccineBySymptomFactory
|
||||
|
||||
class PrrByVaccineBySymptomFactoryTest(unittest.TestCase):
|
||||
|
||||
def test_getPrrByVaccineBySymptom(self):
|
||||
# Given
|
||||
prrByVaccineAndSymptom = TestHelper.createDataFrame(
|
||||
columns = ['11-beta-hydroxylase deficiency', '17-hydroxyprogesterone'],
|
||||
data = [ [0.6, 1.5],
|
||||
[0.3, 3.0]],
|
||||
index = pd.Index(
|
||||
name = 'VAX_TYPE',
|
||||
data = [
|
||||
'6VAX-F',
|
||||
'ADEN'
|
||||
]))
|
||||
|
||||
# When
|
||||
prrByVaccineBySymptom = PrrByVaccineBySymptomFactory.getPrrByVaccineBySymptom(prrByVaccineAndSymptom)
|
||||
|
||||
# Then
|
||||
assert_series_equal(
|
||||
prrByVaccineBySymptom,
|
||||
pd.Series(
|
||||
{
|
||||
'11-beta-hydroxylase deficiency': {'6VAX-F': 0.6, 'ADEN': 0.3},
|
||||
'17-hydroxyprogesterone': {'6VAX-F': 1.5, 'ADEN': 3.0}
|
||||
}))
|
||||
@@ -1,6 +0,0 @@
|
||||
class PrrByVaccineBySymptomTransformer:
|
||||
|
||||
@staticmethod
|
||||
def removeNonZeroPrrs(prrByVaccineBySymptom):
|
||||
return prrByVaccineBySymptom.map(
|
||||
lambda prrByVaccine: {vaccine: prr for vaccine, prr in prrByVaccine.items() if prr != 0})
|
||||
@@ -1,26 +0,0 @@
|
||||
import unittest
|
||||
from pandas.testing import assert_series_equal
|
||||
import pandas as pd
|
||||
from SymptomsCausedByVaccines.PrrByVaccineBySymptomTransformer import PrrByVaccineBySymptomTransformer
|
||||
|
||||
class PrrByVaccineBySymptomTransformerTest(unittest.TestCase):
|
||||
|
||||
def test_filterByNonZeroPrrs(self):
|
||||
# Given
|
||||
prrByVaccineBySymptom = pd.Series(
|
||||
{
|
||||
'11-beta-hydroxylase deficiency': {'6VAX-F': 0.0, 'ADEN': 0.3},
|
||||
'17-hydroxyprogesterone': {'6VAX-F': 1.5, 'ADEN': 0.0}
|
||||
})
|
||||
|
||||
# When
|
||||
prrByVaccineBySymptomWithoutZeroPrrs = PrrByVaccineBySymptomTransformer.removeNonZeroPrrs(prrByVaccineBySymptom)
|
||||
|
||||
# Then
|
||||
assert_series_equal(
|
||||
prrByVaccineBySymptomWithoutZeroPrrs,
|
||||
pd.Series(
|
||||
{
|
||||
'11-beta-hydroxylase deficiency': {'ADEN': 0.3},
|
||||
'17-hydroxyprogesterone': {'6VAX-F': 1.5}
|
||||
}))
|
||||
11
src/SymptomsCausedByVaccines/PrrSeriesFactory.py
Normal file
11
src/SymptomsCausedByVaccines/PrrSeriesFactory.py
Normal file
@@ -0,0 +1,11 @@
|
||||
class PrrSeriesFactory:
|
||||
|
||||
@staticmethod
|
||||
def getPrrByVaccineBySymptom(prrByVaccineAndSymptom):
|
||||
return prrByVaccineAndSymptom.apply(lambda prrByVaccine: prrByVaccine.to_dict())
|
||||
|
||||
@staticmethod
|
||||
def getPrrBySymptomByVaccine(prrByVaccineAndSymptom):
|
||||
return prrByVaccineAndSymptom.apply(
|
||||
lambda prrBySymptom: prrBySymptom.to_dict(),
|
||||
axis = 'columns')
|
||||
58
src/SymptomsCausedByVaccines/PrrSeriesFactoryTest.py
Normal file
58
src/SymptomsCausedByVaccines/PrrSeriesFactoryTest.py
Normal file
@@ -0,0 +1,58 @@
|
||||
import unittest
|
||||
from pandas.testing import assert_series_equal
|
||||
from TestHelper import TestHelper
|
||||
import pandas as pd
|
||||
from SymptomsCausedByVaccines.PrrSeriesFactory import PrrSeriesFactory
|
||||
|
||||
class PrrSeriesFactoryTest(unittest.TestCase):
|
||||
|
||||
def test_getPrrByVaccineBySymptom(self):
|
||||
# Given
|
||||
prrByVaccineAndSymptom = TestHelper.createDataFrame(
|
||||
columns = ['11-beta-hydroxylase deficiency', '17-hydroxyprogesterone'],
|
||||
data = [ [0.6, 1.5],
|
||||
[0.3, 3.0]],
|
||||
index = pd.Index(
|
||||
name = 'VAX_TYPE',
|
||||
data = [
|
||||
'6VAX-F',
|
||||
'ADEN'
|
||||
]))
|
||||
|
||||
# When
|
||||
prrByVaccineBySymptom = PrrSeriesFactory.getPrrByVaccineBySymptom(prrByVaccineAndSymptom)
|
||||
|
||||
# Then
|
||||
assert_series_equal(
|
||||
prrByVaccineBySymptom,
|
||||
pd.Series(
|
||||
{
|
||||
'11-beta-hydroxylase deficiency': {'6VAX-F': 0.6, 'ADEN': 0.3},
|
||||
'17-hydroxyprogesterone': {'6VAX-F': 1.5, 'ADEN': 3.0}
|
||||
}))
|
||||
|
||||
def test_getPrrBySymptomByVaccine(self):
|
||||
# Given
|
||||
prrByVaccineAndSymptom = TestHelper.createDataFrame(
|
||||
columns = ['11-beta-hydroxylase deficiency', '17-hydroxyprogesterone'],
|
||||
data = [ [0.6, 1.5],
|
||||
[1.3, 2.5]],
|
||||
index = pd.Index(
|
||||
name = 'VAX_TYPE',
|
||||
data = [
|
||||
'6VAX-F',
|
||||
'ADEN'
|
||||
]))
|
||||
|
||||
# When
|
||||
prrBySymptomByVaccine = PrrSeriesFactory.getPrrBySymptomByVaccine(prrByVaccineAndSymptom)
|
||||
|
||||
# Then
|
||||
assert_series_equal(
|
||||
prrBySymptomByVaccine,
|
||||
TestHelper.createSeries(
|
||||
indexName = 'VAX_TYPE',
|
||||
data = {
|
||||
'6VAX-F': {'11-beta-hydroxylase deficiency': 0.6, '17-hydroxyprogesterone': 1.5},
|
||||
'ADEN': {'11-beta-hydroxylase deficiency': 1.3, '17-hydroxyprogesterone': 2.5}
|
||||
}))
|
||||
18
src/SymptomsCausedByVaccines/PrrSeriesTransformer.py
Normal file
18
src/SymptomsCausedByVaccines/PrrSeriesTransformer.py
Normal file
@@ -0,0 +1,18 @@
|
||||
class PrrSeriesTransformer:
|
||||
|
||||
@staticmethod
|
||||
def filterByNonZeroPrrs(prrByVaccineBySymptom):
|
||||
return PrrSeriesTransformer._filterPrrsBy(
|
||||
prrByVaccineBySymptom,
|
||||
lambda prr: prr != 0)
|
||||
|
||||
@staticmethod
|
||||
def filterByHighPrrs(prrBySymptomByVaccine):
|
||||
return PrrSeriesTransformer._filterPrrsBy(
|
||||
prrBySymptomByVaccine,
|
||||
lambda prr: prr > 1)
|
||||
|
||||
@staticmethod
|
||||
def _filterPrrsBy(prrByKeyByOtherKey, prrFilter):
|
||||
return prrByKeyByOtherKey.map(
|
||||
lambda prrByKey: {key: prr for key, prr in prrByKey.items() if prrFilter(prr)})
|
||||
46
src/SymptomsCausedByVaccines/PrrSeriesTransformerTest.py
Normal file
46
src/SymptomsCausedByVaccines/PrrSeriesTransformerTest.py
Normal file
@@ -0,0 +1,46 @@
|
||||
import unittest
|
||||
from pandas.testing import assert_series_equal
|
||||
import pandas as pd
|
||||
from SymptomsCausedByVaccines.PrrSeriesTransformer import PrrSeriesTransformer
|
||||
|
||||
class PrrSeriesTransformerTest(unittest.TestCase):
|
||||
|
||||
def test_filterByNonZeroPrrs(self):
|
||||
# Given
|
||||
prrByVaccineBySymptom = pd.Series(
|
||||
{
|
||||
'11-beta-hydroxylase deficiency': {'6VAX-F': 0.0, 'ADEN': 0.3},
|
||||
'17-hydroxyprogesterone': {'6VAX-F': 1.5, 'ADEN': 0.0}
|
||||
})
|
||||
|
||||
# When
|
||||
prrByVaccineBySymptomWithoutZeroPrrs = PrrSeriesTransformer.filterByNonZeroPrrs(prrByVaccineBySymptom)
|
||||
|
||||
# Then
|
||||
assert_series_equal(
|
||||
prrByVaccineBySymptomWithoutZeroPrrs,
|
||||
pd.Series(
|
||||
{
|
||||
'11-beta-hydroxylase deficiency': {'ADEN': 0.3},
|
||||
'17-hydroxyprogesterone': {'6VAX-F': 1.5}
|
||||
}))
|
||||
|
||||
def test_filterByHighPrrs(self):
|
||||
# Given
|
||||
prrBySymptomByVaccine = pd.Series(
|
||||
{
|
||||
'6VAX-F': {'11-beta-hydroxylase deficiency': 0.6, '17-hydroxyprogesterone': 1.5},
|
||||
'ADEN': {'11-beta-hydroxylase deficiency': 1.3, '17-hydroxyprogesterone': 0.9}
|
||||
})
|
||||
|
||||
# When
|
||||
prrBySymptomByVaccineWithHighPrrs = PrrSeriesTransformer.filterByHighPrrs(prrBySymptomByVaccine)
|
||||
|
||||
# Then
|
||||
assert_series_equal(
|
||||
prrBySymptomByVaccineWithHighPrrs,
|
||||
pd.Series(
|
||||
{
|
||||
'6VAX-F': {'17-hydroxyprogesterone': 1.5},
|
||||
'ADEN': {'11-beta-hydroxylase deficiency': 1.3}
|
||||
}))
|
||||
Reference in New Issue
Block a user