refactoring
This commit is contained in:
14
src/HistogramFactory.py
Normal file
14
src/HistogramFactory.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from SymptomHistogramByBatchcodeTableFactory import SymptomHistogramByBatchcodeTableFactory
|
||||
from HistogramTable2DictTableConverter import HistogramTable2DictTableConverter
|
||||
|
||||
|
||||
def createGlobalHistograms(symptomByBatchcodeTable):
|
||||
symptomHistogramByBatchcodeTable = SymptomHistogramByBatchcodeTableFactory.createGlobalSymptomHistogramByBatchcodeTable(symptomByBatchcodeTable)
|
||||
dictByBatchcodeTable = HistogramTable2DictTableConverter.convertGlobalHistogramTable2DictTable(symptomHistogramByBatchcodeTable)
|
||||
return dictByBatchcodeTable
|
||||
|
||||
|
||||
def createHistograms(symptomByBatchcodeTable):
|
||||
symptomHistogramByBatchcodeTable = SymptomHistogramByBatchcodeTableFactory.createSymptomHistogramByBatchcodeTable(symptomByBatchcodeTable)
|
||||
dictByBatchcodeTable = HistogramTable2DictTableConverter.convertHistogramTable2DictTable(symptomHistogramByBatchcodeTable)
|
||||
return dictByBatchcodeTable
|
||||
24
src/HistogramFactoryAndPersister.py
Normal file
24
src/HistogramFactoryAndPersister.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from HistogramFactory import createGlobalHistograms, createHistograms
|
||||
from HistogramPersister import saveHistograms
|
||||
|
||||
|
||||
def createAndSaveGlobalHistograms(symptomByBatchcodeTable):
|
||||
dictByBatchcodeTable4Country = createGlobalHistograms(symptomByBatchcodeTable)
|
||||
saveHistograms(dictByBatchcodeTable4Country, 'Global')
|
||||
|
||||
|
||||
def createAndSaveHistogramsForCountries(symptomByBatchcodeTable, countries):
|
||||
dictByBatchcodeTable = createHistograms(symptomByBatchcodeTable)
|
||||
for count, country in enumerate(countries, start = 1):
|
||||
_createAndSaveHistogramsForCountry(
|
||||
count = count,
|
||||
numCountries = len(countries),
|
||||
country = country,
|
||||
dictByBatchcodeTable = dictByBatchcodeTable)
|
||||
|
||||
|
||||
def _createAndSaveHistogramsForCountry(count, numCountries, country, dictByBatchcodeTable):
|
||||
# FK-TODO: use https://github.com/tqdm/tqdm
|
||||
print(f'saving histograms for country {count}/{numCountries}: {country}')
|
||||
dictByBatchcodeTable4Country = dictByBatchcodeTable[dictByBatchcodeTable['COUNTRY'] == country]
|
||||
saveHistograms(dictByBatchcodeTable4Country, country)
|
||||
13
src/HistogramPersister.py
Normal file
13
src/HistogramPersister.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from MultiIndexValuesProvider import MultiIndexValuesProvider
|
||||
from HistogramDescriptionPersister import HistogramDescriptionPersister
|
||||
import shutil
|
||||
|
||||
def saveHistograms(dictByBatchcodeTable4Country, country):
|
||||
batchcodes = MultiIndexValuesProvider.getValues(dictByBatchcodeTable4Country.index)
|
||||
batchcodes = {batchcode for batchcode in batchcodes if batchcode != 'nan'}
|
||||
directory = f'../docs/data/histograms/{country}'
|
||||
shutil.rmtree(directory, ignore_errors = True)
|
||||
HistogramDescriptionPersister(directory).saveHistogramDescriptionsForBatchcodes(
|
||||
batchcodes,
|
||||
dictByBatchcodeTable4Country,
|
||||
progress = lambda count, size, batchcode: print(f'{count}/{size}: {batchcode}'))
|
||||
@@ -18,7 +18,10 @@
|
||||
"from DateProvider import DateProvider\n",
|
||||
"from InternationalVaersCovid19Provider import getInternationalVaersCovid19, get_international_VAERSVAX_VAERSSYMPTOMS_Covid19\n",
|
||||
"from BatchCodeTableHtmlUpdater import updateBatchCodeTableHtmlFile\n",
|
||||
"from BatchCodeTablePersister import createAndSaveBatchCodeTables"
|
||||
"from BatchCodeTablePersister import createAndSaveBatchCodeTables\n",
|
||||
"from SymptomByBatchcodeTableFactory import SymptomByBatchcodeTableFactory\n",
|
||||
"from HistogramFactoryAndPersister import createAndSaveGlobalHistograms, createAndSaveHistogramsForCountries\n",
|
||||
"from HtmlUtils import getCountries"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -104,8 +107,6 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from SymptomByBatchcodeTableFactory import SymptomByBatchcodeTableFactory\n",
|
||||
"\n",
|
||||
"symptomByBatchcodeTable = SymptomByBatchcodeTableFactory.createSymptomByBatchcodeTable(international_VAERSVAX_Covid19, international_VAERSSYMPTOMS)\n",
|
||||
"symptomByBatchcodeTable"
|
||||
]
|
||||
@@ -113,76 +114,21 @@
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "5997ee59",
|
||||
"id": "23731536",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"isGlobal = False"
|
||||
"createAndSaveGlobalHistograms(symptomByBatchcodeTable)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "9268d60d",
|
||||
"id": "f8e42955",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from SymptomHistogramByBatchcodeTableFactory import SymptomHistogramByBatchcodeTableFactory\n",
|
||||
"\n",
|
||||
"symptomHistogramByBatchcodeTable = SymptomHistogramByBatchcodeTableFactory.createGlobalSymptomHistogramByBatchcodeTable(symptomByBatchcodeTable) if isGlobal else SymptomHistogramByBatchcodeTableFactory.createSymptomHistogramByBatchcodeTable(symptomByBatchcodeTable)\n",
|
||||
"symptomHistogramByBatchcodeTable"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "5170efad",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from HistogramTable2DictTableConverter import HistogramTable2DictTableConverter\n",
|
||||
"\n",
|
||||
"dictByBatchcodeTable = HistogramTable2DictTableConverter.convertGlobalHistogramTable2DictTable(symptomHistogramByBatchcodeTable) if isGlobal else HistogramTable2DictTableConverter.convertHistogramTable2DictTable(symptomHistogramByBatchcodeTable)\n",
|
||||
"dictByBatchcodeTable"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "a57e0fd5",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from HtmlUtils import getCountries\n",
|
||||
"from MultiIndexValuesProvider import MultiIndexValuesProvider\n",
|
||||
"from HistogramDescriptionPersister import HistogramDescriptionPersister\n",
|
||||
"import shutil\n",
|
||||
"\n",
|
||||
"if isGlobal:\n",
|
||||
" batchcodes = MultiIndexValuesProvider.getValues(dictByBatchcodeTable.index)\n",
|
||||
" batchcodes = {batchcode for batchcode in batchcodes if batchcode != 'nan'}\n",
|
||||
" directory = f'../docs/data/histograms/Global'\n",
|
||||
" shutil.rmtree(directory, ignore_errors = True)\n",
|
||||
" histogramDescriptionPersister = HistogramDescriptionPersister(directory)\n",
|
||||
" histogramDescriptionPersister.saveHistogramDescriptionsForBatchcodes(\n",
|
||||
" batchcodes,\n",
|
||||
" dictByBatchcodeTable,\n",
|
||||
" progress = lambda count, size, batchcode: print(f'{count}/{size}: {batchcode}'))\n",
|
||||
"else:\n",
|
||||
" countries = getCountries(international_VAERSVAX_Covid19)\n",
|
||||
" for count, country in enumerate(countries, start = 1):\n",
|
||||
" # FK-TODO: use https://github.com/tqdm/tqdm\n",
|
||||
" print(f'saving histograms for country {count}/{len(countries)}: {country}')\n",
|
||||
" dictByBatchcodeTable4Country = dictByBatchcodeTable[dictByBatchcodeTable['COUNTRY'] == country]\n",
|
||||
" batchcodes = MultiIndexValuesProvider.getValues(dictByBatchcodeTable4Country.index)\n",
|
||||
" batchcodes = {batchcode for batchcode in batchcodes if batchcode != 'nan'}\n",
|
||||
" directory = f'../docs/data/histograms/{country}'\n",
|
||||
" shutil.rmtree(directory, ignore_errors = True)\n",
|
||||
" histogramDescriptionPersister = HistogramDescriptionPersister(directory)\n",
|
||||
" histogramDescriptionPersister.saveHistogramDescriptionsForBatchcodes(\n",
|
||||
" batchcodes,\n",
|
||||
" dictByBatchcodeTable4Country,\n",
|
||||
" progress = lambda count, size, batchcode: print(f'{count}/{size}: {batchcode}'))"
|
||||
"createAndSaveHistogramsForCountries(symptomByBatchcodeTable, getCountries(international_VAERSVAX_Covid19))"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user