Skip to content

Commit

Permalink
Merge branch '4544-AT-submission-import' of https://github.com/SEED-p…
Browse files Browse the repository at this point in the history
…latform/seed into 4544-AT-submission-import
  • Loading branch information
perryr16 committed Apr 30, 2024
2 parents 91b37a3 + b456033 commit 910d7f7
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 24 deletions.
15 changes: 7 additions & 8 deletions seed/analysis_pipelines/better/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from celery import chain, shared_task
from django.core.files.base import ContentFile
from django.db.models import Count
from django.utils.timezone import make_aware

from seed.analysis_pipelines.better.buildingsync import SEED_TO_BSYNC_RESOURCE_TYPE, _build_better_input
from seed.analysis_pipelines.better.client import BETTERClient
Expand Down Expand Up @@ -159,8 +160,8 @@ def get_meter_readings(property_id, preprocess_meters, config):
value2 = value2 + timedelta(days=1)
elif config.get("select_meters") == "select_cycle":
cycle = Cycle.objects.get(pk=config["cycle_id"])
value1 = dateutil.parser.parse(cycle.start.isoformat())
value2 = dateutil.parser.parse(cycle.end.isoformat()) + timedelta(days=1)
value1 = make_aware(dateutil.parser.parse(cycle.start.isoformat()))
value2 = make_aware(dateutil.parser.parse(cycle.end.isoformat())) + timedelta(days=1)

except Exception as err:
raise AnalysisPipelineError(f"Analysis configuration error: invalid dates selected for meter readings: {err}")
Expand Down Expand Up @@ -208,7 +209,6 @@ def get_meter_readings(property_id, preprocess_meters, config):
"readings": readings,
}
)

return selected_meters_and_readings


Expand Down Expand Up @@ -295,8 +295,8 @@ def _start_analysis(self, analysis_id):
pipeline = BETTERPipeline(analysis_id)
progress_data = pipeline.set_analysis_status_to_running()
progress_data.step("Sending requests to BETTER service")

analysis = Analysis.objects.get(id=analysis_id)

client = BETTERClient(analysis.organization.better_analysis_api_key)
context = BETTERPipelineContext(analysis, progress_data, client)

Expand Down Expand Up @@ -492,15 +492,14 @@ def _process_results(self, analysis_id):
)
except Exception:
if analysis.can_create():
column, _created = Column.objects.create(
Column.objects.create(
is_extra_data=True,
column_name=column_data_path.column_name,
organization=analysis.organization,
table_name="PropertyState",
display_name=column_data_path.column_display_name,
column_description=column_data_path.column_display_name,
)
column.display_name = column_data_path.column_display_name
column.column_description = column_data_path.column_display_name
column.save()
else:
missing_columns = True

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ angular.module('BE.seed.controller.inventory_detail_analyses', []).controller('i
resolve: {
inventory_ids: () => [$scope.inventory.view_id],
cycles: () => cycle_service.get_cycles().then((result) => result.cycles),
current_cycle: () => $scope.cycle
current_cycle: () => $scope.cycle,
user: () => $scope.menu.user
}
})
.result.then((data) => {
Expand Down
13 changes: 2 additions & 11 deletions seed/static/seed/js/controllers/inventory_settings_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,23 +290,14 @@ angular.module('BE.seed.controller.inventory_settings', []).controller('inventor
};

$scope.newProfile = () => {
const columns = [];
const derived_columns = [];
for (const column in currentColumns) {
if (column.derived_column) {
derived_columns.push(column);
} else {
columns.push(column);
}
}
const modalInstance = $uibModal.open({
templateUrl: `${urls.static_url}seed/partials/settings_profile_modal.html`,
controller: 'settings_profile_modal_controller',
resolve: {
action: () => 'new',
data: {
columns,
derived_columns
columns: currentColumns(),
derived_columns: []
},
profile_location: () => 'List View Profile',
inventory_type: () => ($scope.inventory_type === 'properties' ? 'Property' : 'Tax Lot')
Expand Down
31 changes: 31 additions & 0 deletions seed/tests/test_column_list_profiles_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from seed.landing.models import SEEDUser as User
from seed.models import Column
from seed.models.derived_columns import DerivedColumn
from seed.test_helpers.fake import FakeColumnListProfileFactory
from seed.tests.util import AccessLevelBaseTestCase, DeleteModelsTestCase
from seed.utils.organizations import create_organization
Expand Down Expand Up @@ -74,6 +75,36 @@ def test_create_column_profile(self):
self.assertEqual(data["data"]["inventory_type"], "Property")
self.assertEqual(data["data"]["profile_location"], "List View Profile")

def test_create_column_profile_with_derived_column(self):
self.derived_column = DerivedColumn.objects.create(
name="dc",
expression="$a + 10",
organization=self.org,
inventory_type=0,
)
self.payload_data["derived_columns"].append(
{
"column_name": "dc",
"derived_column": True,
"id": self.derived_column.id,
"order": 4,
"pinned": False,
"table_name": "PropertyState",
}
)

response = self.client.post(
reverse("api:v3:column_list_profiles-list") + "?organization_id=" + str(self.org.id),
data=json.dumps(self.payload_data),
content_type="application/json",
)
data = json.loads(response.content)
self.assertEqual(data["status"], "success")
self.assertEqual(len(data["data"]["columns"]), 3)
self.assertEqual(len(data["data"]["derived_columns"]), 1)
self.assertEqual(data["data"]["inventory_type"], "Property")
self.assertEqual(data["data"]["profile_location"], "List View Profile")

def test_get_column_profile(self):
# Create two list settings
self.client.post(
Expand Down
8 changes: 4 additions & 4 deletions vendors/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 910d7f7

Please sign in to comment.