adding HistogramDescriptionPersister

This commit is contained in:
frankknoll
2023-01-27 10:41:19 +01:00
parent d56b17fd17
commit 0dbc9f922e
3 changed files with 57 additions and 9 deletions

3
.gitignore vendored
View File

@@ -13,4 +13,5 @@ src/captchaImage.jpeg
src/HowBadIsMyBatch.nbconvert.html src/HowBadIsMyBatch.nbconvert.html
src/__pycache__/ src/__pycache__/
src/intensivstationen/__pycache__/ src/intensivstationen/__pycache__/
google-chrome-stable_current_amd64* google-chrome-stable_current_amd64*
docs/data/histograms/

View File

@@ -0,0 +1,22 @@
from TableByBatchcodeFilter import TableByBatchcodeFilter
from DictByBatchcodeTable2DictConverter import DictByBatchcodeTable2DictConverter
from IOUtils import IOUtils
class HistogramDescriptionPersister:
def __init__(self, directory):
self.directory = directory
def saveHistogramDescriptionsForBatchcodes(self, batchcodes, dictByBatchcodeTable):
for batchcode in batchcodes:
histogramDescription = self._getHistogramDescriptionForBatchcode(batchcode, dictByBatchcodeTable)
print('saving', batchcode)
IOUtils.saveDictAsJson(
histogramDescription,
f'{self.directory}/{batchcode}.json')
def _getHistogramDescriptionForBatchcode(self, batchcode, dictByBatchcodeTable):
dictByBatchcodeTableForBatchcode = TableByBatchcodeFilter.filterTableByBatchcode(batchcode, dictByBatchcodeTable)
histogramDescription = DictByBatchcodeTable2DictConverter.convertDictByBatchcodeTable2Dict(dictByBatchcodeTableForBatchcode, batchcode)
return histogramDescription

View File

@@ -87,6 +87,17 @@
"international_VAERSVAX_Covid19" "international_VAERSVAX_Covid19"
] ]
}, },
{
"cell_type": "code",
"execution_count": null,
"id": "99137f64",
"metadata": {},
"outputs": [],
"source": [
"batchcodes = international_VAERSVAX_Covid19['VAX_LOT'].dropna().drop_duplicates().to_list()\n",
"batchcodes"
]
},
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
@@ -171,11 +182,24 @@
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": null,
"id": "5c77a3d4", "id": "fc2c5591",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"dictByBatchcodeTable" "from HistogramDescriptionPersister import HistogramDescriptionPersister\n",
"\n",
"histogramDescriptionPersister = HistogramDescriptionPersister('../docs/data/histograms')\n",
"histogramDescriptionPersister.saveHistogramDescriptionsForBatchcodes(['eh9899'], dictByBatchcodeTable)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ab4ccc60",
"metadata": {},
"outputs": [],
"source": [
"batchcodes[:10]"
] ]
}, },
{ {
@@ -186,7 +210,7 @@
"outputs": [], "outputs": [],
"source": [ "source": [
"from TableByBatchcodeFilter import TableByBatchcodeFilter\n", "from TableByBatchcodeFilter import TableByBatchcodeFilter\n",
"filteredTable = TableByBatchcodeFilter.filterTableByBatchcode('FE6208', dictByBatchcodeTable)\n", "filteredTable = TableByBatchcodeFilter.filterTableByBatchcode('<NA>', dictByBatchcodeTable)\n",
"filteredTable" "filteredTable"
] ]
}, },
@@ -197,11 +221,12 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"from DictByBatchcodeTable2JsonConverter import DictByBatchcodeTable2JsonConverter\n", "from DictByBatchcodeTable2DictConverter import DictByBatchcodeTable2DictConverter\n",
"import json\n", "import json\n",
"# FK-TODO: convertDictByBatchcodeTable2Json() für alle Batchcodes aufrufen und jedes Ergebnis in einer Datei batchcode.json speichern.\n", "# FK-TODO: filterTableByBatchcode() und convertDictByBatchcodeTable2Json() für alle Batchcodes aufrufen und jedes Ergebnis in einer Datei batchcode.json speichern.\n",
"jsonActual = DictByBatchcodeTable2JsonConverter.convertDictByBatchcodeTable2Json(filteredTable, 'FE6208')\n", "dict = DictByBatchcodeTable2DictConverter.convertDictByBatchcodeTable2Dict(filteredTable, 'FE6208')\n",
"print(json.dumps(json.loads(jsonActual), indent=2))" "dict\n",
"# print(json.dumps(json.loads(jsonActual), indent=2))"
] ]
}, },
{ {
@@ -506,7 +531,7 @@
"name": "python", "name": "python",
"nbconvert_exporter": "python", "nbconvert_exporter": "python",
"pygments_lexer": "ipython3", "pygments_lexer": "ipython3",
"version": "3.10.8 (main, Nov 24 2022, 14:13:03) [GCC 11.2.0]" "version": "3.10.8"
}, },
"vscode": { "vscode": {
"interpreter": { "interpreter": {