Skip to content

Commit

Permalink
Merge pull request #3187 from SEED-platform/2844-refactor/list-analysis
Browse files Browse the repository at this point in the history
2844 refactor/list analysis
  • Loading branch information
Ryo committed Mar 30, 2022
2 parents a9b1b3f + e23ab9a commit 8f07b64
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 12 deletions.
19 changes: 18 additions & 1 deletion seed/static/seed/js/controllers/analyses_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,32 @@ angular.module('BE.seed.controller.analyses', [])
'$scope',
'analyses_payload',
'organization_payload',
'organization_service',
'users_payload',
'auth_payload',
'messages_payload',
'urls',
'analyses_service',
'Notification',
function (
$scope,
analyses_payload,
organization_payload,
organization_service,
users_payload,
auth_payload,
messages_payload,
urls,
analyses_service,
Notification
) {
$scope.org = organization_payload;
$scope.org = organization_payload.organization;
$scope.auth = auth_payload.auth;
$scope.analyses = analyses_payload.analyses;
$scope.views = analyses_payload.views;
$scope.original_views = analyses_payload.original_views;
$scope.users = users_payload.users;
$scope.messages = messages_payload.messages;

// Stores functions for stopping the polling of analysis progress. Keyed by analysis id
const analysis_polling_stoppers = {};
Expand Down Expand Up @@ -141,12 +148,22 @@ angular.module('BE.seed.controller.analyses', [])
}
});
};

$scope.has_children = function (value) {
if (typeof value == 'object') {
return true;
}
};

$scope.get_display_name = function (inventory_state) {
return organization_service.get_inventory_display_value(
$scope.org,
// NOTE: hardcoding 'property' b/c you can only run analyses on properties
'property',
inventory_state
);
};

}
])
.filter('get_run_duration', function () {
Expand Down
7 changes: 5 additions & 2 deletions seed/static/seed/js/seed.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,11 @@ SEED_app.config(['stateHelperProvider', '$urlRouterProvider', '$locationProvider
analyses_payload: ['analyses_service', 'user_service', function (analyses_service, user_service) {
return analyses_service.get_analyses_for_org(user_service.get_organization().id);
}],
organization_payload: ['user_service', function (user_service) {
return user_service.get_organization();
organization_payload: ['user_service', 'organization_service', function (user_service, organization_service) {
return organization_service.get_organization(user_service.get_organization().id);
}],
messages_payload: ['analyses_service', 'user_service', '$stateParams', function (analyses_service, user_service) {
return analyses_service.get_analyses_messages_for_org(user_service.get_organization().id);
}],
users_payload: ['organization_service', 'user_service', function (organization_service, user_service) {
return organization_service.get_organization_users({org_id: user_service.get_organization().id});
Expand Down
7 changes: 7 additions & 0 deletions seed/static/seed/js/services/analyses_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ angular.module('BE.seed.service.analyses', [])
});
};

const get_analyses_messages_for_org = function (org_id) {
return $http.get('/api/v3/analyses/0/messages/?organization_id=' + org_id).then(function (response) {
return response.data;
});
};

const get_analysis_views_for_org = function (analysis_id, org_id) {
return $http.get('/api/v3/analyses/' + analysis_id + '/views/?organization_id=' + org_id).then(function (response) {
return response.data;
Expand Down Expand Up @@ -233,6 +239,7 @@ angular.module('BE.seed.service.analyses', [])
get_analyses_for_canonical_properties: get_analyses_for_canonical_properties,
get_analysis_for_org: get_analysis_for_org,
get_analysis_messages_for_org: get_analysis_messages_for_org,
get_analyses_messages_for_org: get_analyses_messages_for_org,
get_analysis_views_for_org: get_analysis_views_for_org,
get_analysis_view_for_org: get_analysis_view_for_org,
create_analysis: create_analysis,
Expand Down
63 changes: 59 additions & 4 deletions seed/static/seed/partials/analyses.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
</div>
</div>

<div class="section">
<div class="section_content_container">
<div class="section_content">
<div class="modal-body">
<uib-tabset class="modal-tabs">
<uib-tab index="1">
<uib-tab-heading>
<b>By Analysis</b>
</uib-tab-heading>
<div class="table_list_container">
<table id="analyses-table" class="table table-striped table_highlight_first">
<table id="analyses-table" class="table table-striped table_highlight_first" style="margin:0;">
<thead>
<tr>
<th translate>Analysis Name (User Defined)</th>
Expand Down Expand Up @@ -60,6 +63,58 @@
</tbody>
</table>
</div>
</uib-tab>
<uib-tab index="2">
<uib-tab-heading>
<b>By Property</b>
</uib-tab-heading>
<div class="table_list_container">
<table id="analysis-runs-table" class="table table-striped table_highlight_first" style="margin:0;">
<thead>
<tr>
<th translate>Run ID</th>
<th translate>Property</th>
<th translate>Latest Messages</th>
<th translate>Output Files</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="view in views | filter:filter_params:strict">
<td><a ui-sref="analysis_run(::{run_id: view.id, analysis_id: view.analysis, organization_id: org.id})" ui-sref-active="active">{$:: view.id $}</a></td>
<td>
<a ng-if="original_views[view.id]" ui-sref="inventory_detail({inventory_type: 'properties', view_id: original_views[view.id]})">
{$:: get_display_name(view.property_state) || 'Property ' + original_views[view.id] $}
</a>
<span ng-if="!original_views[view.id]" uib-tooltip="Property no longer exists">
{$:: get_display_name(view.property_state) || 'Unknown' $}
</span>
</td>
<td>
<ul>
<li ng-repeat="message in messages | filter : {'analysis_property_view':view.id}">
{$:: message['user_message'] $}
</li>
</ul>
</td>
<td>
<span ng-repeat="file in view.output_files | filter:filter_params:strict">
<a ng-if="file['analysis_property_views'].length > 1" href="{$:: file.file $}" download>Portfolio Report <span class="fa fa-download"></span></a>
<a ng-if="file['analysis_property_views'].length == 1" href="{$:: file.file $}" download>{$:: file.content_type == 'html' ? 'Building Report' : file.content_type $} <span class="fa fa-download"></span></a>
<span ng-repeat-end ng-if="!$last">, </span>
</span>
</td>
</tr>
</tbody>
</table>
</div>
</uib-tab>
</uib-tabset>
</div>


<div class="section">
<div class="section_content_container">
<div class="section_content">
</div>
</div>
</div>
18 changes: 16 additions & 2 deletions seed/views/v3/analyses.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
from seed.analysis_pipelines.pipeline import AnalysisPipeline, AnalysisPipelineException
from seed.decorators import ajax_request_class, require_organization_id_class
from seed.lib.superperms.orgs.decorators import has_perm_class
from seed.models import Analysis, Cycle, PropertyView, PropertyState, Column
from seed.models import Analysis, AnalysisPropertyView, Cycle, PropertyView, PropertyState, Column
from seed.serializers.analyses import AnalysisSerializer
from seed.serializers.analysis_property_views import AnalysisPropertyViewSerializer
from seed.utils.api import api_endpoint_class, OrgMixin
from seed.utils.api_schema import AutoSchemaHelper

Expand Down Expand Up @@ -105,6 +106,7 @@ def create(self, request):
def list(self, request):
organization_id = self.get_organization(request)
property_id = request.query_params.get('property_id', None)

analyses = []
if property_id is not None:
analyses_queryset = (
Expand All @@ -123,9 +125,21 @@ def list(self, request):
serialized_analysis.update({'highlights': analysis.get_highlights(property_id)})
analyses.append(serialized_analysis)

views_queryset = AnalysisPropertyView.objects.filter(analysis__organization_id=organization_id).order_by('-id')
serialized_views = []
property_views_by_apv_id = AnalysisPropertyView.get_property_views(views_queryset)
for view in views_queryset:
serialized_view = AnalysisPropertyViewSerializer(view).data
serialized_views.append(serialized_view)

return JsonResponse({
'status': 'success',
'analyses': analyses
'analyses': analyses,
'views': serialized_views,
'original_views': {
apv_id: property_view.id if property_view is not None else None
for apv_id, property_view in property_views_by_apv_id.items()
}
})

@swagger_auto_schema(manual_parameters=[AutoSchemaHelper.query_org_id_field(True)])
Expand Down
8 changes: 5 additions & 3 deletions seed/views/v3/analysis_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
from seed.lib.superperms.orgs.decorators import has_perm_class
from seed.models import AnalysisMessage
from seed.serializers.analysis_messages import AnalysisMessageSerializer
from seed.utils.api import api_endpoint_class
from seed.utils.api import api_endpoint_class, OrgMixin


class AnalysisMessageViewSet(viewsets.ViewSet):
class AnalysisMessageViewSet(viewsets.ViewSet, OrgMixin):
serializer_class = AnalysisMessageSerializer
model = AnalysisMessage

Expand All @@ -24,7 +24,9 @@ class AnalysisMessageViewSet(viewsets.ViewSet):
@ajax_request_class
@has_perm_class('requires_member')
def list(self, request, analysis_pk, view_pk=None):
if view_pk is None:
if int(analysis_pk) < 1:
messages_queryset = AnalysisMessage.objects.filter(analysis__organization=self.get_organization(request)).order_by('-id')
elif view_pk is None:
messages_queryset = AnalysisMessage.objects.filter(analysis=analysis_pk).order_by('-id')
else:
messages_queryset = AnalysisMessage.objects.filter(analysis=analysis_pk, analysis_property_view=view_pk).order_by('-id')
Expand Down

0 comments on commit 8f07b64

Please sign in to comment.