From 0dbc9f922ea20bac7bb1bbc6cd0e50b5e81120b6 Mon Sep 17 00:00:00 2001 From: frankknoll Date: Fri, 27 Jan 2023 10:41:19 +0100 Subject: [PATCH] adding HistogramDescriptionPersister --- .gitignore | 3 +- src/HistogramDescriptionPersister.py | 22 +++++++++++++++ src/HowBadIsMyBatch.ipynb | 41 ++++++++++++++++++++++------ 3 files changed, 57 insertions(+), 9 deletions(-) create mode 100644 src/HistogramDescriptionPersister.py diff --git a/.gitignore b/.gitignore index 3b9471615e7..7f52c422558 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,5 @@ src/captchaImage.jpeg src/HowBadIsMyBatch.nbconvert.html src/__pycache__/ src/intensivstationen/__pycache__/ -google-chrome-stable_current_amd64* \ No newline at end of file +google-chrome-stable_current_amd64* +docs/data/histograms/ diff --git a/src/HistogramDescriptionPersister.py b/src/HistogramDescriptionPersister.py new file mode 100644 index 00000000000..1cfadd75caf --- /dev/null +++ b/src/HistogramDescriptionPersister.py @@ -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 diff --git a/src/HowBadIsMyBatch.ipynb b/src/HowBadIsMyBatch.ipynb index d16a6732070..6896d0e0756 100644 --- a/src/HowBadIsMyBatch.ipynb +++ b/src/HowBadIsMyBatch.ipynb @@ -87,6 +87,17 @@ "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", "execution_count": null, @@ -171,11 +182,24 @@ { "cell_type": "code", "execution_count": null, - "id": "5c77a3d4", + "id": "fc2c5591", "metadata": {}, "outputs": [], "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": [], "source": [ "from TableByBatchcodeFilter import TableByBatchcodeFilter\n", - "filteredTable = TableByBatchcodeFilter.filterTableByBatchcode('FE6208', dictByBatchcodeTable)\n", + "filteredTable = TableByBatchcodeFilter.filterTableByBatchcode('', dictByBatchcodeTable)\n", "filteredTable" ] }, @@ -197,11 +221,12 @@ "metadata": {}, "outputs": [], "source": [ - "from DictByBatchcodeTable2JsonConverter import DictByBatchcodeTable2JsonConverter\n", + "from DictByBatchcodeTable2DictConverter import DictByBatchcodeTable2DictConverter\n", "import json\n", - "# FK-TODO: convertDictByBatchcodeTable2Json() für alle Batchcodes aufrufen und jedes Ergebnis in einer Datei batchcode.json speichern.\n", - "jsonActual = DictByBatchcodeTable2JsonConverter.convertDictByBatchcodeTable2Json(filteredTable, 'FE6208')\n", - "print(json.dumps(json.loads(jsonActual), indent=2))" + "# FK-TODO: filterTableByBatchcode() und convertDictByBatchcodeTable2Json() für alle Batchcodes aufrufen und jedes Ergebnis in einer Datei batchcode.json speichern.\n", + "dict = DictByBatchcodeTable2DictConverter.convertDictByBatchcodeTable2Dict(filteredTable, 'FE6208')\n", + "dict\n", + "# print(json.dumps(json.loads(jsonActual), indent=2))" ] }, { @@ -506,7 +531,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.8 (main, Nov 24 2022, 14:13:03) [GCC 11.2.0]" + "version": "3.10.8" }, "vscode": { "interpreter": {