use of au.gov.asd.tac.constellation.views.analyticview.results.ScoreResult.ElementScore in project constellation by constellation-app.
the class MaxScoreAggregator method aggregate.
@Override
public ScoreResult aggregate(final List<ScoreResult> results) {
final ScoreResult combinedResults = new ScoreResult();
final ScoreResult aggregateResult = new ScoreResult();
if (CollectionUtils.isEmpty(results)) {
return aggregateResult;
}
aggregateResult.setIgnoreNullResults(results.stream().anyMatch(result -> result.isIgnoreNullResults()));
results.forEach(scoreResult -> combinedResults.combine(scoreResult));
combinedResults.getResult().forEach((key, value) -> {
final Map<String, Float> aggregateScores = new HashMap<>();
aggregateScores.put(SCORE_NAME, value.getNamedScores().values().stream().reduce(Math::max).orElse(0.0F));
aggregateResult.add(new ElementScore(key.getElementType(), key.getElementId(), key.getIdentifier(), false, aggregateScores));
});
return aggregateResult;
}
use of au.gov.asd.tac.constellation.views.analyticview.results.ScoreResult.ElementScore in project constellation by constellation-app.
the class MeanScoreAggregator method aggregate.
@Override
public ScoreResult aggregate(final List<ScoreResult> results) {
final ScoreResult combinedResults = new ScoreResult();
final ScoreResult aggregateResult = new ScoreResult();
if (CollectionUtils.isEmpty(results)) {
return aggregateResult;
}
aggregateResult.setIgnoreNullResults(results.stream().anyMatch(result -> result.isIgnoreNullResults()));
results.forEach(scoreResult -> combinedResults.combine(scoreResult));
combinedResults.getResult().forEach((key, value) -> {
final Map<String, Float> aggregateScores = new HashMap<>();
aggregateScores.put(SCORE_NAME, value.getNamedScores().values().stream().reduce((x, y) -> x + y).orElse(0.0F) / value.getNamedScores().size());
aggregateResult.add(new ElementScore(key.getElementType(), key.getElementId(), key.getIdentifier(), false, aggregateScores));
});
return aggregateResult;
}
use of au.gov.asd.tac.constellation.views.analyticview.results.ScoreResult.ElementScore in project constellation by constellation-app.
the class ScoreAnalyticPlugin method computeResultsFromGraph.
protected final void computeResultsFromGraph(final GraphReadMethods graph, final PluginParameters parameters) {
result = new ScoreResult();
result.setIgnoreNullResults(ignoreDefaultValues());
int graphElementCount = 0;
int identifierAttributeId = Graph.NOT_FOUND;
final Set<GraphElementType> graphElementTypes = getAnalyticAttributes(parameters).stream().map(attribute -> attribute.getElementType()).collect(Collectors.toSet());
for (final GraphElementType graphElementType : graphElementTypes) {
switch(graphElementType) {
case VERTEX:
graphElementCount = graph.getVertexCount();
identifierAttributeId = VisualConcept.VertexAttribute.IDENTIFIER.get(graph);
break;
case TRANSACTION:
graphElementCount = graph.getTransactionCount();
identifierAttributeId = VisualConcept.TransactionAttribute.IDENTIFIER.get(graph);
break;
default:
break;
}
for (int graphElementPosition = 0; graphElementPosition < graphElementCount; graphElementPosition++) {
final int graphElementId;
if (graphElementType == GraphElementType.VERTEX) {
graphElementId = graph.getVertex(graphElementPosition);
} else {
graphElementId = graphElementType == GraphElementType.TRANSACTION ? graph.getTransaction(graphElementPosition) : Graph.NOT_FOUND;
}
final String identifier = graph.getStringValue(identifierAttributeId, graphElementId);
final Map<String, Float> namedScores = new HashMap<>();
boolean isNull = true;
for (final SchemaAttribute analyticAttribute : getAnalyticAttributes(parameters)) {
final int scoreAttributeId = analyticAttribute.get(graph);
if (scoreAttributeId == Graph.NOT_FOUND) {
throw new RuntimeException("Expected attribute not found on graph: " + analyticAttribute.getName());
}
final float score = graph.getFloatValue(scoreAttributeId, graphElementId);
final float defaultScore = (float) graph.getAttributeDefaultValue(scoreAttributeId);
if (isNull) {
isNull = ignoreDefaultValues() && score == defaultScore;
}
namedScores.put(analyticAttribute.getName(), score);
}
result.add(new ElementScore(graphElementType, graphElementId, identifier, isNull, namedScores));
}
}
}
use of au.gov.asd.tac.constellation.views.analyticview.results.ScoreResult.ElementScore in project constellation by constellation-app.
the class AnalyticResultNGTest method testSort.
/**
* Test of sort method, of class AnalyticResult.
*/
@Test
public void testSort() {
System.out.println("sort");
LinkedHashMap<IdentificationData, ElementScore> testResult = new LinkedHashMap<>();
AnalyticResultImpl instance = new AnalyticResultImpl();
// Create unsorted ElementScore results
GraphElementType vertex = GraphElementType.VERTEX;
final IdentificationData idData1 = new IdentificationData(vertex, 1, "Node1");
final IdentificationData idData2 = new IdentificationData(vertex, 2, "Node2");
final IdentificationData idData3 = new IdentificationData(vertex, 3, "Node3");
final IdentificationData idData4 = new IdentificationData(vertex, 4, "Node4");
final IdentificationData idData5 = new IdentificationData(vertex, 5, "Node5");
final Map<String, Float> namedScores1 = new HashMap<>();
namedScores1.put("Centrality.OutBetweenness", (float) .8);
final Map<String, Float> namedScores2 = new HashMap<>();
namedScores2.put("Centrality.OutBetweenness", (float) 1.2);
final Map<String, Float> namedScores3 = new HashMap<>();
namedScores3.put("Centrality.OutBetweenness", (float) .7);
final Map<String, Float> namedScores4 = new HashMap<>();
namedScores4.put("Centrality.OutBetweenness", (float) 1.1);
final Map<String, Float> namedScores5 = new HashMap<>();
namedScores5.put("Centrality.OutBetweenness", (float) .6);
final ElementScore elementScore1 = new ElementScore(vertex, 1, "Node1", false, namedScores1);
final ElementScore elementScore2 = new ElementScore(vertex, 2, "Node1", false, namedScores2);
final ElementScore elementScore3 = new ElementScore(vertex, 3, "Node1", false, namedScores3);
final ElementScore elementScore4 = new ElementScore(vertex, 4, "Node1", false, namedScores4);
final ElementScore elementScore5 = new ElementScore(vertex, 5, "Node1", false, namedScores5);
instance.getResult().put(idData1, elementScore1);
instance.getResult().put(idData2, elementScore2);
instance.getResult().put(idData3, elementScore3);
instance.getResult().put(idData4, elementScore4);
instance.getResult().put(idData5, elementScore5);
// Populte the unsorted values in hashmap
testResult.put(idData1, elementScore1);
testResult.put(idData2, elementScore2);
testResult.put(idData3, elementScore3);
testResult.put(idData4, elementScore4);
testResult.put(idData5, elementScore5);
// Compare the unsorted map to the instance map to verify
assertEquals(instance.result, testResult);
// Do the instance sort
instance.sort();
// Populte the sorted values in hashmap
testResult.clear();
testResult.put(idData2, elementScore2);
testResult.put(idData4, elementScore4);
testResult.put(idData1, elementScore1);
testResult.put(idData3, elementScore3);
testResult.put(idData5, elementScore5);
// Compare the sorted map to the instance map to verify
assertEquals(instance.result, testResult);
}
use of au.gov.asd.tac.constellation.views.analyticview.results.ScoreResult.ElementScore in project constellation by constellation-app.
the class MinScoreAggregator method aggregate.
@Override
public ScoreResult aggregate(final List<ScoreResult> results) {
final ScoreResult combinedResults = new ScoreResult();
final ScoreResult aggregateResult = new ScoreResult();
if (CollectionUtils.isEmpty(results)) {
return aggregateResult;
}
aggregateResult.setIgnoreNullResults(results.stream().anyMatch(result -> result.isIgnoreNullResults()));
results.forEach(scoreResult -> combinedResults.combine(scoreResult));
combinedResults.getResult().forEach((key, value) -> {
final Map<String, Float> aggregateScores = new HashMap<>();
aggregateScores.put(SCORE_NAME, value.getNamedScores().values().stream().reduce(Math::min).orElse(0.0F));
aggregateResult.add(new ElementScore(key.getElementType(), key.getElementId(), key.getIdentifier(), false, aggregateScores));
});
return aggregateResult;
}
Aggregations