Skip to content

Commit

Permalink
Sort Loader apps based on total findings
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyas-damle committed Jul 26, 2024
1 parent 445c7c3 commit 4f05809
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion pebblo/app/service/local_ui_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,15 @@ def get_all_apps_details(self):
f"[Dashboard]: Error processing app {app_dir}: {err}"
)

# Sort loader apps
sorted_loader_apps = self._sort_loader_apps(all_loader_apps)
logger.debug("[Dashboard]: Preparing loader app response object")
loader_response = LoaderAppModel(
applicationsAtRiskCount=self.loader_apps_at_risk,
findingsCount=self.loader_findings,
documentsWithFindingsCount=self.loader_files_findings,
dataSourceCount=self.loader_data_source,
appList=all_loader_apps,
appList=sorted_loader_apps,
findings=self.loader_findings_list,
documentsWithFindings=self.loader_document_with_findings_list,
dataSource=self.loader_data_source_list,
Expand Down Expand Up @@ -535,6 +537,18 @@ def sort_retrievals_data(self, retrieval):
sorted_data = sorted(retrieval, key=self._calculate_total_count, reverse=True)
return sorted_data

@staticmethod
def _calculate_findings(item):
"""Calculate total findings(entities + topics)"""
return item["topics"] + item["entities"]

def _sort_loader_apps(self, loader_apps_list: list):
"""Sort the list based on the findings in descending order"""
sorted_data = sorted(
loader_apps_list, key=self._calculate_findings, reverse=True
)
return sorted_data

def get_all_documents(self, retrieval_data: list) -> dict:
"""
This function returns documents per app with its metadata in following format:
Expand Down

0 comments on commit 4f05809

Please sign in to comment.