From e208727ff70280371f20192c9d9d8a3c412fd3f7 Mon Sep 17 00:00:00 2001 From: frankknoll Date: Fri, 27 Jan 2023 11:14:41 +0100 Subject: [PATCH] refactoring --- src/HistogramDescriptionPersister.py | 8 +++----- src/HowBadIsMyBatch.ipynb | 5 ++++- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/HistogramDescriptionPersister.py b/src/HistogramDescriptionPersister.py index df1a7f84c9b..f607709f2b8 100644 --- a/src/HistogramDescriptionPersister.py +++ b/src/HistogramDescriptionPersister.py @@ -8,13 +8,11 @@ class HistogramDescriptionPersister: def __init__(self, directory): self.directory = directory - def saveHistogramDescriptionsForBatchcodes(self, batchcodes, dictByBatchcodeTable): + def saveHistogramDescriptionsForBatchcodes(self, batchcodes, dictByBatchcodeTable, progress): for count, batchcode in enumerate(batchcodes, start = 1): histogramDescription = self._getHistogramDescriptionForBatchcode(batchcode, dictByBatchcodeTable) - print(f'{count}/{len(batchcodes)}: saving {batchcode}') - IOUtils.saveDictAsJson( - histogramDescription, - f'{self.directory}/{batchcode}.json') + IOUtils.saveDictAsJson(histogramDescription, f'{self.directory}/{batchcode}.json') + progress(count, len(batchcodes), batchcode) def _getHistogramDescriptionForBatchcode(self, batchcode, dictByBatchcodeTable): dictByBatchcodeTableForBatchcode = TableByBatchcodeFilter.filterTableByBatchcode(batchcode, dictByBatchcodeTable) diff --git a/src/HowBadIsMyBatch.ipynb b/src/HowBadIsMyBatch.ipynb index 18924a3f9a9..65881e7904f 100644 --- a/src/HowBadIsMyBatch.ipynb +++ b/src/HowBadIsMyBatch.ipynb @@ -189,7 +189,10 @@ "from HistogramDescriptionPersister import HistogramDescriptionPersister\n", "\n", "histogramDescriptionPersister = HistogramDescriptionPersister('../docs/data/histograms')\n", - "histogramDescriptionPersister.saveHistogramDescriptionsForBatchcodes(batchcodes[:100], dictByBatchcodeTable)" + "histogramDescriptionPersister.saveHistogramDescriptionsForBatchcodes(\n", + " batchcodes[:100],\n", + " dictByBatchcodeTable,\n", + " progress = lambda count, size, batchcode: print(f'{count}/{size}: {batchcode}'))" ] }, {