diff --git a/common/management/commands/update_country_data.py b/common/management/commands/update_country_data.py index 45024b7..6ded22c 100644 --- a/common/management/commands/update_country_data.py +++ b/common/management/commands/update_country_data.py @@ -17,16 +17,15 @@ def handle(self, *args, **options): independent = data["independent"] is_deprecated = data["is_deprecated"] record_type = data["record_type"] - print(record_type) iso3 = data["iso3"] if iso3: country = Country.objects.filter(iso3=iso3.lower()) if country.exists(): - country = country.last() - country.independent = independent - country.is_deprecated = is_deprecated - country.record_type = record_type - country.save(update_fields=["independent", "is_deprecated", "record_type"]) + for country_item in country: + country_item.independent = independent + country_item.is_deprecated = is_deprecated + country_item.record_type = record_type + country_item.save(update_fields=["independent", "is_deprecated", "record_type"]) cluster_country_name = [ "West Africa Country Cluster", "Tunis Country Cluster", diff --git a/imminent/management/commands/import_gwis_data.py b/imminent/management/commands/import_gwis_data.py index ebb23a0..7c9070c 100644 --- a/imminent/management/commands/import_gwis_data.py +++ b/imminent/management/commands/import_gwis_data.py @@ -17,7 +17,7 @@ def handle(self, *args, **kwargs): # Get all the countries with iso3 codes that are not deprecated and independent country_iso3 = list(Country.objects.filter(is_deprecated=False, independent=True).values_list("iso3", flat=True)) - for year in range(2024, 2025): + for year in range(2003, 2026): for iso3 in country_iso3: if iso3: self.import_monthly_data(iso3, year) @@ -41,7 +41,7 @@ def import_monthly_data(self, iso3, year): self.create_gwis_entry(iso3, month, year, GWIS.DSRTYPE.MONTHLY) def import_cumulative_data(self, iso3, year): - url = f"https://api2.effis.emergency.copernicus.eu/statistics/v2/dsr/cumulative?country={iso3.upper()}&year={year}" + url = f"https://api2.effis.emergency.copernicus.eu/statistics/v2/dsr/monthly?country={iso3.upper()}&year={year}" response = requests.get(url, verify=False) if response.status_code != 200: @@ -55,7 +55,7 @@ def import_cumulative_data(self, iso3, year): cumulative_response = response_data.get("dsrcumulative", []) for month in cumulative_response: - self.create_gwis_entry(iso3, month, year, GWIS.DSRTYPE.CUMULATIVE) + self.create_gwis_entry(iso3, month, year, GWIS.DSRTYPE.CUMMULATIVE) def create_gwis_entry(self, iso3, data, year, dsr_type): country = Country.objects.filter(iso3=iso3).first() diff --git a/seasonal/INFORM_Risk_2025_v070.xlsx b/seasonal/INFORM_Risk_2025_v070.xlsx new file mode 100644 index 0000000..cd7db1f Binary files /dev/null and b/seasonal/INFORM_Risk_2025_v070.xlsx differ diff --git a/seasonal/management/commands/aggregate_gwis_data.py b/seasonal/management/commands/aggregate_gwis_data.py index 8c47364..9521276 100644 --- a/seasonal/management/commands/aggregate_gwis_data.py +++ b/seasonal/management/commands/aggregate_gwis_data.py @@ -42,7 +42,7 @@ def handle(self, *args, **options): new_df = new_df.replace(np.nan, None) country_groups = new_df.groupby("country") for country_name, group in country_groups: - gwis_data = {"country": Country.objects.filter(name__icontains=country_name).first()} + gwis_data = {"country": Country.objects.filter(name=country_name).first()} for month in month_mapping.values(): gwis_data[month] = ( group.loc[group["month"] == month, "dsr_avg"].values[0] if month in group["month"].values else None diff --git a/seasonal/management/commands/create_hazard_information.py b/seasonal/management/commands/create_hazard_information.py index 871f16b..5d0e5ff 100644 --- a/seasonal/management/commands/create_hazard_information.py +++ b/seasonal/management/commands/create_hazard_information.py @@ -48,7 +48,7 @@ def handle(self, **options): map_hazard_type = HazadTypeList[1] elif hazard_type == "DR": map_hazard_type = HazadTypeList[2] - if map_hazard_type: + if not map_hazard_type: continue url = f"https://thinkhazard.org/en/report/{country_id}/{hazard_type}.json" diff --git a/seasonal/management/commands/create_risk_score.py b/seasonal/management/commands/create_risk_score.py index 6d0aab1..ddeff2b 100644 --- a/seasonal/management/commands/create_risk_score.py +++ b/seasonal/management/commands/create_risk_score.py @@ -54,7 +54,7 @@ def handle(self, **options): df1 = inform_score_dataframe df1["ISO3"] = df1["ISO3"].str.upper() # latest inform score data - df2 = pd.read_excel(file1, sheet_name="INFORM Risk 2024 (a-z)", skiprows=(0, 2), usecols="A, B, S, AE", engine="openpyxl") + df2 = pd.read_excel(file1, sheet_name="INFORM Risk 2025 (a-z)", skiprows=(0, 2), usecols="A, B, S, AE", engine="openpyxl") df2.rename( {"VULNERABILITY": "Vulnerability", "LACK OF COPING CAPACITY": "LCC"}, axis=1, @@ -118,7 +118,7 @@ def handle(self, **options): ) risk_score_data = { "country": Country.objects.filter( - iso3__icontains=row["ISO3"], + name=row["name"], iso3__isnull=False, record_type__isnull=False, record_type=Country.CountryType.COUNTRY, @@ -141,4 +141,5 @@ def handle(self, **options): "population_in_thousands": row["Population_in_thousands"], "vulnerability": row["Vulnerability"], } - RiskScore.objects.create(**risk_score_data) + if risk_score_data["country"]: + RiskScore.objects.create(**risk_score_data) diff --git a/seasonal/scripts/fetch_inform_data.py b/seasonal/scripts/fetch_inform_data.py index f9c1e09..216e0aa 100644 --- a/seasonal/scripts/fetch_inform_data.py +++ b/seasonal/scripts/fetch_inform_data.py @@ -15,7 +15,7 @@ def get_maximum_rows(*, sheet_object): def fetch_inform_data(file): # NOTE: set `data_only=True` to read cell value instead of formula workbook = openpyxl.load_workbook(file, data_only=True) - worksheet = workbook.get_sheet_by_name("INFORM Risk 2022 (a-z)") + worksheet = workbook.get_sheet_by_name("INFORM Risk 2025 (a-z)") max_rows = get_maximum_rows(sheet_object=worksheet) # Iterate the loop to read the cell values data_all = [] diff --git a/seasonal/scripts/fetch_inform_seasonal.py b/seasonal/scripts/fetch_inform_seasonal.py index 0bab68f..1286cb1 100644 --- a/seasonal/scripts/fetch_inform_seasonal.py +++ b/seasonal/scripts/fetch_inform_seasonal.py @@ -26,7 +26,7 @@ def fetch_inform_seasonal(file): workbook = openpyxl.load_workbook(file) worksheet = workbook.get_sheet_by_name("Sheet1") max_rows = get_maximum_rows(sheet_object=worksheet) - hazard_list = [HazardType.CYCLONE, HazardType.DROUGHT, HazardType.FLOOD] + hazard_list = [HazardType.CYCLONE.value, HazardType.DROUGHT.value, HazardType.FLOOD.value] for i in range(2, max_rows + 1): iso3 = worksheet.cell(row=i, column=1).value hazard_type = parse_hazard_type(worksheet.cell(row=i, column=2).value)