From 47cdaf22e26745c9fd3bc6fbc312dcf41654f92a Mon Sep 17 00:00:00 2001 From: Alexander Griffen Date: Tue, 27 Feb 2024 15:06:38 +0000 Subject: [PATCH] DATASET: Wildlife trusts regions --- .../import_wildlife_trusts_regions.py | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 hub/management/commands/import_wildlife_trusts_regions.py diff --git a/hub/management/commands/import_wildlife_trusts_regions.py b/hub/management/commands/import_wildlife_trusts_regions.py new file mode 100644 index 000000000..762086f97 --- /dev/null +++ b/hub/management/commands/import_wildlife_trusts_regions.py @@ -0,0 +1,52 @@ +from django.conf import settings + +import pandas as pd + +from hub.models import DataSet + +from .base_importers import BaseConstituencyGroupListImportCommand + + +class Command(BaseConstituencyGroupListImportCommand): + help = "Import Wildlife trust reserves" + + data_file = ( + settings.BASE_DIR / "data" / "wildlife_trust_regions_in_constituencies.csv" + ) + cons_row = "PCON19NM" + uses_gss = False + message = "Importing constituency Wildlife Trust regions data" + + data_sets = { + "wildlife_trusts_regions": { + "defaults": { + "label": "Wildlife Trust Regions", + "description": "The Wildlife Trust Region(s) that a constituency falls under.", + "data_type": "json", + "category": "place", + "subcategory": "groups", + "source_label": "Data from The Widlife Trusts", + "source": "https://www.wildlifetrusts.org/", + "source_type": "csv", + "table": "areadata", + "is_filterable": True, + "comparators": DataSet.in_comparators(), + }, + "col": "Trust", + } + } + group_data_type = "wildlife_trusts_regions" + + def get_df(self): + return pd.read_csv(self.data_file, usecols=["Trust", "PCON19NM"]).rename( + columns={"PCON19NM": "constituency"} + ) + + def get_group_json(self, row): + return row[["Trust"]].dropna().rename({"Trust": "group_name"}).to_dict() + + def update_averages(self): + pass + + def update_max_min(self): + pass