Skip to content

Commit

Permalink
Apply GHG and GHGI unit versions to canonical columns (#4462)
Browse files Browse the repository at this point in the history
* eeej small files

* add ghg intensity options to org model

* add ghg intensity to org settings

* org migration for ghg display units

* precommit

* update tests

---------

Co-authored-by: Katherine Fleming <[email protected]>
  • Loading branch information
perryr16 and kflemin authored Jan 20, 2024
1 parent cc89f5a commit 1003ef9
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 0 deletions.
23 changes: 23 additions & 0 deletions seed/lib/superperms/orgs/migrations/0029_auto_20240105_1257.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.2.23 on 2024-01-05 20:57

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('orgs', '0028_organization_audit_template_report_type'),
]

operations = [
migrations.AlterField(
model_name='organization',
name='display_units_ghg',
field=models.CharField(choices=[('kgCO2e/year', 'kgCO2e/year'), ('MtCO2e/year', 'MtCO2e/year')], default='MtCO2e/year', max_length=32),
),
migrations.AlterField(
model_name='organization',
name='display_units_ghg_intensity',
field=models.CharField(choices=[('kgCO2e/ft**2/year', 'kgCO2e/ft²/year'), ('MtCO2e/ft**2/year', 'MtCO2e/ft²/year'), ('kgCO2e/m**2/year', 'kgCO2e/m²/year'), ('MtCO2e/m**2/year', 'MtCO2e/m²/year')], default='kgCO2e/ft**2/year', max_length=32),
),
]
4 changes: 4 additions & 0 deletions seed/lib/superperms/orgs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,15 @@ class Organization(models.Model):
)

MEASUREMENT_CHOICES_GHG = (
('kgCO2e/year', 'kgCO2e/year'),
('MtCO2e/year', 'MtCO2e/year'),
)

MEASUREMENT_CHOICES_GHG_INTENSITY = (
('kgCO2e/ft**2/year', 'kgCO2e/ft²/year'),
('MtCO2e/ft**2/year', 'MtCO2e/ft²/year'),
('kgCO2e/m**2/year', 'kgCO2e/m²/year'),
('MtCO2e/m**2/year', 'MtCO2e/m²/year'),
)

US = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,36 @@ angular.module('BE.seed.controller.organization_settings', []).controller('organ
}
];

$scope.unit_options_ghg = [
{
label: $translate.instant('kgCO2e/year'),
value: 'kgCO2e/year'
},
{
label: $translate.instant('MtCO2e/year'),
value: 'MtCO2e/year'
},
]

$scope.unit_options_ghg_intensity = [
{
label: $translate.instant('kgCO2e/ft²/year'),
value: 'kgCO2e/ft**2/year'
},
{
label: $translate.instant('kgCO2e/m²/year'),
value: 'kgCO2e/m**2/year'
},
{
label: $translate.instant('MtCO2e/ft²/year'),
value: 'MtCO2e/ft**2/year'
},
{
label: $translate.instant('MtCO2e/m²/year'),
value: 'MtCO2e/m**2/year'
},
]

// Ideally, these units and types for meters should be translatable.
$scope.chosen_type_unit = {
type: null,
Expand Down
28 changes: 28 additions & 0 deletions seed/static/seed/partials/organization_settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,34 @@ <h3 translate>Measurement unit display for energy use intensities (EUI)</h3>
</div>
</div>

<div class="section_content_container">
<div class="section_content with_padding">
<h3 translate>Measurement unit display for Green House Gas Emissions (GHG)</h3>
<form class="form-horizontal" role="form">
<div class="form-group">
<div class="col-sm-4">
<select class="form-control" ng-options="o.value as o.label for o in unit_options_ghg"
ng-model="org.display_units_ghg"></select>
</div>
</div>
</form>
</div>
</div>

<div class="section_content_container">
<div class="section_content with_padding">
<h3 translate>Measurement unit display for Green House Gas Emission Intensity (GHGI)</h3>
<form class="form-horizontal" role="form">
<div class="form-group">
<div class="col-sm-4">
<select class="form-control" ng-options="o.value as o.label for o in unit_options_ghg_intensity"
ng-model="org.display_units_ghg_intensity"></select>
</div>
</div>
</form>
</div>
</div>

<div class="section_content_container">
<div class="section_content with_padding">
<h3 translate>METER_DISPLAY_SETTINGS_TITLE</h3>
Expand Down
6 changes: 6 additions & 0 deletions seed/tests/test_account_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ def test_dict_org(self):
'parent_id': self.org.pk,
'display_units_eui': 'kBtu/ft**2/year',
'display_units_area': 'ft**2',
'display_units_ghg': 'MtCO2e/year',
'display_units_ghg_intensity': 'kgCO2e/ft**2/year',
'display_decimal_places': 2,
'cycles': [{
'name': self.cal_year_name,
Expand Down Expand Up @@ -179,6 +181,8 @@ def test_dict_org_w_member_in_parent_and_child(self):
'parent_id': self.org.pk,
'display_units_eui': 'kBtu/ft**2/year',
'display_units_area': 'ft**2',
'display_units_ghg': 'MtCO2e/year',
'display_units_ghg_intensity': 'kgCO2e/ft**2/year',
'display_decimal_places': 2,
'cycles': [{
'name': self.cal_year_name,
Expand Down Expand Up @@ -211,6 +215,8 @@ def test_dict_org_w_member_in_parent_and_child(self):
'parent_id': self.org.pk,
'display_units_eui': 'kBtu/ft**2/year',
'display_units_area': 'ft**2',
'display_units_ghg': 'MtCO2e/year',
'display_units_ghg_intensity': 'kgCO2e/ft**2/year',
'display_decimal_places': 2,
'cycles': [{
'name': self.cal_year_name,
Expand Down
14 changes: 14 additions & 0 deletions seed/views/v3/organizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ def _dict_org(request, organizations):
'is_parent': o.is_parent,
'parent_id': o.parent_id,
'display_units_eui': o.display_units_eui,
'display_units_ghg': o.display_units_ghg,
'display_units_ghg_intensity': o.display_units_ghg_intensity,
'display_units_area': o.display_units_area,
'display_decimal_places': o.display_decimal_places,
'cycles': cycles,
Expand Down Expand Up @@ -500,6 +502,18 @@ def warn_bad_units(kind, unit_string):
else:
warn_bad_pint_spec('eui', desired_display_units_eui)

desired_display_units_ghg = posted_org.get('display_units_ghg')
if is_valid_choice(Organization.MEASUREMENT_CHOICES_GHG, desired_display_units_ghg):
org.display_units_ghg = desired_display_units_ghg
else:
warn_bad_pint_spec('ghg', desired_display_units_ghg)

desired_display_units_ghg_intensity = posted_org.get('display_units_ghg_intensity')
if is_valid_choice(Organization.MEASUREMENT_CHOICES_GHG_INTENSITY, desired_display_units_ghg_intensity):
org.display_units_ghg_intensity = desired_display_units_ghg_intensity
else:
warn_bad_pint_spec('ghg_intensity', desired_display_units_ghg_intensity)

desired_display_units_area = posted_org.get('display_units_area')
if is_valid_choice(Organization.MEASUREMENT_CHOICES_AREA, desired_display_units_area):
org.display_units_area = desired_display_units_area
Expand Down

0 comments on commit 1003ef9

Please sign in to comment.