Skip to content

Commit

Permalink
Merge pull request #1934 from SEED-platform/bricr-dev
Browse files Browse the repository at this point in the history
BRICR-dev changes into develop
  • Loading branch information
nllong committed Aug 6, 2019
2 parents e120119 + 28d1ba2 commit 8ba06bf
Show file tree
Hide file tree
Showing 16 changed files with 142 additions and 58 deletions.
13 changes: 11 additions & 2 deletions seed/building_sync/building_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ class BuildingSync(object):
"required": True,
"type": "string",
},
"property_type": {
"path": "auc:Sites.auc:Site.auc:Buildings.auc:Building.auc:Sections.auc:Section.auc:OccupancyClassification",
"required": True,
"type": "string",
},
"year_built": {
"path": "auc:Sites.auc:Site.auc:Buildings.auc:Building.auc:YearOfConstruction",
"required": True,
Expand Down Expand Up @@ -607,6 +612,7 @@ def _lookup_sub(node, key_path_name, key_path_value, value_path_name):
new_data['reference_case'] = ref_case.get('@IDref')
# fixed naming of existing scenario fields
new_data['annual_site_energy_savings'] = node.get('auc:AnnualSavingsSiteEnergy')
new_data['annual_source_energy_savings'] = node.get('auc:AnnualSavingsSourceEnergy')
new_data['annual_cost_savings'] = node.get('auc:AnnualSavingsCost')

# new scenario fields
Expand Down Expand Up @@ -637,10 +643,11 @@ def _lookup_sub(node, key_path_name, key_path_value, value_path_name):
resource_nodes = resource_nodes_arr

for rn in resource_nodes:
# print("RN: {}".format(rn))
if rn.get('auc:EndUse') == 'All end uses':
new_data['annual_site_energy'] = rn.get('auc:SiteEnergyUse')
# print("SITE ENERGY USE: {}".format(new_data['annual_site_energy']))
new_data['annual_site_energy_use_intensity'] = rn.get('auc:SiteEnergyUseIntensity')
new_data['annual_source_energy'] = rn.get('auc:SourceEnergyUse')
new_data['annual_source_energy_use_intensity'] = rn.get('auc:SourceEnergyUseIntensity')

resources = []
resource_uses = s.get('auc:ResourceUses')
Expand All @@ -665,6 +672,8 @@ def _lookup_sub(node, key_path_name, key_path_value, value_path_name):
# just do these 2 types for now
if ru.get('auc:EnergyResource') == 'Electricity':
new_data['annual_electricity_energy'] = ru.get('auc:AnnualFuelUseConsistentUnits') # in MMBtu
# get demand as well
new_data['annual_peak_demand'] = ru.get('auc:AnnualPeakConsistentUnits') # in KW
elif ru.get('auc:EnergyResource') == 'Natural gas':
new_data['annual_natural_gas_energy'] = ru.get('auc:AnnualFuelUseConsistentUnits') # in MMBtu

Expand Down
8 changes: 4 additions & 4 deletions seed/building_sync/tests/data/buildingsync_ex01_measures.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@
<auc:Perimeter>977</auc:Perimeter>
<auc:YearOfConstruction>1967</auc:YearOfConstruction>
<auc:YearOfLastMajorRemodel>2009</auc:YearOfLastMajorRemodel>
<auc:Subsections>
<auc:Subsection ID="Default_Subsection">
<auc:Sections>
<auc:Section ID="Default_Subsection">
<auc:OccupancyClassification>Office</auc:OccupancyClassification>
<auc:TypicalOccupantUsages>
<auc:TypicalOccupantUsage>
Expand All @@ -97,8 +97,8 @@
<auc:FloorAreaValue>0.0</auc:FloorAreaValue>
</auc:FloorArea>
</auc:FloorAreas>
</auc:Subsection>
</auc:Subsections>
</auc:Section>
</auc:Sections>
</auc:Building>
</auc:Buildings>
</auc:Site>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@
<auc:Perimeter>977</auc:Perimeter>
<auc:YearOfConstruction>1967</auc:YearOfConstruction>
<auc:YearOfLastMajorRemodel>2009</auc:YearOfLastMajorRemodel>
<auc:Subsections>
<auc:Subsection ID="Default_Subsection">
<auc:Sections>
<auc:Section ID="Default_Subsection">
<auc:OccupancyClassification>Office</auc:OccupancyClassification>
<auc:TypicalOccupantUsages>
<auc:TypicalOccupantUsage>
Expand All @@ -97,8 +97,8 @@
<auc:FloorAreaValue>0.0</auc:FloorAreaValue>
</auc:FloorArea>
</auc:FloorAreas>
</auc:Subsection>
</auc:Subsections>
</auc:Section>
</auc:Sections>
</auc:Building>
</auc:Buildings>
</auc:Site>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@
<auc:Perimeter>2145</auc:Perimeter>
<auc:YearOfConstruction>2010</auc:YearOfConstruction>
<auc:YearOfLastMajorRemodel>2012</auc:YearOfLastMajorRemodel>
<auc:Subsections>
<auc:Subsection ID="Default_Subsection">
<auc:Sections>
<auc:Section ID="Default_Subsection">
<auc:OccupancyClassification>Retail</auc:OccupancyClassification>
<auc:TypicalOccupantUsages>
<auc:TypicalOccupantUsage>
Expand All @@ -99,8 +99,8 @@
<auc:FloorAreaValue>0.0</auc:FloorAreaValue>
</auc:FloorArea>
</auc:FloorAreas>
</auc:Subsection>
</auc:Subsections>
</auc:Section>
</auc:Sections>
</auc:Building>
</auc:Buildings>
</auc:Site>
Expand Down
8 changes: 4 additions & 4 deletions seed/building_sync/tests/data/ex_1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@
<auc:Perimeter>977</auc:Perimeter>
<auc:YearOfConstruction>1967</auc:YearOfConstruction>
<auc:YearOfLastMajorRemodel>2009</auc:YearOfLastMajorRemodel>
<auc:Subsections>
<auc:Subsection ID="Default_Subsection">
<auc:Sections>
<auc:Section ID="Default_Subsection">
<auc:OccupancyClassification>Office</auc:OccupancyClassification>
<auc:TypicalOccupantUsages>
<auc:TypicalOccupantUsage>
Expand All @@ -97,8 +97,8 @@
<auc:FloorAreaValue>0.0</auc:FloorAreaValue>
</auc:FloorArea>
</auc:FloorAreas>
</auc:Subsection>
</auc:Subsections>
</auc:Section>
</auc:Sections>
</auc:Building>
</auc:Buildings>
</auc:Site>
Expand Down
8 changes: 4 additions & 4 deletions seed/building_sync/tests/data/ex_1_different_namespace.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@
<other_ns:Perimeter>977</other_ns:Perimeter>
<other_ns:YearOfConstruction>1889</other_ns:YearOfConstruction>
<other_ns:YearOfLastMajorRemodel>2018</other_ns:YearOfLastMajorRemodel>
<other_ns:Subsections>
<other_ns:Subsection ID="Default_Subsection">
<other_ns:Sections>
<other_ns:Section ID="Default_Subsection">
<other_ns:OccupancyClassification>Restaurant</other_ns:OccupancyClassification>
<other_ns:TypicalOccupantUsages>
<other_ns:TypicalOccupantUsage>
Expand All @@ -90,8 +90,8 @@
<other_ns:FloorAreaValue>55000</other_ns:FloorAreaValue>
</other_ns:FloorArea>
</other_ns:FloorAreas>
</other_ns:Subsection>
</other_ns:Subsections>
</other_ns:Section>
</other_ns:Sections>
</other_ns:Building>
</other_ns:Buildings>
</other_ns:Site>
Expand Down
8 changes: 4 additions & 4 deletions seed/building_sync/tests/data/test_single_scenario.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@
<auc:Perimeter>977</auc:Perimeter>
<auc:YearOfConstruction>1967</auc:YearOfConstruction>
<auc:YearOfLastMajorRemodel>2009</auc:YearOfLastMajorRemodel>
<auc:Subsections>
<auc:Subsection ID="Default_Subsection">
<auc:Sections>
<auc:Section ID="Default_Subsection">
<auc:OccupancyClassification>Office</auc:OccupancyClassification>
<auc:TypicalOccupantUsages>
<auc:TypicalOccupantUsage>
Expand All @@ -97,8 +97,8 @@
<auc:FloorAreaValue>0.0</auc:FloorAreaValue>
</auc:FloorArea>
</auc:FloorAreas>
</auc:Subsection>
</auc:Subsections>
</auc:Section>
</auc:Sections>
</auc:Building>
</auc:Buildings>
</auc:Site>
Expand Down
Binary file modified seed/building_sync/tests/data/valid_xml_ex1_ex2.zip
Binary file not shown.
30 changes: 30 additions & 0 deletions seed/migrations/0109_auto_20190724_1251.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.21 on 2019-07-24 19:51
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('seed', '0108_merge_20190716_1038'),
]

operations = [
migrations.AddField(
model_name='scenario',
name='annual_site_energy_use_intensity',
field=models.FloatField(null=True),
),
migrations.AddField(
model_name='scenario',
name='annual_source_energy',
field=models.FloatField(null=True),
),
migrations.AddField(
model_name='scenario',
name='annual_source_energy_use_intensity',
field=models.FloatField(null=True),
),
]
3 changes: 3 additions & 0 deletions seed/models/building_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ def process(self, organization_id, cycle, property_view=None):
scenario.annual_electricity_savings = s.get('annual_electricity_savings')
scenario.annual_natural_gas_savings = s.get('annual_natural_gas_savings')
scenario.annual_site_energy = s.get('annual_site_energy')
scenario.annual_source_energy = s.get('annual_source_energy')
scenario.annual_site_energy_use_intensity = s.get('annual_site_energy_use_intensity')
scenario.annual_source_energy_use_intensity = s.get('annual_source_energy_use_intensity')
scenario.annual_natural_gas_energy = s.get('annual_natural_gas_energy')
scenario.annual_electricity_energy = s.get('annual_electricity_energy')
scenario.annual_peak_demand = s.get('annual_peak_demand')
Expand Down
41 changes: 20 additions & 21 deletions seed/models/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
:copyright (c) 2014 - 2019, The Regents of the University of California, through Lawrence Berkeley National Laboratory (subject to receipt of any required approvals from the U.S. Department of Energy) and contributors. All rights reserved. # NOQA
:author
"""
from __future__ import unicode_literals
from __future__ import absolute_import
from __future__ import unicode_literals

import copy
import logging
import re
from os import path
from past.builtins import basestring
from django.apps import apps
from django.contrib.postgres.fields import JSONField

from django.contrib.gis.db import models as geomodels
from django.contrib.postgres.fields import JSONField
from django.db import (
models,
transaction,
Expand All @@ -23,10 +22,9 @@
from django.db.models.signals import pre_delete, pre_save, post_save, m2m_changed
from django.dispatch import receiver
from django.forms.models import model_to_dict
from past.builtins import basestring
from quantityfield.fields import QuantityField

from .auditlog import AUDIT_IMPORT
from .auditlog import DATA_UPDATE_TYPE
from seed.data_importer.models import ImportFile
# from seed.utils.cprofile import cprofile
from seed.lib.mcm.cleaners import date_cleaner
Expand All @@ -49,6 +47,8 @@
)
from seed.utils.time import convert_datestr
from seed.utils.time import convert_to_js_timestamp
from .auditlog import AUDIT_IMPORT
from .auditlog import DATA_UPDATE_TYPE

_log = logging.getLogger(__name__)

Expand Down Expand Up @@ -448,8 +448,7 @@ def record_dict(log):

while not done_searching:
# if there is no parents, then break out immediately
if (
log.parent1_id is None and log.parent2_id is None) or log.name == 'Manual Edit':
if (log.parent1_id is None and log.parent2_id is None) or log.name == 'Manual Edit':
break

# initalize the tree to None everytime. If not new tree is found, then we will not iterate
Expand Down Expand Up @@ -614,21 +613,17 @@ def merge_relationships(cls, merged_state, state1, state2):
"""
Merge together the old relationships with the new.
"""
SimulationClass = apps.get_model('seed', 'Simulation')
ScenarioClass = apps.get_model('seed', 'Scenario')
PropertyMeasureClass = apps.get_model('seed', 'PropertyMeasure')
from seed.models.simulations import Simulation
from seed.models.property_measures import PropertyMeasure
from seed.models.scenarios import Scenario

# TODO: get some items off of this property view - labels and eventually notes

# collect the relationships
no_measure_scenarios = [x for x in state2.scenarios.filter(measures__isnull=True)] + \
[x for x in state1.scenarios.filter(measures__isnull=True)]
building_files = [x for x in state2.building_files.all()] + [x for x in
state1.building_files.all()]
simulations = [x for x in
SimulationClass.objects.filter(property_state__in=[state1, state2])]
measures = [x for x in
PropertyMeasureClass.objects.filter(property_state__in=[state1, state2])]
no_measure_scenarios = [x for x in state2.scenarios.filter(measures__isnull=True)]
building_files = [x for x in state2.building_files.all()]
simulations = [x for x in Simulation.objects.filter(property_state=state2)]
measures = [x for x in PropertyMeasure.objects.filter(property_state=state2)]

# copy in the no measure scenarios
for new_s in no_measure_scenarios:
Expand Down Expand Up @@ -693,14 +688,18 @@ def merge_relationships(cls, merged_state, state1, state2):

# connect back up the scenario measures
for scenario_id, measure_list in scenario_measure_map.items():

# create a new scenario from the old one
scenario = ScenarioClass.objects.get(pk=scenario_id)
scenario = Scenario.objects.get(pk=scenario_id)

scenario.pk = None
scenario.property_state = merged_state
scenario.save() # save to get new id

scenario.copy_initial_meters(scenario_id)

# get the measures
measures = PropertyMeasureClass.objects.filter(pk__in=measure_list)
measures = PropertyMeasure.objects.filter(pk__in=measure_list)
for measure in measures:
scenario.measures.add(measure)
scenario.save()
Expand Down
22 changes: 21 additions & 1 deletion seed/models/scenarios.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,12 @@ class Scenario(models.Model):
summer_peak_load_reduction = models.FloatField(null=True)
winter_peak_load_reduction = models.FloatField(null=True)
annual_site_energy = models.FloatField(null=True)
annual_source_energy = models.FloatField(null=True)
annual_natural_gas_energy = models.FloatField(null=True)
annual_electricity_energy = models.FloatField(null=True)
annual_peak_demand = models.FloatField(null=True)
annual_site_energy_use_intensity = models.FloatField(null=True)
annual_source_energy_use_intensity = models.FloatField(null=True)
hdd = models.FloatField(null=True)
hdd_base_temperature = models.FloatField(null=True)
cdd = models.FloatField(null=True)
Expand All @@ -78,4 +81,21 @@ class Scenario(models.Model):

measures = models.ManyToManyField(PropertyMeasure)

# TODO: add in meters -- meters are linked from Class Meter
def copy_initial_meters(self, source_scenario_id):
"""
Copy meters from another scenario.
As hinted by the name, this method is meant to be used when there are no
meters currently associated to this scenario.
"""
from seed.models.meters import Meter

source_scenario = Scenario.objects.get(pk=source_scenario_id)

for source_meter in source_scenario.meter_set.all():
# create new meter and copy over the readings from the source_meter
meter = Meter.objects.get(pk=source_meter.id)
meter.pk = None
meter.scenario_id = self.id
meter.copy_readings(source_meter, overlaps_possible=False)
meter.save() # save to get new id / association
1 change: 1 addition & 0 deletions seed/tests/test_building_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def test_buildingsync_constructor(self):
status, property_state, property_view, messages = bf.process(self.org.id, self.org.cycles.first())
self.assertTrue(status)
self.assertEqual(property_state.address_line_1, '123 Main St')
self.assertEqual(property_state.property_type, 'Office')
self.assertEqual(messages, {'errors': [], 'warnings': []})

def test_buildingsync_constructor_diff_ns(self):
Expand Down
9 changes: 8 additions & 1 deletion seed/tests/test_building_file_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,14 @@ def test_upload_with_measure_duplicates(self):
self.assertEqual(response.status_code, 200)
result = json.loads(response.content)
self.assertEqual(result['status'], 'success')
expected_message = {'warnings': ['Measure category and name is not valid other_electric_motors_and_drives:replace_with_higher_efficiency_bad_name', 'Measure category and name is not valid other_hvac:install_demand_control_ventilation_bad_name', 'Measure associated with scenario not found. Scenario: Replace with higher efficiency Only, Measure name: Measure22', 'Measure associated with scenario not found. Scenario: Install demand control ventilation Only, Measure name: Measure24']}
expected_message = {
'warnings': [
'Measure category and name is not valid other_electric_motors_and_drives:replace_with_higher_efficiency_bad_name',
'Measure category and name is not valid other_hvac:install_demand_control_ventilation_bad_name',
'Measure associated with scenario not found. Scenario: Replace with higher efficiency Only, Measure name: Measure22',
'Measure associated with scenario not found. Scenario: Install demand control ventilation Only, Measure name: Measure24'
]
}
self.assertEqual(result['message'], expected_message)
self.assertEqual(len(result['data']['property_view']['state']['measures']), 28)
self.assertEqual(len(result['data']['property_view']['state']['scenarios']), 31)
Expand Down
2 changes: 0 additions & 2 deletions seed/tests/test_tax_lot_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ def test_xlxs_export(self):
content_type='application/x-www-form-urlencoded'
)

print(response.content)

# parse the content as array
data = response.content.decode('utf-8').split('\n')

Expand Down

0 comments on commit 8ba06bf

Please sign in to comment.