refactoring
This commit is contained in:
@@ -5,44 +5,25 @@ import numpy as np
|
|||||||
class BarChartDescriptionTables:
|
class BarChartDescriptionTables:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def filterValidJensenShannonDistances(barChartDescriptionTable):
|
def filter(barChartDescriptionTable, predicate):
|
||||||
return BarChartDescriptionTables._filter(
|
return barChartDescriptionTable[barChartDescriptionTable.apply(
|
||||||
barChartDescriptionTable,
|
lambda barChartDescription: predicate(
|
||||||
BarChartDescriptionTables._isValidJensenShannonDistance)
|
barChartDescription['BAR_CHART_DESCRIPTION']),
|
||||||
|
axis='columns')]
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _isValidJensenShannonDistance(barChartDescription):
|
def isValidJensenShannonDistance(barChartDescription):
|
||||||
jensenShannonDistance = barChartDescription['Jensen-Shannon distance']
|
jensenShannonDistance = barChartDescription['Jensen-Shannon distance']
|
||||||
return not math.isnan(jensenShannonDistance)
|
return not math.isnan(jensenShannonDistance)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def filterHasMinSizeOfGuessedHistogram(barChartDescriptionTable, minSizeOfGuessedHistogram):
|
def hasMinSizeOfGuessedHistogram(barChartDescription, minSizeOfGuessedHistogram):
|
||||||
return BarChartDescriptionTables._filter(
|
|
||||||
barChartDescriptionTable,
|
|
||||||
lambda barChartDescription:
|
|
||||||
BarChartDescriptionTables._hasMinSizeOfGuessedHistogram(barChartDescription, minSizeOfGuessedHistogram))
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _hasMinSizeOfGuessedHistogram(barChartDescription, minSizeOfGuessedHistogram):
|
|
||||||
sizeOfGuessedHistogram = sum(
|
sizeOfGuessedHistogram = sum(
|
||||||
barChartDescription['Adverse Reaction Reports guessed'])
|
barChartDescription['Adverse Reaction Reports guessed'])
|
||||||
return sizeOfGuessedHistogram >= minSizeOfGuessedHistogram
|
return sizeOfGuessedHistogram >= minSizeOfGuessedHistogram
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def filterHasCountryWithGuessedGreaterThanKnown(barChartDescriptionTable):
|
def hasCountryWithGuessedGreaterThanKnown(barChartDescription):
|
||||||
return BarChartDescriptionTables._filter(
|
|
||||||
barChartDescriptionTable,
|
|
||||||
BarChartDescriptionTables._hasCountryWithGuessedGreaterThanKnown)
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _hasCountryWithGuessedGreaterThanKnown(barChartDescription):
|
|
||||||
guessedBarChart = barChartDescription['Adverse Reaction Reports guessed']
|
guessedBarChart = barChartDescription['Adverse Reaction Reports guessed']
|
||||||
knownBarChart = barChartDescription['Adverse Reaction Reports known']
|
knownBarChart = barChartDescription['Adverse Reaction Reports known']
|
||||||
return np.any(np.asarray(guessedBarChart) > np.asarray(knownBarChart))
|
return np.any(np.asarray(guessedBarChart) > np.asarray(knownBarChart))
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _filter(barChartDescriptionTable, predicate):
|
|
||||||
return barChartDescriptionTable[barChartDescriptionTable.apply(
|
|
||||||
lambda barChartDescription: predicate(
|
|
||||||
barChartDescription['BAR_CHART_DESCRIPTION']),
|
|
||||||
axis='columns')]
|
|
||||||
|
|||||||
@@ -38,8 +38,9 @@ class BarChartDescriptionTablesTest(unittest.TestCase):
|
|||||||
name='VAX_LOT'))
|
name='VAX_LOT'))
|
||||||
|
|
||||||
# When
|
# When
|
||||||
barChartDescriptionTableResult = BarChartDescriptionTables.filterValidJensenShannonDistances(
|
barChartDescriptionTableResult = BarChartDescriptionTables.filter(
|
||||||
barChartDescriptionTable)
|
barChartDescriptionTable,
|
||||||
|
BarChartDescriptionTables.isValidJensenShannonDistance)
|
||||||
|
|
||||||
# Then
|
# Then
|
||||||
assert_frame_equal(
|
assert_frame_equal(
|
||||||
@@ -84,8 +85,12 @@ class BarChartDescriptionTablesTest(unittest.TestCase):
|
|||||||
name='VAX_LOT'))
|
name='VAX_LOT'))
|
||||||
|
|
||||||
# When
|
# When
|
||||||
barChartDescriptionTableResult = BarChartDescriptionTables.filterHasMinSizeOfGuessedHistogram(
|
barChartDescriptionTableResult = BarChartDescriptionTables.filter(
|
||||||
barChartDescriptionTable, 20)
|
barChartDescriptionTable,
|
||||||
|
lambda barChartDescription:
|
||||||
|
BarChartDescriptionTables.hasMinSizeOfGuessedHistogram(
|
||||||
|
barChartDescription,
|
||||||
|
minSizeOfGuessedHistogram=20))
|
||||||
|
|
||||||
# Then
|
# Then
|
||||||
assert_frame_equal(
|
assert_frame_equal(
|
||||||
@@ -114,8 +119,12 @@ class BarChartDescriptionTablesTest(unittest.TestCase):
|
|||||||
name='VAX_LOT'))
|
name='VAX_LOT'))
|
||||||
|
|
||||||
# When
|
# When
|
||||||
barChartDescriptionTableResult = BarChartDescriptionTables.filterHasMinSizeOfGuessedHistogram(
|
barChartDescriptionTableResult = BarChartDescriptionTables.filter(
|
||||||
barChartDescriptionTable, 31)
|
barChartDescriptionTable,
|
||||||
|
lambda barChartDescription:
|
||||||
|
BarChartDescriptionTables.hasMinSizeOfGuessedHistogram(
|
||||||
|
barChartDescription,
|
||||||
|
minSizeOfGuessedHistogram=31))
|
||||||
|
|
||||||
# Then
|
# Then
|
||||||
assert_frame_equal(
|
assert_frame_equal(
|
||||||
@@ -159,8 +168,9 @@ class BarChartDescriptionTablesTest(unittest.TestCase):
|
|||||||
name='VAX_LOT'))
|
name='VAX_LOT'))
|
||||||
|
|
||||||
# When
|
# When
|
||||||
barChartDescriptionTableResult = BarChartDescriptionTables.filterHasCountryWithGuessedGreaterThanKnown(
|
barChartDescriptionTableResult = BarChartDescriptionTables.filter(
|
||||||
barChartDescriptionTable)
|
barChartDescriptionTable,
|
||||||
|
BarChartDescriptionTables.hasCountryWithGuessedGreaterThanKnown)
|
||||||
|
|
||||||
# Then
|
# Then
|
||||||
assert_frame_equal(
|
assert_frame_equal(
|
||||||
|
|||||||
Reference in New Issue
Block a user