Search in sources :

Example 1 with ClusterData

use of au.gov.asd.tac.constellation.views.analyticview.results.ClusterResult.ClusterData in project constellation by constellation-app.

the class ClusterAnalyticPlugin method computeResultsFromGraph.

protected final void computeResultsFromGraph(final GraphReadMethods graph, final PluginParameters parameters) {
    result = new ClusterResult();
    result.setIgnoreNullResults(ignoreDefaultValues());
    getAnalyticAttributes(parameters).forEach(schemaAttribute -> {
        int graphElementCount = 0;
        int identifierAttributeId = Graph.NOT_FOUND;
        final int clusterNumberAtributeId = schemaAttribute.get(graph);
        if (clusterNumberAtributeId == Graph.NOT_FOUND) {
            throw new RuntimeException("Expected attribute not found on graph: " + schemaAttribute.getName());
        }
        final GraphElementType graphElementType = schemaAttribute.getElementType();
        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 int clusterNumber = graph.getIntValue(clusterNumberAtributeId, graphElementId);
            final int defaultNumber = (int) graph.getAttributeDefaultValue(clusterNumberAtributeId);
            final boolean isNull = ignoreDefaultValues() && clusterNumber == defaultNumber;
            result.add(new ClusterData(graphElementType, graphElementId, identifier, isNull, clusterNumber));
        }
    });
}
Also used : ClusterData(au.gov.asd.tac.constellation.views.analyticview.results.ClusterResult.ClusterData) ClusterResult(au.gov.asd.tac.constellation.views.analyticview.results.ClusterResult) GraphElementType(au.gov.asd.tac.constellation.graph.GraphElementType)

Aggregations

GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)1 ClusterResult (au.gov.asd.tac.constellation.views.analyticview.results.ClusterResult)1 ClusterData (au.gov.asd.tac.constellation.views.analyticview.results.ClusterResult.ClusterData)1