Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions common/management/commands/update_country_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions imminent/management/commands/import_gwis_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand All @@ -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()
Expand Down
Binary file added seasonal/INFORM_Risk_2025_v070.xlsx
Binary file not shown.
2 changes: 1 addition & 1 deletion seasonal/management/commands/aggregate_gwis_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion seasonal/management/commands/create_hazard_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 4 additions & 3 deletions seasonal/management/commands/create_risk_score.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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)
2 changes: 1 addition & 1 deletion seasonal/scripts/fetch_inform_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down
2 changes: 1 addition & 1 deletion seasonal/scripts/fetch_inform_seasonal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading