From e956ba5800f7851013bc0531ae3e50ec2805801b Mon Sep 17 00:00:00 2001 From: Alexander Griffen Date: Tue, 19 Dec 2023 09:46:26 +0000 Subject: [PATCH 1/2] DATASET: Christian aid campaign organisers --- ...mport_christian_aid_campaign_organisers.py | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 hub/management/commands/import_christian_aid_campaign_organisers.py 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..04726a83d --- /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": "Campaign organisers are constituents trained by Christian Aid to campaign for climate justice in their local church and community.", + "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_christian_aid_campaign_organisers_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 "Number of Christian Aid climate campaign organisers" + + def delete_data(self): + AreaData.objects.filter(data_type__in=self.data_types.values()).delete() From 81cb336e8d5faf9b1c62a946758985bf5eaec784 Mon Sep 17 00:00:00 2001 From: Struan Donald Date: Mon, 8 Jan 2024 17:12:41 +0000 Subject: [PATCH 2/2] increase the length of dataset name fields --- .../0054_increase_dataset_name_length.py | 23 +++++++++++++++++++ hub/models.py | 4 ++-- 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 hub/migrations/0054_increase_dataset_name_length.py diff --git a/hub/migrations/0054_increase_dataset_name_length.py b/hub/migrations/0054_increase_dataset_name_length.py new file mode 100644 index 000000000..70d047e35 --- /dev/null +++ b/hub/migrations/0054_increase_dataset_name_length.py @@ -0,0 +1,23 @@ +# Generated by Django 4.2.5 on 2024-01-08 17:11 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("hub", "0053_alter_dataset_release_date"), + ] + + operations = [ + migrations.AlterField( + model_name="dataset", + name="name", + field=models.CharField(max_length=100, unique=True), + ), + migrations.AlterField( + model_name="datatype", + name="name", + field=models.CharField(max_length=100), + ), + ] diff --git a/hub/models.py b/hub/models.py index 036f94b77..5dddb75ed 100644 --- a/hub/models.py +++ b/hub/models.py @@ -333,7 +333,7 @@ def in_comparators(): def options_default(): return [] - name = models.CharField(max_length=50, unique=True) + name = models.CharField(max_length=100, unique=True) description = models.TextField(blank=True, null=True) label = models.CharField(max_length=200, blank=True, null=True) data_type = models.CharField(max_length=20, choices=TypeMixin.TYPE_CHOICES) @@ -400,7 +400,7 @@ def filter(self, query, **kwargs): class DataType(TypeMixin, ShaderMixin, models.Model): data_set = models.ForeignKey(DataSet, on_delete=models.CASCADE) - name = models.CharField(max_length=50) + name = models.CharField(max_length=100) data_type = models.CharField(max_length=20, choices=TypeMixin.TYPE_CHOICES) last_update = models.DateTimeField(auto_now=True) average = models.FloatField(blank=True, null=True)