Skip to content

Commit

Permalink
Added import service for ARC data, Created regions table for future m…
Browse files Browse the repository at this point in the history
…apping functionality, created region checker function to validate region strings, updated backend to account for data structure changes (#376)
  • Loading branch information
JulianForeman authored Aug 1, 2024
1 parent 5ab244a commit 8913558
Show file tree
Hide file tree
Showing 10 changed files with 308 additions and 74 deletions.
93 changes: 58 additions & 35 deletions django/api/constants/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,47 +23,60 @@
typo_checker,
location_checker,
email_validator,
validate_field_values
validate_field_values,
region_checker
)
from api.services.resolvers import get_google_resolver
from api.constants.misc import GER_VALID_FIELD_VALUES
from api.constants.misc import GER_VALID_FIELD_VALUES, ARC_VALID_FIELD_VALUES


from enum import Enum

class ARCProjectTrackingColumns(Enum):
FUNDING_CALL = "Funding Call"
REFERENCE_NUMBER = "Ref #"
PROPONENT = "Proponent"
REF_NUMBER = "Ref #"
STATUS = "Status"
FUNDING_CALL = "Funding Call"
PROJECT_TITLE = "Project Title"
VEHICLE_CATEGORY = "Vehicle Category"
ZEV_SUB_SECTOR = "ZEV Sub-Section"
FUEL_TYPE = "Fuel Type"
RETROFIT = "Retrofit"
PRIMARY_LOCATION = "Primary Location"
STATUS = "Status"
ARC_FUNDING = "ARC Funding"
FUNDS_ISSUED = "Funds Issued"
ECONOMIC_REGION = "Economic Region"
JOBS = "Jobs (FTEs)"
FUNDS_COMMITED = "Funds Committed"
FUNDS_DISBURSED = "Funds Disbursed"
REMAINING_DISBURSED = "Remaining To Disburse"
TOTAL_PROJECT_VALUE = "Total Project Value"
START_DATE = "Start Date"
COMPLETION_DATE = "Completion Date"
TOTAL_PROJECT_VALUE = "Total Project Value"
ZEV_SUB_SECTOR = "ZEV Sub-Sector"
ON_ROAD_OFF_ROAD = "On-Road/Off-Road"
FUEL_TYPE = "Fuel Type"
COMPLETE_OR_TERMINATION_DATE = "Complete or Termination date"
PUBLICLY_ANNOUNCED = "Publicly Announced"

NOTES = "Notes"

class ArcProjectTrackingColumnMapping(Enum):
funding_call = "Funding Call"
proponent = "Proponent"
reference_number = "Ref #"
proponent = "Proponent"
status = "Status"
funding_call = "Funding Call"
project_title = "Project Title"
vehicle_category = "Vehicle Category"
zev_sub_sector = "ZEV Sub-Section"
fuel_type = "Fuel Type"
retrofit = "Retrofit"
primary_location = "Primary Location"
status = "Status"
arc_funding = "ARC Funding"
funds_issued = "Funds Issued"
economic_region = "Economic Region"
jobs = "Jobs (FTEs)"
funds_commited = "Funds Committed"
funds_disbursed = "Funds Disbursed"
remaining_disbursed = "Remaining To Disburse"
total_project_value = "Total Project Value"
start_date = "Start Date"
completion_date = "Completion Date"
total_project_value = "Total Project Value"
zev_sub_sector = "ZEV Sub-Sector"
on_road_off_road = "On-Road/Off-Road"
fuel_type = "Fuel Type"
complete_or_termination_date = "Complete or Termination date"
publicly_announced = "Publicly Announced"

notes = "Notes"

class EVChargingRebatesColumns(Enum):
ORGANIZATION = "Organization"
Expand Down Expand Up @@ -414,21 +427,27 @@ class GoElectricRebatesColumnMapping(Enum):

FIELD_TYPES = {
"ARC Project Tracking": {
"funding_call": str,
"proponent": str,
"reference_number": str,
"project_title": str,
"primary_location": str,
"proponent": str,
"status": str,
"arc_funding": int,
"funds_issued": int,
"start_date": str,
"completion_date": str,
"total_project_value": int,
"funding_call": str,
"project_title": str,
"vehicle_category": str,
"zev_sub_sector": str,
"on_road_off_road": str,
"fuel_type": str,
"publicly_announced": bool,
"retrofit": str,
"primary_location": str,
"economic_region": str,
"jobs": int,
"funds_commited": int,
"funds_disbursed": int,
"remaining_disbursed": int,
"total_project_value": int,
"start_date": datetime.date,
"completion_date": datetime.date,
"complete_or_termination_date": datetime.date,
"publicly_announced": str,
"notes": str,
},
"EV Charging Rebates": {
"organization": str,
Expand Down Expand Up @@ -596,8 +615,12 @@ class GoElectricRebatesColumnMapping(Enum):
"model": ARCProjectTracking,
"columns": ARCProjectTrackingColumns,
"column_mapping": ArcProjectTrackingColumnMapping,
"sheet_name": "Project_Tracking",
"sheet_name": "ARC Data",
"preparation_functions": [prepare_arc_project_tracking],
"validation_functions": [
{'function': validate_field_values, "columns": [], "kwargs": {"indices_offset":2, "fields_and_values": ARC_VALID_FIELD_VALUES}},
{"function": region_checker, "columns": ['Economic Region'], "kwargs": {"indices_offset":2}},
]
},
"EV Charging Rebates": {
"model": ChargerRebates,
Expand Down Expand Up @@ -659,7 +682,7 @@ class GoElectricRebatesColumnMapping(Enum):
{"function": typo_checker, "columns": ["Applicant Name"], "kwargs": {"cutoff": 0.8, "indices_offset": 2}},
{"function": location_checker, "columns": ["City"], "kwargs": {"indices_offset":2}},
{"function": email_validator, "columns": ["Email"], "kwargs": {"indices_offset":2, "get_resolver": get_google_resolver}},
{"function": validate_field_values, "columns": [], "kwargs": {"indices_offset":2, "fields_and_values": GER_VALID_FIELD_VALUES}}
{"function": validate_field_values, "columns": [], "kwargs": {"indices_offset":2, "fields_and_values": GER_VALID_FIELD_VALUES}},
]
},
}
15 changes: 14 additions & 1 deletion django/api/constants/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,17 @@
'Fleet/Individuals': ['Fleet', 'Individual'],
'Rebate adjustment (discount)': ['Yes'],
'Class': ['2B', '3', '4', '5', '6', '7', '8']
}
}

ARC_VALID_FIELD_VALUES = {
'Funding Call': ['ARC-2018-1', 'ARC-2020-2'],
'Status': ['Approved', 'Completed', 'Terminated'],
'Vehicle Category': ['On-Road', 'On/Off Road', 'Marine', 'Aviation', 'Off-Road'],
'Zev Sub-Section': [
'Testing and certification services', 'Battery components',
'Vehicle components', 'Fuelling Infrastructure', 'Vehicles',
'Transferable Technologies'
],
'Fuel Type': ['H2', 'Electric'],
'Retrofit': ['BEV Retrofit', 'Hybrid Retrofit', 'H2 Retrofit', 'N/A']
}
112 changes: 112 additions & 0 deletions django/api/migrations/0032_auto_20240726_2118.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# Generated by Django 3.2.25 on 2024-07-26 21:18

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api', '0031_auto_20240712_2036'),
]

operations = [
migrations.RenameField(
model_name='arcprojecttracking',
old_name='arc_funding',
new_name='funds_disbursed',
),
migrations.RenameField(
model_name='arcprojecttracking',
old_name='funds_issued',
new_name='jobs',
),
migrations.RenameField(
model_name='arcprojecttracking',
old_name='on_road_off_road',
new_name='notes',
),
migrations.AddField(
model_name='arcprojecttracking',
name='complete_or_termination_date',
field=models.DateField(blank=True, null=True),
),
migrations.AddField(
model_name='arcprojecttracking',
name='economic_region',
field=models.CharField(default='Across BC', max_length=250),
preserve_default=False,
),
migrations.AddField(
model_name='arcprojecttracking',
name='funds_commited',
field=models.IntegerField(default=0),
preserve_default=False,
),
migrations.AddField(
model_name='arcprojecttracking',
name='remaining_disbursed',
field=models.IntegerField(blank=True, null=True),
),
migrations.AddField(
model_name='arcprojecttracking',
name='retrofit',
field=models.CharField(blank=True, max_length=250, null=True),
),
migrations.AddField(
model_name='arcprojecttracking',
name='vehicle_category',
field=models.CharField(default='A', max_length=250),
preserve_default=False,
),
migrations.AlterField(
model_name='arcprojecttracking',
name='completion_date',
field=models.DateField(blank=True, null=True),
),
migrations.AlterField(
model_name='arcprojecttracking',
name='funding_call',
field=models.CharField(default='a', max_length=50),
preserve_default=False,
),
migrations.AlterField(
model_name='arcprojecttracking',
name='primary_location',
field=models.CharField(default='BC', max_length=250),
preserve_default=False,
),
migrations.AlterField(
model_name='arcprojecttracking',
name='project_title',
field=models.CharField(default='Title', max_length=500),
preserve_default=False,
),
migrations.AlterField(
model_name='arcprojecttracking',
name='proponent',
field=models.CharField(default='test', max_length=500),
preserve_default=False,
),
migrations.AlterField(
model_name='arcprojecttracking',
name='publicly_announced',
field=models.CharField(blank=True, max_length=250, null=True),
),
migrations.AlterField(
model_name='arcprojecttracking',
name='reference_number',
field=models.CharField(default=0, max_length=50),
preserve_default=False,
),
migrations.AlterField(
model_name='arcprojecttracking',
name='start_date',
field=models.DateField(blank=True, null=True),
),
migrations.AlterField(
model_name='arcprojecttracking',
name='status',
field=models.CharField(default='Valid', max_length=250),
preserve_default=False,
),
]
27 changes: 27 additions & 0 deletions django/api/migrations/0033_regions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 3.2.25 on 2024-07-31 17:42

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api', '0032_auto_20240726_2118'),
]

operations = [
migrations.CreateModel(
name='Regions',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('create_timestamp', models.DateTimeField(auto_now_add=True, null=True)),
('create_user', models.CharField(default='SYSTEM', max_length=130)),
('update_timestamp', models.DateTimeField(auto_now=True, null=True)),
('update_user', models.CharField(max_length=130, null=True)),
('name', models.CharField(max_length=250)),
],
options={
'db_table': 'regions',
},
),
]
1 change: 1 addition & 0 deletions django/api/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@
from . import uploaded_vins_file
from . import uploaded_vin_record
from . import decoded_vin_record
from . import regions
56 changes: 36 additions & 20 deletions django/api/models/arc_project_tracking.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,63 @@

class ARCProjectTracking(Auditable):

funding_call = models.CharField(blank=True, null=True, max_length=50, unique=False)

proponent = models.CharField(blank=True, null=True, max_length=500, unique=False)

reference_number = models.CharField(
blank=True, null=True, max_length=50, unique=False
blank=False, null=False, max_length=50, unique=False
)

proponent = models.CharField(blank=False, null=False, max_length=500, unique=False)

status = models.CharField(blank=False, null=False, max_length=250, unique=False)

funding_call = models.CharField(blank=False, null=False, max_length=50, unique=False)

project_title = models.CharField(
blank=True, null=True, max_length=500, unique=False
blank=False, null=False, max_length=500, unique=False
)

primary_location = models.CharField(
blank=True, null=True, max_length=250, unique=False
vehicle_category = models.CharField(
blank=False, null=False, max_length=250
)

status = models.CharField(blank=True, null=True, max_length=250, unique=False)
zev_sub_sector = models.CharField(
blank=True, null=True, max_length=250, unique=False
)

arc_funding = models.IntegerField(blank=True, null=True)
fuel_type = models.CharField(blank=True, null=True, max_length=250, unique=False)

funds_issued = models.IntegerField(blank=True, null=True)
retrofit = models.CharField(blank=True, null=True, max_length=250)

start_date = models.CharField(blank=True, null=True, max_length=250, unique=False)
primary_location = models.CharField(
blank=False, null=False, max_length=250, unique=False
)

completion_date = models.CharField(
blank=True, null=True, max_length=250, unique=False
economic_region = models.CharField(
blank=False, null=False, max_length=250
)

jobs = models.IntegerField(blank=True, null=True)

funds_commited = models.IntegerField(blank=False, null=False)

funds_disbursed = models.IntegerField(blank=True, null=True)

remaining_disbursed = models.IntegerField(blank=True, null=True)

total_project_value = models.IntegerField(blank=True, null=True)

zev_sub_sector = models.CharField(
blank=True, null=True, max_length=250, unique=False
start_date = models.DateField(blank=True, null=True, unique=False)

completion_date = models.DateField(
blank=True, null=True, unique=False
)

on_road_off_road = models.CharField(
blank=True, null=True, max_length=250, unique=False
complete_or_termination_date = models.DateField(
blank=True, null=True, unique=False
)

fuel_type = models.CharField(blank=True, null=True, max_length=250, unique=False)
publicly_announced = models.CharField(blank=True, null=True, max_length=250)

publicly_announced = models.BooleanField(default=False)
notes = models.CharField(blank=True, null=True, max_length=250)

class Meta:
db_table = "arc_project_tracking"
Loading

0 comments on commit 8913558

Please sign in to comment.