From 4f058090b8bba7a5c2d1369077b8a2194accfa9e Mon Sep 17 00:00:00 2001 From: Shreyas Damle Date: Fri, 26 Jul 2024 15:05:08 +0530 Subject: [PATCH] Sort Loader apps based on total findings --- pebblo/app/service/local_ui_service.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/pebblo/app/service/local_ui_service.py b/pebblo/app/service/local_ui_service.py index 850fd048..6977d091 100644 --- a/pebblo/app/service/local_ui_service.py +++ b/pebblo/app/service/local_ui_service.py @@ -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, @@ -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: