minifying histogram JSON files
This commit is contained in:
@@ -1,13 +1,6 @@
|
||||
class HistoDescrsProvider {
|
||||
|
||||
static getHistoDescrs(batchcode) {
|
||||
return fetch(`data/histograms/Global/${batchcode}.json`)
|
||||
.then(response => response.json())
|
||||
.then(histoDescrs => {
|
||||
histoDescrs.histograms.sort((histoDescr1, histoDescr2) => histoDescr1.batchcodes.length - histoDescr2.batchcodes.length);
|
||||
histoDescrs.histogram = histoDescrs.histograms[0].histogram;
|
||||
delete histoDescrs.histograms;
|
||||
return histoDescrs;
|
||||
});
|
||||
return fetch(`data/histograms/Global/${batchcode}.json`).then(response => response.json())
|
||||
}
|
||||
}
|
||||
@@ -28,9 +28,7 @@ class BatchCodeTableIntoHistogramDescriptionTableMerger:
|
||||
'Deaths',
|
||||
'Disabilities',
|
||||
'Life Threatening Illnesses',
|
||||
'Company',
|
||||
'Severe reports',
|
||||
'Lethality'
|
||||
'Company'
|
||||
]]
|
||||
|
||||
def _merge_columns_into_HISTOGRAM_DESCRIPTION(self, table):
|
||||
|
||||
@@ -55,8 +55,6 @@ class BatchCodeTableIntoHistogramDescriptionTableMergerTest(unittest.TestCase):
|
||||
'Disabilities': 2,
|
||||
'Life Threatening Illnesses': 2,
|
||||
'Company': 'MODERNA',
|
||||
'Severe reports': 2/2 * 100,
|
||||
'Lethality': np.nan,
|
||||
'histograms': [
|
||||
{
|
||||
'batchcodes': ['1808982', 'EW0175', 'FD1921'],
|
||||
|
||||
25
src/HistogramDescriptionTableSelector.py
Normal file
25
src/HistogramDescriptionTableSelector.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import warnings
|
||||
|
||||
class HistogramDescriptionTableSelector:
|
||||
|
||||
@staticmethod
|
||||
def selectHistogramsWithShortestBatchcodeCombinations(histogramDescriptionTable):
|
||||
histogramDescriptionTable['HISTOGRAM_DESCRIPTION'] = histogramDescriptionTable['HISTOGRAM_DESCRIPTION'].map(HistogramDescriptionTableSelector._selectHistogramWithShortestBatchcodeCombination)
|
||||
return histogramDescriptionTable
|
||||
|
||||
@staticmethod
|
||||
def _selectHistogramWithShortestBatchcodeCombination(histoDescr):
|
||||
return {
|
||||
"batchcode": histoDescr["batchcode"],
|
||||
"histogram": HistogramDescriptionTableSelector._getHistogramWithShortestBatchcodeCombination(histoDescr)
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def _getHistogramWithShortestBatchcodeCombination(histoDescr):
|
||||
histogramsSortedByShortestBatchcodeCombination = sorted(
|
||||
histoDescr["histograms"],
|
||||
key = lambda histogram: len(histogram["batchcodes"]))
|
||||
histogramWithShortestBatchcodeCombination = histogramsSortedByShortestBatchcodeCombination[0]
|
||||
if len(histogramWithShortestBatchcodeCombination["batchcodes"]) != 1:
|
||||
warnings.warn(f"batchcode {histoDescr['batchcode']} has non unique batchcode combination {histogramWithShortestBatchcodeCombination['batchcodes']} for it's histogram")
|
||||
return histogramWithShortestBatchcodeCombination["histogram"]
|
||||
51
src/HistogramDescriptionTableSelectorTest.py
Normal file
51
src/HistogramDescriptionTableSelectorTest.py
Normal file
@@ -0,0 +1,51 @@
|
||||
import unittest
|
||||
from pandas.testing import assert_frame_equal
|
||||
from HistogramDescriptionTableSelector import HistogramDescriptionTableSelector
|
||||
from TestHelper import TestHelper
|
||||
import pandas as pd
|
||||
|
||||
class HistogramDescriptionTableSelectorTest(unittest.TestCase):
|
||||
|
||||
def test_selectHistogramsWithShortestBatchcodeCombinations(self):
|
||||
# Given
|
||||
histogramDescriptionTable = TestHelper.createDataFrame(
|
||||
columns = ['HISTOGRAM_DESCRIPTION'],
|
||||
data = [ [
|
||||
{
|
||||
"batchcode": "1808982",
|
||||
"histograms": [
|
||||
{
|
||||
"batchcodes": ["1808982", "EW0175", "FD1921"],
|
||||
"histogram": {"Blood pressure orthostatic abnormal": 5, "Chest discomfort": 1}
|
||||
},
|
||||
{
|
||||
"batchcodes": ["015M20A", "1808982"],
|
||||
"histogram": {"Chest discomfort": 2}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
],
|
||||
index = pd.Index(
|
||||
name = 'VAX_LOT',
|
||||
data = ['1808982']))
|
||||
|
||||
# When
|
||||
histogramsWithShortestBatchcodeCombinationsTable = HistogramDescriptionTableSelector.selectHistogramsWithShortestBatchcodeCombinations(histogramDescriptionTable)
|
||||
|
||||
# Then
|
||||
assert_frame_equal(
|
||||
histogramsWithShortestBatchcodeCombinationsTable,
|
||||
TestHelper.createDataFrame(
|
||||
columns = ['HISTOGRAM_DESCRIPTION'],
|
||||
data = [ [
|
||||
{
|
||||
"batchcode": "1808982",
|
||||
"histogram": {"Chest discomfort": 2}
|
||||
}
|
||||
]
|
||||
],
|
||||
index = pd.Index(
|
||||
name = 'VAX_LOT',
|
||||
data = ['1808982'])))
|
||||
|
||||
@@ -2,6 +2,7 @@ from HistogramFactory import createHistograms
|
||||
from HistogramPersister import saveHistograms
|
||||
from MultiIndexExploder import MultiIndexExploder
|
||||
from HistogramDescriptionTableFactory import HistogramDescriptionTableFactory
|
||||
from HistogramDescriptionTableSelector import HistogramDescriptionTableSelector
|
||||
from BatchCodeTableIntoHistogramDescriptionTableMerger import BatchCodeTableIntoHistogramDescriptionTableMerger
|
||||
|
||||
|
||||
@@ -10,6 +11,7 @@ def createAndSaveGlobalHistograms(symptomByBatchcodeTable, batchCodeTable):
|
||||
dictByBatchcodeTable = createHistograms(symptomByBatchcodeTable)
|
||||
explodedTable = MultiIndexExploder.explodeMultiIndexOfTable(dictByBatchcodeTable)
|
||||
histogramDescriptionTable = HistogramDescriptionTableFactory.createHistogramDescriptionTable(explodedTable)
|
||||
histogramDescriptionTable = HistogramDescriptionTableSelector.selectHistogramsWithShortestBatchcodeCombinations(histogramDescriptionTable)
|
||||
histogramDescriptionTable = BatchCodeTableIntoHistogramDescriptionTableMerger().mergeBatchCodeTableIntoHistogramDescriptionTable(
|
||||
batchCodeTable = _rearrange(batchCodeTable),
|
||||
histogramDescriptionTable = histogramDescriptionTable)
|
||||
|
||||
@@ -120,7 +120,7 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"batchCodeTable = createGlobalBatchCodeTable(\n",
|
||||
" deleteEntriesWithADRsLessThanOrEqual = 1,\n",
|
||||
" deleteEntriesWithADRsLessThanOrEqual = 2,\n",
|
||||
" minADRsForLethality = 100,\n",
|
||||
" batchCodeTableFactory = BatchCodeTableFactory(internationalVaersCovid19))\n",
|
||||
"batchCodeTable"
|
||||
|
||||
@@ -4,7 +4,6 @@ FK-FIXME:
|
||||
|
||||
FK-TODO:
|
||||
- add google captcha to batchCodeTable.html
|
||||
- aus den JSON-Dateien lethality und severity entfernen.
|
||||
|
||||
anacron job:
|
||||
sudo cp src/intensivstationen_howbadismybatch.sh /etc/cron.daily/intensivstationen_howbadismybatch
|
||||
|
||||
Reference in New Issue
Block a user