Skip to content

Commit

Permalink
Improve role analysis attribute chart
Browse files Browse the repository at this point in the history
1. Sort descending
  • Loading branch information
tchrapovic committed Mar 15, 2024
1 parent dd7b339 commit f478117
Showing 1 changed file with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,19 @@

package com.evolveum.midpoint.gui.impl.page.admin.role.mining.model;

import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import com.evolveum.midpoint.common.mining.objects.analysis.AttributeAnalysisStructure;

import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;

import org.apache.wicket.model.LoadableDetachableModel;
import org.jetbrains.annotations.NotNull;

import com.evolveum.midpoint.common.mining.objects.analysis.AttributeAnalysisStructure;
import com.evolveum.midpoint.gui.api.model.LoadableModel;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
import com.evolveum.wicket.chartjs.*;

import org.jetbrains.annotations.NotNull;

import javax.xml.namespace.QName;

/**
* The model for the role analysis attribute chart.
* Used for loading the data for the role analysis attribute chart.
Expand Down Expand Up @@ -87,7 +81,25 @@ protected ChartConfiguration load() {
Map<String, List<AttributeAnalysisStructure>> itemPathMap = objects.stream()
.collect(Collectors.groupingBy(AttributeAnalysisStructure::getItemPath));

for (Map.Entry<String, List<AttributeAnalysisStructure>> entry : itemPathMap.entrySet()) {
Map<String, List<AttributeAnalysisStructure>> sortedItemPathMap = itemPathMap.entrySet().stream()
.sorted((entry1, entry2) -> {
double totalDensity1 = entry1.getValue().stream()
.mapToDouble(AttributeAnalysisStructure::getDensity)
.sum();

double totalDensity2 = entry2.getValue().stream()
.mapToDouble(AttributeAnalysisStructure::getDensity)
.sum();

double averageDensity1 = totalDensity1 / 2;
double averageDensity2 = totalDensity2 / 2;

return Double.compare(averageDensity2, averageDensity1);
})
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue,
(oldValue, newValue) -> oldValue, LinkedHashMap::new));

for (Map.Entry<String, List<AttributeAnalysisStructure>> entry : sortedItemPathMap.entrySet()) {
String itemPath = entry.getKey();
List<AttributeAnalysisStructure> filteredObjects = entry.getValue();

Expand Down

0 comments on commit f478117

Please sign in to comment.