Skip to content

Commit

Permalink
Merge pull request #1921 from SEED-platform/meter-display-settings-up…
Browse files Browse the repository at this point in the history
…dates

Meter display settings updates
  • Loading branch information
nllong committed Jul 19, 2019
2 parents 6535505 + 812863f commit d666183
Show file tree
Hide file tree
Showing 8 changed files with 203 additions and 83 deletions.
25 changes: 24 additions & 1 deletion seed/lib/superperms/orgs/migrations/0010_auto_20190616_1351.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,30 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='organization',
name='display_meter_units',
field=django.contrib.postgres.fields.jsonb.JSONField(default={'Coal (anthracite)': 'kBtu (thousand Btu)', 'Coal (bituminous)': 'kBtu (thousand Btu)', 'Coke': 'kBtu (thousand Btu)', 'Diesel': 'kBtu (thousand Btu)', 'District Chilled Water - Absorption': 'kBtu (thousand Btu)', 'District Chilled Water - Electric': 'kBtu (thousand Btu)', 'District Chilled Water - Engine': 'kBtu (thousand Btu)', 'District Chilled Water - Other': 'kBtu (thousand Btu)', 'District Hot Water': 'kBtu (thousand Btu)', 'District Steam': 'kBtu (thousand Btu)', 'Electric - Grid': 'kBtu (thousand Btu)', 'Electric - Solar': 'kBtu (thousand Btu)', 'Electric - Wind': 'kBtu (thousand Btu)', 'Fuel Oil (No. 1)': 'kBtu (thousand Btu)', 'Fuel Oil (No. 2)': 'kBtu (thousand Btu)', 'Fuel Oil (No. 4)': 'kBtu (thousand Btu)', 'Fuel Oil (No. 5 and No. 6)': 'kBtu (thousand Btu)', 'Kerosene': 'kBtu (thousand Btu)', 'Natural Gas': 'kBtu (thousand Btu)', 'Other:': 'kBtu (thousand Btu)', 'Propane': 'kBtu (thousand Btu)', 'Wood': 'kBtu (thousand Btu)'}),
field=django.contrib.postgres.fields.jsonb.JSONField(default={
'Coal (anthracite)': 'kBtu (thousand Btu)',
'Coal (bituminous)': 'kBtu (thousand Btu)',
'Coke': 'kBtu (thousand Btu)',
'Diesel': 'kBtu (thousand Btu)',
'District Chilled Water - Absorption': 'kBtu (thousand Btu)',
'District Chilled Water - Electric': 'kBtu (thousand Btu)',
'District Chilled Water - Engine': 'kBtu (thousand Btu)',
'District Chilled Water - Other': 'kBtu (thousand Btu)',
'District Hot Water': 'kBtu (thousand Btu)',
'District Steam': 'kBtu (thousand Btu)',
'Electric - Grid': 'kBtu (thousand Btu)',
'Electric - Solar': 'kBtu (thousand Btu)',
'Electric - Wind': 'kBtu (thousand Btu)',
'Fuel Oil (No. 1)': 'kBtu (thousand Btu)',
'Fuel Oil (No. 2)': 'kBtu (thousand Btu)',
'Fuel Oil (No. 4)': 'kBtu (thousand Btu)',
'Fuel Oil (No. 5 and No. 6)': 'kBtu (thousand Btu)',
'Kerosene': 'kBtu (thousand Btu)',
'Natural Gas': 'kBtu (thousand Btu)',
'Other:': 'kBtu (thousand Btu)',
'Propane': 'kBtu (thousand Btu)',
'Wood': 'kBtu (thousand Btu)'
}),
),
migrations.RunPython(update_display_meter_units_options),
]
74 changes: 74 additions & 0 deletions seed/lib/superperms/orgs/migrations/0011_auto_20190714_2159.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.21 on 2019-07-15 04:59
from __future__ import unicode_literals

import django.contrib.postgres.fields.jsonb
from django.db import migrations


def update_display_meter_units_options(apps, schema_editor):
Organization = apps.get_model('orgs', 'Organization')
default_display_options = {
'Coal (anthracite)': 'kBtu (thousand Btu)',
'Coal (bituminous)': 'kBtu (thousand Btu)',
'Coke': 'kBtu (thousand Btu)',
'Diesel': 'kBtu (thousand Btu)',
'District Chilled Water - Absorption': 'kBtu (thousand Btu)',
'District Chilled Water - Electric': 'kBtu (thousand Btu)',
'District Chilled Water - Engine': 'kBtu (thousand Btu)',
'District Chilled Water - Other': 'kBtu (thousand Btu)',
'District Hot Water': 'kBtu (thousand Btu)',
'District Steam': 'kBtu (thousand Btu)',
'Electric - Grid': 'kWh (thousand Watt-hours)',
'Electric - Solar': 'kWh (thousand Watt-hours)',
'Electric - Wind': 'kWh (thousand Watt-hours)',
'Fuel Oil (No. 1)': 'kBtu (thousand Btu)',
'Fuel Oil (No. 2)': 'kBtu (thousand Btu)',
'Fuel Oil (No. 4)': 'kBtu (thousand Btu)',
'Fuel Oil (No. 5 and No. 6)': 'kBtu (thousand Btu)',
'Kerosene': 'kBtu (thousand Btu)',
'Natural Gas': 'kBtu (thousand Btu)',
'Other:': 'kBtu (thousand Btu)',
'Propane': 'kBtu (thousand Btu)',
'Wood': 'kBtu (thousand Btu)'
}
Organization.objects.all().update(display_meter_units=default_display_options)


class Migration(migrations.Migration):

dependencies = [
('orgs', '0010_auto_20190616_1351'),
]

operations = [
migrations.AlterField(
model_name='organization',
name='display_meter_units',
field=django.contrib.postgres.fields.jsonb.JSONField(default={
'Coal (anthracite)': 'kBtu (thousand Btu)',
'Coal (bituminous)': 'kBtu (thousand Btu)',
'Coke': 'kBtu (thousand Btu)',
'Diesel': 'kBtu (thousand Btu)',
'District Chilled Water - Absorption': 'kBtu (thousand Btu)',
'District Chilled Water - Electric': 'kBtu (thousand Btu)',
'District Chilled Water - Engine': 'kBtu (thousand Btu)',
'District Chilled Water - Other': 'kBtu (thousand Btu)',
'District Hot Water': 'kBtu (thousand Btu)',
'District Steam': 'kBtu (thousand Btu)',
'Electric - Grid': 'kWh (thousand Watt-hours)',
'Electric - Solar': 'kWh (thousand Watt-hours)',
'Electric - Wind': 'kWh (thousand Watt-hours)',
'Fuel Oil (No. 1)': 'kBtu (thousand Btu)',
'Fuel Oil (No. 2)': 'kBtu (thousand Btu)',
'Fuel Oil (No. 4)': 'kBtu (thousand Btu)',
'Fuel Oil (No. 5 and No. 6)': 'kBtu (thousand Btu)',
'Kerosene': 'kBtu (thousand Btu)',
'Natural Gas': 'kBtu (thousand Btu)',
'Other:': 'kBtu (thousand Btu)',
'Propane': 'kBtu (thousand Btu)',
'Wood': 'kBtu (thousand Btu)'
}),
),
migrations.RunPython(update_display_meter_units_options),
]
27 changes: 22 additions & 5 deletions seed/lib/superperms/orgs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from django.db import models
from django.db.models.signals import pre_delete

from seed.data_importer.utils import kbtu_thermal_conversion_factors
from seed.lib.superperms.orgs.exceptions import TooManyNestedOrgs

_log = logging.getLogger(__name__)
Expand Down Expand Up @@ -104,11 +103,29 @@ class Organization(models.Model):
(CAN, 'CAN'),
)

# US factors are usable here as the type-unit combinations are the same (though actual factors differ).
_default_display_meter_units = {
type: 'kBtu (thousand Btu)'
for type, _units
in kbtu_thermal_conversion_factors("US").items()
'Coal (anthracite)': 'kBtu (thousand Btu)',
'Coal (bituminous)': 'kBtu (thousand Btu)',
'Coke': 'kBtu (thousand Btu)',
'Diesel': 'kBtu (thousand Btu)',
'District Chilled Water - Absorption': 'kBtu (thousand Btu)',
'District Chilled Water - Electric': 'kBtu (thousand Btu)',
'District Chilled Water - Engine': 'kBtu (thousand Btu)',
'District Chilled Water - Other': 'kBtu (thousand Btu)',
'District Hot Water': 'kBtu (thousand Btu)',
'District Steam': 'kBtu (thousand Btu)',
'Electric - Grid': 'kWh (thousand Watt-hours)',
'Electric - Solar': 'kWh (thousand Watt-hours)',
'Electric - Wind': 'kWh (thousand Watt-hours)',
'Fuel Oil (No. 1)': 'kBtu (thousand Btu)',
'Fuel Oil (No. 2)': 'kBtu (thousand Btu)',
'Fuel Oil (No. 4)': 'kBtu (thousand Btu)',
'Fuel Oil (No. 5 and No. 6)': 'kBtu (thousand Btu)',
'Kerosene': 'kBtu (thousand Btu)',
'Natural Gas': 'kBtu (thousand Btu)',
'Other:': 'kBtu (thousand Btu)',
'Propane': 'kBtu (thousand Btu)',
'Wood': 'kBtu (thousand Btu)'
}

class Meta:
Expand Down
90 changes: 58 additions & 32 deletions seed/static/seed/js/controllers/organization_settings_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,24 @@ angular.module('BE.seed.controller.organization_settings', []).controller('organ

$scope.org_static = angular.copy($scope.org);

$scope.unit_options_eui = [
{ label: $translate.instant('kBtu/sq. ft./year'), value: 'kBtu/ft**2/year' },
{ label: $translate.instant('GJ/m²/year'), value: 'GJ/m**2/year' },
{ label: $translate.instant('MJ/m²/year'), value: 'MJ/m**2/year' },
{ label: $translate.instant('kWh/m²/year'), value: 'kWh/m**2/year' },
{ label: $translate.instant('kBtu/m²/year'), value: 'kBtu/m**2/year' }
];
$scope.unit_options_eui = [{
label: $translate.instant('kBtu/sq. ft./year'),
value: 'kBtu/ft**2/year'
}, {
label: $translate.instant('GJ/m²/year'),
value: 'GJ/m**2/year'
}, {
label: $translate.instant('MJ/m²/year'),
value: 'MJ/m**2/year'
}, {
label: $translate.instant('kWh/m²/year'),
value: 'kWh/m**2/year'
}, {
label: $translate.instant('kBtu/m²/year'),
value: 'kBtu/m**2/year'
}];

// Ideally, these the units and types for meters should be translatable.
// Ideally, these units and types for meters should be translatable.
$scope.chosen_type_unit = {
type: null,
unit: null
Expand All @@ -39,7 +48,10 @@ angular.module('BE.seed.controller.organization_settings', []).controller('organ
// Energy type option executed within this method in order to repeat on organization update
var get_energy_type_options = function () {
$scope.energy_type_options = _.map($scope.org.display_meter_units, function (unit, type) {
return { label: type + ' | ' + unit, value: type };
return {
label: type + ' | ' + unit,
value: type
};
});
};
get_energy_type_options();
Expand All @@ -48,15 +60,14 @@ angular.module('BE.seed.controller.organization_settings', []).controller('organ
$scope.energy_unit_options = results;
});

$scope.energy_unit_options_for_type = [];

$scope.get_valid_units_for_type = function () {
// Clear current unit choice to avoid possibility of invalid choice persisting
$scope.chosen_type_unit.unit = null;

$scope.energy_unit_options_for_type = _.map($scope.energy_unit_options[$scope.chosen_type_unit.type], function (unit) {
return { label: unit, value: unit };
});
var options = $scope.energy_unit_options[$scope.chosen_type_unit.type];
var previous_unit = $scope.org.display_meter_units[$scope.chosen_type_unit.type];
if (_.includes(options, previous_unit)) {
$scope.chosen_type_unit.unit = previous_unit;
} else {
$scope.chosen_type_unit.unit = null;
}
};

// Called when save_settings is called to update the scoped org before org save request is sent.
Expand All @@ -70,23 +81,38 @@ angular.module('BE.seed.controller.organization_settings', []).controller('organ
}
};

$scope.unit_options_area = [
{ label: $translate.instant('square feet'), value: 'ft**2' },
{ label: $translate.instant('square metres'), value: 'm**2' }
];
$scope.unit_options_area = [{
label: $translate.instant('square feet'),
value: 'ft**2'
}, {
label: $translate.instant('square metres'),
value: 'm**2'
}];

$scope.significant_figures_options = [
{ label: '0', value: 0 },
{ label: '0.1', value: 1 },
{ label: '0.02', value: 2 },
{ label: '0.003', value: 3 },
{ label: '0.0004', value: 4 }
];
$scope.significant_figures_options = [{
label: '0',
value: 0
}, {
label: '0.1',
value: 1
}, {
label: '0.02',
value: 2
}, {
label: '0.003',
value: 3
}, {
label: '0.0004',
value: 4
}];

$scope.thermal_conversion_countries = [
{ label: 'US', value: 1 },
{ label: 'Canada', value: 2 }
];
$scope.thermal_conversion_countries = [{
label: 'US',
value: 1
}, {
label: 'Canada',
value: 2
}];

/**
* saves the updates settings
Expand Down
1 change: 0 additions & 1 deletion seed/static/seed/js/services/meter_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ angular.module('BE.seed.service.meter', [])
if (_.isUndefined(excluded_meter_ids)) excluded_meter_ids = [];
return $http.post('/api/v2/meters/property_meter_usage/', {
property_view_id: property_view_id,
organization_id: organization_id,
interval: interval,
excluded_meter_ids: excluded_meter_ids
}).then(function (response) {
Expand Down
40 changes: 13 additions & 27 deletions seed/static/seed/partials/organization_settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
<div class="page_title">
<h1>{$ org_static.name $}</h1>
</div>
<div class="right page_action_container">
</div>
<div class="right page_action_container"></div>
</div>
</div>
<div class="section_nav_container">
Expand All @@ -20,7 +19,8 @@ <h1>{$ org_static.name $}</h1>
<h2><i class="fa fa-cogs"></i> {$:: 'Settings' | translate $}</h2>
</div>
<div class="section_action_container right section_action_btn">
<button type="button" class="pull-right btn btn-primary" ng-click="save_settings()">{$:: 'Save Changes' | translate $} <i class="fa fa-check" ng-show="settings_updated"></i></button>
<button type="button" class="pull-right btn btn-primary" ng-click="save_settings()">{$:: 'Save Changes' | translate $}
<i class="fa fa-check" ng-show="settings_updated"></i></button>
</div>
</div>
</div>
Expand All @@ -43,9 +43,7 @@ <h3 translate>Measurement unit display for energy use intensities (EUI)</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_eui"
ng-model="org.display_units_eui"></select>
<select class="form-control" ng-options="o.value as o.label for o in unit_options_eui" ng-model="org.display_units_eui"></select>
</div>
</div>
</form>
Expand All @@ -58,21 +56,15 @@ <h3 translate>METER_DISPLAY_SETTINGS_TITLE</h3>
<form class="form-horizontal" role="form">
<div class="form-group">
<div class="col-sm-4">
<select class="form-control"
ng-change="get_valid_units_for_type()"
ng-options="type.value as type.label for type in energy_type_options"
ng-model="chosen_type_unit.type">
<option value="" translate>ENERGY_TYPE_DISPLAY_CHOICE_PLACEHOLDER</option>
<select class="form-control" ng-change="get_valid_units_for_type()" ng-options="type.value as type.label for type in energy_type_options" ng-model="chosen_type_unit.type">
<option value="" translate>ENERGY_TYPE_DISPLAY_CHOICE_PLACEHOLDER</option>
</select>
</div>
</div>
<div class="form-group" ng-if=chosen_type_unit.type>
<div class="form-group">
<div class="col-sm-4">
<select
class="form-control"
ng-options="unit.value as unit.label for unit in energy_unit_options_for_type"
ng-model="chosen_type_unit.unit">
<option value="" translate>ENERGY_UNIT_DISPLAY_CHOICE_PLACEHOLDER</option>
<select class="form-control" ng-disabled="chosen_type_unit.type === null" ng-options="unit as unit for unit in energy_unit_options[chosen_type_unit.type]" ng-model="chosen_type_unit.unit">
<option value="" translate>ENERGY_UNIT_DISPLAY_CHOICE_PLACEHOLDER</option>
</select>
</div>
</div>
Expand All @@ -86,9 +78,7 @@ <h3 translate>Measurement unit display for areas</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_area"
ng-model="org.display_units_area"></select>
<select class="form-control" ng-options="o.value as o.label for o in unit_options_area" ng-model="org.display_units_area"></select>
</div>
</div>
</form>
Expand All @@ -101,9 +91,7 @@ <h3 translate>Significant figures for EUIs and areas</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 significant_figures_options"
ng-model="org.display_significant_figures"></select>
<select class="form-control" ng-options="o.value as o.label for o in significant_figures_options" ng-model="org.display_significant_figures"></select>
</div>
</div>
</form>
Expand All @@ -116,9 +104,7 @@ <h3 translate>THERMAL_CONV_ASSUMPTION_TITLE</h3>
<form class="form-horizontal" role="form">
<div class="form-group">
<div class="col-sm-4" uib-popover="Warning: Meters will be imported as and viewed according to this assumption." popover-trigger="mouseenter" popover-placement="right-top">
<select class="form-control"
ng-options="country.value as country.label for country in thermal_conversion_countries"
ng-model="org.thermal_conversion_assumption"></select>
<select class="form-control" ng-options="country.value as country.label for country in thermal_conversion_countries" ng-model="org.thermal_conversion_assumption"></select>
</div>
</div>
</form>
Expand All @@ -131,7 +117,7 @@ <h3 translate>MapQuest API Key</h3>
<form class="form-horizontal" role="form">
<div class="form-group">
<div class="col-sm-4">
<input type="text" class="form-control" ng-model="org.mapquest_api_key" ng-disabled="::!auth.requires_owner">
<input type="text" class="form-control" ng-model="org.mapquest_api_key" ng-disabled="::!auth.requires_owner">
</div>
</div>
</form>
Expand Down

0 comments on commit d666183

Please sign in to comment.