-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DATASET: Save the children supporters
- Loading branch information
1 parent
ae67f86
commit 6ee28f9
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
hub/management/commands/import_save_the_children_supporter_data.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
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 the number of Save the Children supporters per constituency" | ||
) | ||
|
||
message = "importing Save the Children shop count" | ||
uses_gss = False | ||
cons_row = "CONSTITUENCY" | ||
data_file = ( | ||
settings.BASE_DIR / "data" / "2022_Campaigning_Actions_By_Constituency 1.csv" | ||
) | ||
|
||
defaults = { | ||
"label": "Number of Save the Children supporters", | ||
"description": "The number of Save The Children supporters per constituency.", | ||
"data_type": "integer", | ||
"category": "movement", | ||
"subcategory": "supporters_and_activists", | ||
"source_label": "Data from Save the Children.", | ||
# "release_date": "2022", | ||
"source": "https://www.savethechildren.org.uk/", | ||
"source_type": "csv", | ||
"data_url": "", | ||
"table": "areadata", | ||
"default_value": 10, | ||
"comparators": DataSet.numerical_comparators(), | ||
"unit_type": "raw", | ||
"unit_distribution": "people_in_area", | ||
} | ||
|
||
data_sets = { | ||
"save_the_children_supporter_count": { | ||
"defaults": defaults, | ||
"col": "NUMBER_OF_SUPPORTERS", | ||
}, | ||
} | ||
|
||
def get_dataframe(self): | ||
df = pd.read_csv(self.data_file) | ||
return df | ||
|
||
def delete_data(self): | ||
for data_type in self.data_types.values(): | ||
AreaData.objects.filter(data_type=data_type).delete() |