adding MedianOfFreeBedsByKreisTableFactoryTest
This commit is contained in:
27
src/help.txt
27
src/help.txt
@@ -17,30 +17,9 @@ get VAERS data:
|
||||
FK-FIXME:
|
||||
|
||||
FK-TODO:
|
||||
- Format des jeweiligen Herstellers berücksichtigen:
|
||||
039k20a
|
||||
MOD039K20A
|
||||
#039K20A
|
||||
039K20A-MODERNA
|
||||
039K20A-2A (vielleicht nicht)
|
||||
039K20A or 039L
|
||||
Moderna/039K20A
|
||||
MODERNA 039K20A
|
||||
MODERNA039K20A
|
||||
Modena 039k20A
|
||||
L039K20A
|
||||
M039K20A
|
||||
MOD; 039K20A
|
||||
m0039k20A
|
||||
u039k20a
|
||||
6/21 039K20A
|
||||
2039K20A
|
||||
013L20A 039K20A#039K20A
|
||||
#039K
|
||||
039K20A 12-31-
|
||||
039K20A & 031M2
|
||||
039K20A and 032
|
||||
039K20A, 011L20
|
||||
- Intensivstationen ergänzen durch Tabelle oder Barchart:
|
||||
Kreis => "Median des Anteils freier Betten", absteigend sortiert nach "Median des Anteils freier Betten".
|
||||
- Darstellung als Dashboard, siehe https://covid-karte.de/ oder https://experience.arcgis.com/experience/3a132983ad3c4ab8a28704e9addefaba
|
||||
|
||||
man 5 fcrontab
|
||||
|
||||
|
||||
@@ -336,6 +336,30 @@
|
||||
" return BeautifulSoup(html, 'lxml')\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "29b0930a",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import unittest"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "45072a1d",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class TestHelper:\n",
|
||||
"\n",
|
||||
" @staticmethod\n",
|
||||
" def createDataFrame(index, columns, data, dtypes = {}):\n",
|
||||
" return pd.DataFrame(index = index, columns = columns, data = data).astype(dtypes)\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -343,9 +367,6 @@
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import unittest\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"class KreisOptionsSetterTest(unittest.TestCase):\n",
|
||||
"\n",
|
||||
" def test_setKreisOptions(self):\n",
|
||||
@@ -389,6 +410,8 @@
|
||||
" ''')\n",
|
||||
"\n",
|
||||
"# adapted from https://stackoverflow.com/questions/8006909/pretty-print-assertequal-for-html-strings\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"def assertEqualHTML(string1, string2, file1='', file2=''):\n",
|
||||
" u'''\n",
|
||||
" Compare two unicode strings containing HTML.\n",
|
||||
@@ -418,16 +441,6 @@
|
||||
" raise Exception('Not equal %s %s' % (file1, file2))\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "e80117e5",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"unittest.main(argv = [''], verbosity = 2, exit = False)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
@@ -561,6 +574,84 @@
|
||||
" getAndPersistIntensiveCareBeds(timeSeries, kreis)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "d9d4acab",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"class MedianOfFreeBedsByKreisTableFactory:\n",
|
||||
" \n",
|
||||
" def __init__(self, dataFrame):\n",
|
||||
" self.dataFrame = dataFrame\n",
|
||||
"\n",
|
||||
" def createMedianOfFreeBedsByKreisTable(self):\n",
|
||||
" self.dataFrame['free_beds_divided_by_all_beds_in_percent'] = self.dataFrame['betten_frei'] / (self.dataFrame['betten_frei'] + self.dataFrame['betten_belegt']) * 100\n",
|
||||
" aggregated = self.dataFrame.groupby('Kreis').agg(\n",
|
||||
" median_free_beds_in_percent =\n",
|
||||
" pd.NamedAgg(\n",
|
||||
" column = 'free_beds_divided_by_all_beds_in_percent',\n",
|
||||
" aggfunc = 'median'))\n",
|
||||
" return aggregated.sort_values(by = 'median_free_beds_in_percent', ascending = False)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "a739d4d1",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from pandas.testing import assert_frame_equal\n",
|
||||
"import statistics\n",
|
||||
"\n",
|
||||
"class MedianOfFreeBedsByKreisTableFactoryTest(unittest.TestCase):\n",
|
||||
"\n",
|
||||
" def test_createMedianOfFreeBedsByKreisTable(self):\n",
|
||||
" # Given\n",
|
||||
" dataFrame = TestHelper.createDataFrame(\n",
|
||||
" columns = ['date', 'betten_frei', 'betten_belegt', 'Kreis'],\n",
|
||||
" data = [ ['2020-04-24', 40, 38, 'Flensburg, Stadt'],\n",
|
||||
" ['2020-04-24', 42, 36, 'Flensburg, Stadt'],\n",
|
||||
" ['2020-04-24', 44, 34, 'Flensburg, Stadt'],\n",
|
||||
" ['2020-04-24', 9, 10, 'Bamberg']],\n",
|
||||
" index = [\n",
|
||||
" 0,\n",
|
||||
" 1,\n",
|
||||
" 2,\n",
|
||||
" 3])\n",
|
||||
" medianOfFreeBedsByKreisTableFactory = MedianOfFreeBedsByKreisTableFactory(dataFrame)\n",
|
||||
" \n",
|
||||
" # When\n",
|
||||
" medianOfFreeBedsByKreisTable = medianOfFreeBedsByKreisTableFactory.createMedianOfFreeBedsByKreisTable()\n",
|
||||
"\n",
|
||||
" # Then\n",
|
||||
" assert_frame_equal(\n",
|
||||
" medianOfFreeBedsByKreisTable,\n",
|
||||
" TestHelper.createDataFrame(\n",
|
||||
" columns = ['median_free_beds_in_percent'],\n",
|
||||
" data = [ [statistics.median([40/(40 + 38) * 100, 42/(42 + 36) * 100, 44/(44 + 34) * 100])],\n",
|
||||
" [9/(9 + 10) * 100]],\n",
|
||||
" index = pd.Index(\n",
|
||||
" name = 'Kreis',\n",
|
||||
" data = [\n",
|
||||
" 'Flensburg, Stadt',\n",
|
||||
" 'Bamberg'\n",
|
||||
" ])),\n",
|
||||
" check_dtype = False)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "af22cdc5",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"unittest.main(argv = [''], verbosity = 2, exit = False)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
|
||||
Reference in New Issue
Block a user