Skip to content

Commit

Permalink
Great Big Green Week 2024 import
Browse files Browse the repository at this point in the history
Add a generic processing command to turn the spreadsheet of events into
one with constituencies. Add a new command for the 2024 events.

Fixes #593
  • Loading branch information
struan committed Sep 18, 2024
1 parent dc7dc4d commit 601b0ca
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 3 deletions.
6 changes: 5 additions & 1 deletion hub/management/commands/base_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"MTD": "STC",
"NMD": "DIS",
"DIS": "DIS",
"WMC": "WMC",
"WMC": "WMC23",
"WMCF": "WMC23",
}

Expand Down Expand Up @@ -166,12 +166,16 @@ def add_arguments(self, parser):
"-i", "--ignore", action="store_true", help="Ignore existing data file"
)

def _setup(self):
pass

def handle(self, quiet=False, ignore=False, *args, **options):
self._quiet = quiet

if not self._quiet:
self.stdout.write(self.message)
self._ignore = ignore
self._setup(*args, **options)
df = self.get_dataframe()
out_df = self.process_data(df)
self.save_data(out_df)
5 changes: 3 additions & 2 deletions hub/management/commands/base_importers.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ def add_data_sets(self, df=None):

def _fill_empty_entries(self):
for data_type in self.data_types.values():
datum_example = AreaData.objects.filter(data_type=data_type).first()
if (
data_type.data_type
in [
Expand All @@ -140,8 +141,8 @@ def _fill_empty_entries(self):
]
and data_type.data_set.table == "areadata"
and data_type.data_set.fill_blanks
and datum_example is not None
):
datum_example = AreaData.objects.filter(data_type=data_type).first()
if datum_example.float:
key = "float"
elif datum_example.int:
Expand Down Expand Up @@ -428,7 +429,7 @@ def process_data(self, df):
def handle(self, quiet=False, *args, **options):
self._quiet = quiet
df = self.get_dataframe()
if not df:
if df.empty:
if not self._quiet:
self.stdout.write(f"missing data for {self.message} ({self.area_type})")
return
Expand Down
28 changes: 28 additions & 0 deletions hub/management/commands/generate_gbgw_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from django.conf import settings

from .base_generators import BaseLatLonGeneratorCommand


class Command(BaseLatLonGeneratorCommand):
help = "Generate CSV file of GBGW events with area name'"
message = "Generating a CSV of areas for GBGW events"

row_name = "Organisation"

def add_arguments(self, parser):
super().add_arguments(parser)

parser.add_argument(
"--year",
required=True,
action="store",
help="The last two digits of the year for the events, e.g 24 for 2024",
)

def _setup(self, *args, **kwargs):
year = kwargs["year"]
self.data_file = settings.BASE_DIR / "data" / f"gbgw_events_{year}.csv"
self.out_file = settings.BASE_DIR / "data" / f"gbgw_events_{year}_processed.csv"

def get_location_from_row(self, row):
return {"lat_lon": [row.Lat, row.Long]}
43 changes: 43 additions & 0 deletions hub/management/commands/import_gbgw_events_24.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from django.conf import settings

from hub.models import DataSet

from .base_importers import BaseConstituencyCountImportCommand, MultipleAreaTypesMixin


class Command(MultipleAreaTypesMixin, BaseConstituencyCountImportCommand):
help = "Import data about number of GBGW events in 2024 per constituency"
message = "Importing 2024 GBGW events"
uses_gss = False

data_file = settings.BASE_DIR / "data" / "gbgw_events_24_processed.csv"

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

data_sets = {
"constituency_gbgw_2024_event_count": {
"defaults": {
"label": "Number of Great Big Green Week 2024 events",
"description": "Number of public Great Big Green week 2024 events held in the area. This exludes any private events that were held.",
"release_date": "September 2024",
"data_type": "integer",
"category": "movement",
"subcategory": "events",
"source_label": "Data from The Climate Coalition.",
"source": "https://greatbiggreenweek.com/",
"source_type": "google sheet",
"data_url": "",
"table": "areadata",
"is_public": True,
"default_value": 10,
"comparators": DataSet.numerical_comparators(),
"unit_type": "raw",
"unit_distribution": "people_in_area",
}
}
}

0 comments on commit 601b0ca

Please sign in to comment.