Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DATASET: Christian aid campaign organisers #375

Merged
merged 2 commits into from
Jan 9, 2024
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
Original file line number Diff line number Diff line change
@@ -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()
23 changes: 23 additions & 0 deletions hub/migrations/0054_increase_dataset_name_length.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
4 changes: 2 additions & 2 deletions hub/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Loading