diff --git a/hub/management/commands/import_christian_aid_campaign_organisers.py b/hub/management/commands/import_christian_aid_campaign_organisers.py new file mode 100644 index 000000000..e6a59f8dd --- /dev/null +++ b/hub/management/commands/import_christian_aid_campaign_organisers.py @@ -0,0 +1,62 @@ +from django.conf import settings + +import pandas as pd + +from hub.models import AreaData, DataSet + +from .base_importers import BaseImportFromDataFrameCommand + + +class Command(BaseImportFromDataFrameCommand): + help = ( + "Import data about number of Christian Aid campaign organisers per constituency" + ) + + data_file = ( + settings.BASE_DIR + / "data" + / "Christian Aid climate campaign organisers - Data.csv" + ) + cons_row = "Constituency" + message = "Importing Christian Aid climate campaign organisers data" + uses_gss = False + + defaults = { + "data_type": "integer", + "category": "movement", + "subcategory": "supporters_and_activists", + "description": "Number of Christian Aid campaign organisers per constituency.", + "release_date": "February 2023", + "source_label": "Data from Christian Aid.", + "source": "https://www.christianaid.org.uk/", + "source_type": "google sheet", + "table": "areadata", + "default_value": 1, + "data_url": "", + "unit_type": "raw", + "unit_distribution": "people_in_area", + "comparators": DataSet.numerical_comparators(), + } + + data_sets = { + "constituency_foe_activists_count": { + "defaults": defaults, + "col": "organisers", + }, + } + + def get_dataframe(self): + df = pd.read_csv(self.data_file) + df = ( + df.groupby("Constituency") + .count() + .reset_index() + .rename(columns={"Postcode": "organisers"}) + ) + return df + + def get_label(self, defaults): + return f"Number of Christian Aid climate campaign organisers" + + def delete_data(self): + AreaData.objects.filter(data_type__in=self.data_types.values()).delete()