Skip to content

Commit

Permalink
Merge pull request #2973 from SEED-platform/refactor/float-decimal-di…
Browse files Browse the repository at this point in the history
…splay

refactor: use org decimal settings for floats and derived cols
  • Loading branch information
macintoshpie committed Nov 1, 2021
2 parents adf4609 + 8578c6b commit bbb2eeb
Show file tree
Hide file tree
Showing 26 changed files with 84 additions and 43 deletions.
Binary file modified locale/en_US/LC_MESSAGES/django.mo
Binary file not shown.
6 changes: 3 additions & 3 deletions locale/en_US/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -1656,6 +1656,9 @@ msgstr "Number of Properties"
msgid "Number of Tax Lots"
msgstr "Number of Tax Lots"

msgid "Number of decimal places to display"
msgstr "Number of decimal places to display"

msgid "OK_TO_DELETE_NUM_PROPERTIES_AND_TAXLOTS"
msgstr "Are you sure you want to delete {num_properties,plural, one{<strong>1</strong> property} other{<strong>#</strong> properties}} and {num_taxlots,plural,one{<strong>1</strong> tax lot} other{<strong>#</strong> tax lots}}?"

Expand Down Expand Up @@ -2295,9 +2298,6 @@ msgstr "Show/Hide Columns"
msgid "Signature"
msgstr "Signature"

msgid "Significant figures for EUIs and areas"
msgstr "Significant figures for EUIs and areas"

msgid "Site EUI"
msgstr "Site EUI"

Expand Down
Binary file modified locale/fr_CA/LC_MESSAGES/django.mo
Binary file not shown.
6 changes: 3 additions & 3 deletions locale/fr_CA/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -1669,6 +1669,9 @@ msgstr "Nombre de propriétés"
msgid "Number of Tax Lots"
msgstr "Nombre de lots d'impôt"

msgid "Number of decimal places to display"
msgstr "Nombre de décimales à afficher"

msgid "OK_TO_DELETE_NUM_PROPERTIES_AND_TAXLOTS"
msgstr "Voulez-vous vraiment supprimer {num_properties,plural,one{<strong>1</strong> propriété} other{<strong>#</strong> propriétés}} et {num_taxlots,plural,one{<strong>1</strong>lot d'impôt} other{<strong>#</strong> lots d'impôt}}?"

Expand Down Expand Up @@ -2315,9 +2318,6 @@ msgstr "Afficher/masquer les colonnes"
msgid "Signature"
msgstr "Signature"

msgid "Significant figures for EUIs and areas"
msgstr "Chiffres significatifs pour les IUE et les zones"

msgid "Site EUI"
msgstr "IUE site"

Expand Down
1 change: 1 addition & 0 deletions requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pycodestyle==2.6.0
Sphinx==2.3.1
sphinxcontrib-spelling==4.3.0
sphinx_rtd_theme==0.4.3
docutils==0.17.1

# property-based testing
hypothesis==6.12.0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.7 on 2021-10-27 20:50

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('orgs', '0019_organization_better_analysis_api_key'),
]

operations = [
migrations.RenameField(
model_name='organization',
old_name='display_significant_figures',
new_name='display_decimal_places',
),
]
2 changes: 1 addition & 1 deletion seed/lib/superperms/orgs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class Meta:
choices=MEASUREMENT_CHOICES_AREA,
blank=False,
default='ft**2')
display_significant_figures = models.PositiveSmallIntegerField(blank=False, default=2)
display_decimal_places = models.PositiveSmallIntegerField(blank=False, default=2)

created = models.DateTimeField(auto_now_add=True, null=True)
modified = models.DateTimeField(auto_now=True, null=True)
Expand Down
2 changes: 1 addition & 1 deletion seed/serializers/organizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class SaveSettingsOrganizationSerializer(serializers.Serializer):
public_fields = SaveSettingsOrgFieldSerializer(many=True)
display_units_eui = serializers.ChoiceField(choices=Organization.MEASUREMENT_CHOICES_EUI)
display_units_area = serializers.ChoiceField(choices=Organization.MEASUREMENT_CHOICES_AREA)
display_significant_figures = serializers.IntegerField(min_value=0)
display_decimal_places = serializers.IntegerField(min_value=0)
display_meter_units = serializers.JSONField()
thermal_conversion_assumption = serializers.ChoiceField(choices=Organization.THERMAL_CONVERSION_ASSUMPTION_CHOICES)
mapquest_api_key = serializers.CharField()
Expand Down
2 changes: 1 addition & 1 deletion seed/serializers/pint.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def collapse_unit(org, x):
dimensionality = get_dimensionality(x)
pint_spec = pint_specs[dimensionality]
converted_value = x.to(pint_spec).magnitude
return round(converted_value, org.display_significant_figures)
return round(converted_value, org.display_decimal_places)
elif isinstance(x, list):
# recurse out to collapse a dict for eg. the `related` key that
# contains properties when the pt_dict is for a taxlot and vice-versa
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ angular.module('BE.seed.controller.inventory_cycles', [])
options.cellFilter = 'date:\'yyyy-MM-dd h:mm a\'';
options.filter = inventory_service.dateFilter();
} else if (col.data_type === 'eui' || col.data_type === 'area') {
options.cellFilter = 'number: ' + $scope.organization.display_significant_figures;
options.cellFilter = 'number: ' + $scope.organization.display_decimal_places;
options.filter = inventory_service.combinedFilter();
} else {
options.filter = inventory_service.combinedFilter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ angular.module('BE.seed.controller.inventory_detail', [])
if (dataType === 'datetime') {
return $filter('date')(value, 'yyyy-MM-dd h:mm a');
} else if (dataType === 'eui' || dataType === 'area') {
return $filter('number')(value, $scope.organization.display_significant_figures);
return $filter('number')(value, $scope.organization.display_decimal_places);
}
return value;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ angular.module('BE.seed.controller.inventory_detail_cycles', [])
if (dataType === 'datetime') {
return $filter('date')(value, 'yyyy-MM-dd h:mm a');
} else if (dataType === 'eui' || dataType === 'area') {
return $filter('number')(value, $scope.organization.display_significant_figures);
return $filter('number')(value, $scope.organization.display_decimal_places);
}
return value;
};
Expand Down
15 changes: 14 additions & 1 deletion seed/static/seed/js/controllers/inventory_list_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -582,26 +582,39 @@ angular.module('BE.seed.controller.inventory_list', [])
};
_.map($scope.columns, function (col) {
var options = {};
// Modify cellTemplate
if (_.isMatch(col, {column_name: 'property_footprint', table_name: 'PropertyState'})) {
col.cellTemplate = '<div class="ui-grid-cell-contents" uib-tooltip-html="grid.appScope.polygon(row.entity, \'PropertyState\')" tooltip-append-to-body="true" tooltip-popup-delay="500">{{COL_FIELD CUSTOM_FILTERS}}</div>';
} else if (_.isMatch(col, {column_name: 'taxlot_footprint', table_name: 'TaxLotState'})) {
col.cellTemplate = '<div class="ui-grid-cell-contents" uib-tooltip-html="grid.appScope.polygon(row.entity, \'TaxLotState\')" tooltip-append-to-body="true" tooltip-popup-delay="500">{{COL_FIELD CUSTOM_FILTERS}}</div>';
} else {
col.cellTemplate = '<div class="ui-grid-cell-contents" uib-tooltip="{{COL_FIELD CUSTOM_FILTERS}}" tooltip-append-to-body="true" tooltip-popup-delay="500">{{COL_FIELD CUSTOM_FILTERS}}</div>';
}

// Modify headerCellClass
if (col.is_derived_column) {
col.headerCellClass = 'derived-column-display-name'
}

// Modify misc
if (col.data_type === 'datetime') {
options.cellFilter = 'date:\'yyyy-MM-dd h:mm a\'';
options.filter = inventory_service.dateFilter();
} else if (col.data_type === 'date') {
options.filter = inventory_service.dateFilter();
} else if (col.data_type === 'eui' || col.data_type === 'area') {
options.filter = inventory_service.combinedFilter();
options.cellFilter = 'number: ' + $scope.organization.display_significant_figures;
options.cellFilter = 'number: ' + $scope.organization.display_decimal_places;
options.sortingAlgorithm = naturalSort;
} else if (col.data_type === 'float' || col.is_derived_column) {
options.filter = inventory_service.combinedFilter();
options.cellFilter = 'number: ' + $scope.organization.display_decimal_places;
options.sortingAlgorithm = naturalSort;
} else {
options.filter = inventory_service.combinedFilter();
options.sortingAlgorithm = naturalSort;
}

if (col.column_name === 'number_properties' && col.related) options.treeAggregationType = 'total';
else if (col.related || col.is_extra_data) options.treeAggregationType = 'uniqueList';
return _.defaults(col, options, defaults);
Expand Down
2 changes: 1 addition & 1 deletion seed/static/seed/js/controllers/mapping_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ angular.module('BE.seed.controller.mapping', [])
options.cellFilter = 'date:\'yyyy-MM-dd h:mm a\'';
options.filter = inventory_service.dateFilter();
} else if (col.data_type === 'area' || col.data_type === 'eui') {
options.cellFilter = 'number: ' + $scope.organization.display_significant_figures;
options.cellFilter = 'number: ' + $scope.organization.display_decimal_places;
options.sortingAlgorithm = naturalSort;
} else {
options.filter = inventory_service.combinedFilter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,20 @@ angular.module('BE.seed.controller.organization_settings', []).controller('organ
value: 'm**2'
}];

$scope.significant_figures_options = [{
label: '0',
$scope.decimal_places_options = [{
label: '0 (e.g. 0)',
value: 0
}, {
label: '0.1',
label: '1 (e.g. 0.1)',
value: 1
}, {
label: '0.02',
label: '2 (e.g. 0.12)',
value: 2
}, {
label: '0.003',
label: '3 (e.g. 0.123)',
value: 3
}, {
label: '0.0004',
label: '4 (e.g. 0.1234)',
value: 4
}];

Expand Down
2 changes: 1 addition & 1 deletion seed/static/seed/locales/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@
"Number Properties": "Number Properties",
"Number of Properties": "Number of Properties",
"Number of Tax Lots": "Number of Tax Lots",
"Number of decimal places to display": "Number of decimal places to display",
"OK_TO_DELETE_NUM_PROPERTIES_AND_TAXLOTS": "Are you sure you want to delete {num_properties,plural, one{<strong>1<\/strong> property} other{<strong>#<\/strong> properties}} and {num_taxlots,plural,one{<strong>1<\/strong> tax lot} other{<strong>#<\/strong> tax lots}}?",
"OR": "OR",
"ORG_MATCH_MERGE_LINK_WARNING": "WARNING: You have modified the criteria that your organization's data will be matched and merged against. Records in each cycle will be reevaluated to determine if matches exist, and if so they will be automatically merged. Then the records across multiple cycles will be reevaluated to update property and taxlot links or associations. If you continue you may first preview the pending changes before committing.",
Expand Down Expand Up @@ -741,7 +742,6 @@
"Show only mapped fields": "Show only mapped fields",
"Show\/Hide Columns": "Show\/Hide Columns",
"Signature": "Signature",
"Significant figures for EUIs and areas": "Significant figures for EUIs and areas",
"Site EUI": "Site EUI",
"Site EUI Weather Normalized": "Site EUI Weather Normalized",
"Site Energy Use Intensity": "Site Energy Use Intensity",
Expand Down
2 changes: 1 addition & 1 deletion seed/static/seed/locales/fr_CA.json
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,7 @@
"Number Properties": "Propriétés du nombre",
"Number of Properties": "Nombre de propriétés",
"Number of Tax Lots": "Nombre de lots d'impôt",
"Number of decimal places to display": "Nombre de décimales à afficher",
"OK_TO_DELETE_NUM_PROPERTIES_AND_TAXLOTS": "Voulez-vous vraiment supprimer {num_properties,plural,one{<strong>1<\/strong> propriété} other{<strong>#<\/strong> propriétés}} et {num_taxlots,plural,one{<strong>1<\/strong>lot d'impôt} other{<strong>#<\/strong> lots d'impôt}}?",
"OR": "OU",
"ORG_MATCH_MERGE_LINK_WARNING": "AVERTISSEMENT: vous avez modifié les critères de correspondance et de fusion des données de votre organisation. Les enregistrements de chaque cycle seront réévalués pour déterminer s'il existe des correspondances et, le cas échéant, elles seront automatiquement fusionnées. Ensuite, les enregistrements de plusieurs cycles seront réévalués afin de mettre à jour les liens ou associations de propriété et de lot de taxe. Si vous continuez, vous pouvez d'abord visualiser les modifications en attente avant de les valider.",
Expand Down Expand Up @@ -741,7 +742,6 @@
"Show only mapped fields": "Afficher seulement les champs mappés",
"Show\/Hide Columns": "Afficher\/masquer les colonnes",
"Signature": "Signature",
"Significant figures for EUIs and areas": "Chiffres significatifs pour les IUE et les zones",
"Site EUI": "IUE site",
"Site EUI Weather Normalized": "IUE site météo normalisée",
"Site Energy Use Intensity": "Intensité d'utilisation de l'énergie au site",
Expand Down
4 changes: 2 additions & 2 deletions seed/static/seed/partials/organization_settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ <h3 translate>Measurement unit display for areas</h3>

<div class="section_content_container">
<div class="section_content with_padding">
<h3 translate>Significant figures for EUIs and areas</h3>
<h3 translate>Number of decimal places to display</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 decimal_places_options" ng-model="org.display_decimal_places"></select>
</div>
</div>
</form>
Expand Down
9 changes: 9 additions & 0 deletions seed/static/seed/scss/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4010,3 +4010,12 @@ iframe.analysis-results {
width: 300px;
}
}

// Inserts an fa-link in front of the element
// Used in the inventory list to identify derived columns
.derived-column-display-name::before {
font-family: 'FontAwesome';
content: "\f0c1";
margin: 0.5em 0 0 0.5em;
float: left;
}
2 changes: 1 addition & 1 deletion seed/static/seed/tests/inventory_detail_controller.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ describe('controller: inventory_detail_controller', function () {
organization_payload: {
organization: {
id: 1,
display_significant_figures: 2,
display_decimal_places: 2,
},
},
analyses_payload: {
Expand Down
2 changes: 1 addition & 1 deletion seed/static/seed/tests/mapping_controller.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ describe('controller: mapping_controller', function () {
const fake_organization_payload = {
status: 'success',
organization: {
display_significant_figures: 2,
display_decimal_places: 2,
id: 1,
}
}
Expand Down
2 changes: 1 addition & 1 deletion seed/static/seed/tests/property_detail_controller.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ describe('controller: inventory_detail_controller', function () {
organization_payload: {
organization: {
id: 1,
display_significant_figures: 2,
display_decimal_places: 2,
},
},
analyses_payload: {
Expand Down
2 changes: 1 addition & 1 deletion seed/static/seed/tests/taxlot_detail_controller.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ describe('controller: inventory_detail_controller', function () {
organization_payload: {
organization: {
id: 1,
display_significant_figures: 2,
display_decimal_places: 2,
},
},
analyses_payload: {
Expand Down
6 changes: 3 additions & 3 deletions seed/tests/test_account_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def test_dict_org(self):
'id': self.user.pk}],
'number_of_users': 1,
'name': 'my org',
'display_significant_figures': 2,
'display_decimal_places': 2,
'display_units_area': 'ft**2',
'display_units_eui': 'kBtu/ft**2/year',
'user_role': 'owner',
Expand Down Expand Up @@ -142,7 +142,7 @@ def test_dic_org_w_member_in_parent_and_child(self):
'user_is_owner': True,
'display_units_area': 'ft**2',
'display_units_eui': 'kBtu/ft**2/year',
'display_significant_figures': 2,
'display_decimal_places': 2,
'cycles': [{
'num_taxlots': 0,
'num_properties': 0,
Expand All @@ -168,7 +168,7 @@ def test_dic_org_w_member_in_parent_and_child(self):
'org_id': self.org.pk,
'id': self.org.pk,
'user_is_owner': True,
'display_significant_figures': 2,
'display_decimal_places': 2,
'display_units_area': 'ft**2',
'display_units_eui': 'kBtu/ft**2/year',
'cycles': [{
Expand Down
12 changes: 6 additions & 6 deletions seed/views/organizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def _dict_org(request, organizations):
'parent_id': o.parent_id,
'display_units_eui': o.display_units_eui,
'display_units_area': o.display_units_area,
'display_significant_figures': o.display_significant_figures,
'display_decimal_places': o.display_decimal_places,
'cycles': cycles,
'created': o.created.strftime('%Y-%m-%d') if o.created else '',
'mapquest_api_key': o.mapquest_api_key or '',
Expand Down Expand Up @@ -681,12 +681,12 @@ def warn_bad_units(kind, unit_string):
else:
warn_bad_pint_spec('area', desired_display_units_area)

desired_display_significant_figures = posted_org.get('display_significant_figures')
if isinstance(desired_display_significant_figures, int) and desired_display_significant_figures >= 0: # noqa
org.display_significant_figures = desired_display_significant_figures
elif desired_display_significant_figures is not None:
desired_display_decimal_places = posted_org.get('display_decimal_places')
if isinstance(desired_display_decimal_places, int) and desired_display_decimal_places >= 0: # noqa
org.display_decimal_places = desired_display_decimal_places
elif desired_display_decimal_places is not None:
_log.warn("got bad sig figs {0} for org {1}".format(
desired_display_significant_figures, org.name))
desired_display_decimal_places, org.name))

desired_display_meter_units = posted_org.get('display_meter_units')
if desired_display_meter_units:
Expand Down
12 changes: 6 additions & 6 deletions seed/views/v3/organizations.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def _dict_org(request, organizations):
'parent_id': o.parent_id,
'display_units_eui': o.display_units_eui,
'display_units_area': o.display_units_area,
'display_significant_figures': o.display_significant_figures,
'display_decimal_places': o.display_decimal_places,
'cycles': cycles,
'created': o.created.strftime('%Y-%m-%d') if o.created else '',
'mapquest_api_key': o.mapquest_api_key or '',
Expand Down Expand Up @@ -518,12 +518,12 @@ def warn_bad_units(kind, unit_string):
else:
warn_bad_pint_spec('area', desired_display_units_area)

desired_display_significant_figures = posted_org.get('display_significant_figures')
if isinstance(desired_display_significant_figures, int) and desired_display_significant_figures >= 0: # noqa
org.display_significant_figures = desired_display_significant_figures
elif desired_display_significant_figures is not None:
desired_display_decimal_places = posted_org.get('display_decimal_places')
if isinstance(desired_display_decimal_places, int) and desired_display_decimal_places >= 0: # noqa
org.display_decimal_places = desired_display_decimal_places
elif desired_display_decimal_places is not None:
_log.warn("got bad sig figs {0} for org {1}".format(
desired_display_significant_figures, org.name))
desired_display_decimal_places, org.name))

desired_display_meter_units = posted_org.get('display_meter_units')
if desired_display_meter_units:
Expand Down

0 comments on commit bbb2eeb

Please sign in to comment.