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