refactoring
This commit is contained in:
@@ -333,22 +333,31 @@
|
|||||||
" @staticmethod\n",
|
" @staticmethod\n",
|
||||||
" def getInternationalLotTable(dataFrame):\n",
|
" def getInternationalLotTable(dataFrame):\n",
|
||||||
" dataFrame = DataFrameFilter().filterByCovid19(dataFrame)\n",
|
" dataFrame = DataFrameFilter().filterByCovid19(dataFrame)\n",
|
||||||
" dataFrame['Country'] = dataFrame.apply(InternationalLotAnalysis._fun2, axis = 'columns')\n",
|
" internationalLotTable = InternationalLotAnalysis._getInternationalLotTable(dataFrame)\n",
|
||||||
" result = DoseAnalysis._getDoseTable(dataFrame.groupby(dataFrame['Country']))\n",
|
" return internationalLotTable.sort_values(by = 'Severe reports (%)', ascending = False)\n",
|
||||||
" return result.sort_values(by = 'Severe reports (%)', ascending = False)\n",
|
|
||||||
"\n",
|
"\n",
|
||||||
" # FK-TODO: refactor\n",
|
|
||||||
" @staticmethod\n",
|
" @staticmethod\n",
|
||||||
" def _fun2(row):\n",
|
" def _getInternationalLotTable(dataFrame):\n",
|
||||||
" unknown = 'Unknown Country'\n",
|
" countryColumnName = 'Country'\n",
|
||||||
" if isinstance(row['SPLTTYPE'], str):\n",
|
" InternationalLotAnalysis._addCountryColumn(dataFrame, countryColumnName = countryColumnName)\n",
|
||||||
" country = pycountry.countries.get(alpha_2 = row['SPLTTYPE'][:2])\n",
|
" return DoseAnalysis._getDoseTable(dataFrame.groupby(dataFrame[countryColumnName]))\n",
|
||||||
" if country is None:\n",
|
"\n",
|
||||||
" return unknown\n",
|
" @staticmethod\n",
|
||||||
" else:\n",
|
" def _addCountryColumn(dataFrame, countryColumnName):\n",
|
||||||
" return country.name\n",
|
" dataFrame[countryColumnName] = dataFrame.apply(\n",
|
||||||
" else:\n",
|
" lambda row:\n",
|
||||||
" return unknown\n"
|
" InternationalLotAnalysis._getCountryNameOfSplttypeOrDefault(\n",
|
||||||
|
" splttype = row['SPLTTYPE'],\n",
|
||||||
|
" default = 'Unknown Country'),\n",
|
||||||
|
" axis = 'columns')\n",
|
||||||
|
"\n",
|
||||||
|
" @staticmethod\n",
|
||||||
|
" def _getCountryNameOfSplttypeOrDefault(splttype, default):\n",
|
||||||
|
" if not isinstance(splttype, str):\n",
|
||||||
|
" return default\n",
|
||||||
|
" \n",
|
||||||
|
" country = pycountry.countries.get(alpha_2 = splttype[:2])\n",
|
||||||
|
" return country.name if country is not None else default\n"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user