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

Add generator and import script for TCC Common Grounds 2024 pledges #617

Merged
merged 1 commit into from
Nov 5, 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
2 changes: 1 addition & 1 deletion hub/management/commands/base_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def add_arguments(self, parser):
"-i", "--ignore", action="store_true", help="Ignore existing data file"
)

def _setup(self):
def _setup(self, *args, **kwargs):
pass

def handle(self, quiet=False, ignore=False, *args, **options):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from django.conf import settings

import pandas as pd

from .base_generators import BaseLatLonGeneratorCommand


class Command(BaseLatLonGeneratorCommand):
help = "Generate CSV file of pledges to take part in TCC’s 2024 Common Grounds Day of Action"
message = "Generating a CSV of pledges to take part in TCC’s 2024 Common Grounds Day of Action"

data_file = settings.BASE_DIR / "data" / "tcc_common_grounds_2024_pledges.csv"
out_file = (
settings.BASE_DIR / "data" / "tcc_common_grounds_2024_pledges_processed.csv"
)

row_name = "postcode"
uses_gss = True
uses_postcodes = True

def get_dataframe(self):
df = pd.read_csv(self.data_file, usecols=["POSTCODE"])
df.columns = ["postcode"]
return df

def get_location_from_row(self, row):
return {"postcode": row.postcode}
52 changes: 52 additions & 0 deletions hub/management/commands/import_tcc_common_grounds_2024_pledges.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
from django.conf import settings

from hub.models import AreaData, DataSet

from .base_importers import BaseConstituencyCountImportCommand, MultipleAreaTypesMixin


class Command(MultipleAreaTypesMixin, BaseConstituencyCountImportCommand):
help = "Import pledges to take part in TCC’s 2024 Common Grounds Day of Action"

message = (
"importing pledges to take part in TCC’s 2024 Common Grounds Day of Action"
)
uses_gss = True
cons_col = "gss"
data_file = (
settings.BASE_DIR / "data" / "tcc_common_grounds_2024_pledges_processed.csv"
)

area_types = ["WMC", "WMC23", "STC", "DIS"]
cons_col_map = {
"WMC": "WMC",
"WMC23": "WMC23",
"STC": "STC",
"DIS": "DIS",
}

defaults = {
"label": "Constituents pledged to meet MP as part of Common Grounds 2024",
"data_type": "integer",
"category": "movement",
"release_date": "October 2024",
"source_label": "Data from The Climate Coalition.",
"source": "https://peopleclimatenature.org/",
"source_type": "csv",
"data_url": "",
"table": "areadata",
"default_value": 10,
"comparators": DataSet.numerical_comparators(),
"unit_type": "raw",
"unit_distribution": "people_in_area",
}

data_sets = {
"tcc_common_grounds_2024_pledges": {
"defaults": defaults,
},
}

def delete_data(self):
for data_type in self.data_types.values():
AreaData.objects.filter(data_type=data_type).delete()
Loading