Files
HowBadIsMyBatch/src/HowBadIsMyBatch.ipynb
frankknoll 6f2f901dca formating
2023-02-11 12:30:54 +01:00

262 lines
7.9 KiB
Plaintext

{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "9de5907f-18f5-4cb1-903e-26028ff1fa03",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"\n",
"pd.set_option('display.max_rows', 100)\n",
"pd.set_option('display.max_columns', None)\n",
"\n",
"import os\n",
"from VAERSFileDownloader import updateVAERSFiles\n",
"from datetime import datetime\n",
"from DateProvider import DateProvider\n",
"from InternationalVaersCovid19Provider import getInternationalVaersCovid19, get_international_VAERSVAX_VAERSSYMPTOMS_Covid19\n",
"from BatchCodeTableHtmlUpdater import updateBatchCodeTableHtmlFile\n",
"from BatchCodeTablePersister import createAndSaveBatchCodeTables"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d1e4fa9e",
"metadata": {},
"outputs": [],
"source": [
"print(datetime.now().strftime(\"%d.%m.%Y, %H:%M:%S Uhr\"))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ffad1c04",
"metadata": {},
"outputs": [],
"source": [
"dateProvider = DateProvider()\n",
"print(' lastUpdated:', dateProvider.getLastUpdated())\n",
"print('lastUpdatedDataSource:', dateProvider.getLastUpdatedDataSource())\n",
"needsUpdate = dateProvider.needsUpdate()\n",
"print('needsUpdate:', needsUpdate)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "194b7357",
"metadata": {},
"outputs": [],
"source": [
"years_from_2020_to_present = list(range(2020, datetime.now().year + 1))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a793dff0",
"metadata": {},
"outputs": [],
"source": [
"updateVAERSFiles(\n",
" years = years_from_2020_to_present,\n",
" workingDirectory = os.getcwd())"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "58333a19",
"metadata": {},
"outputs": [],
"source": [
"international_VAERSVAX_Covid19, international_VAERSSYMPTOMS = get_international_VAERSVAX_VAERSSYMPTOMS_Covid19(years = years_from_2020_to_present)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f10b558f",
"metadata": {},
"outputs": [],
"source": [
"international_VAERSVAX_Covid19"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3e0908fe",
"metadata": {},
"outputs": [],
"source": [
"international_VAERSSYMPTOMS"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "204af94d",
"metadata": {},
"outputs": [],
"source": [
"from SymptomByBatchcodeTableFactory import SymptomByBatchcodeTableFactory\n",
"\n",
"symptomByBatchcodeTable = SymptomByBatchcodeTableFactory.createSymptomByBatchcodeTable(international_VAERSVAX_Covid19, international_VAERSSYMPTOMS)\n",
"symptomByBatchcodeTable"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5997ee59",
"metadata": {},
"outputs": [],
"source": [
"isGlobal = True"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9268d60d",
"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",
" directory = f'../docs/data/histograms'\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}'))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "86918e80",
"metadata": {},
"outputs": [],
"source": [
"# batchcodes = international_VAERSVAX_Covid19['VAX_LOT'].dropna().drop_duplicates().to_list()\n",
"# batchcodes"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "781ac80e",
"metadata": {},
"outputs": [],
"source": [
"internationalVaersCovid19 = getInternationalVaersCovid19(years = years_from_2020_to_present)\n",
"internationalVaersCovid19"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8d6507ca",
"metadata": {},
"outputs": [],
"source": [
"updateBatchCodeTableHtmlFile(internationalVaersCovid19, batchCodeTableHtmlFile=\"../docs/batchCodeTable.html\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0915aa5a",
"metadata": {},
"outputs": [],
"source": [
"createAndSaveBatchCodeTables(\n",
" internationalVaersCovid19,\n",
" minADRsForLethality = 100,\n",
" onCountryProcessed = display)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "howbadismybatch-venv-kernel",
"language": "python",
"name": "howbadismybatch-venv-kernel"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.8"
},
"vscode": {
"interpreter": {
"hash": "1bce2b9b19ce5f16d695ff75ac05095b3e564c169ff454b58b87cb796c0695b8"
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}