Search in sources :

Example 46 with PluginParameter

use of au.gov.asd.tac.constellation.plugins.parameters.PluginParameter in project constellation by constellation-app.

the class SmallWorldGraphBuilderPluginNGTest method testUpdateParameters.

/**
 * Test of updateParameters method, of class SmallWorldGraphBuilderPlugin.
 */
@Test
public void testUpdateParameters() {
    System.out.println("updateParameters");
    final SmallWorldGraphBuilderPlugin instance = new SmallWorldGraphBuilderPlugin();
    final PluginParameters params = instance.createParameters();
    final PluginParameter<MultiChoiceParameterValue> nAttribute = (PluginParameter<MultiChoiceParameterValue>) params.getParameters().get(NODE_TYPES_PARAMETER_ID);
    final PluginParameter<MultiChoiceParameterValue> tAttribute = (PluginParameter<MultiChoiceParameterValue>) params.getParameters().get(TRANSACTION_TYPES_PARAMETER_ID);
    assertTrue(MultiChoiceParameterType.getOptions(nAttribute).isEmpty());
    assertTrue(MultiChoiceParameterType.getOptions(tAttribute).isEmpty());
    instance.updateParameters(new DualGraph(graph.getSchema(), graph), params);
    assertEquals(MultiChoiceParameterType.getOptions(nAttribute).size(), 27);
    assertEquals(MultiChoiceParameterType.getChoices(nAttribute).size(), 1);
    assertEquals(MultiChoiceParameterType.getOptions(tAttribute).size(), 9);
    assertEquals(MultiChoiceParameterType.getChoices(tAttribute).size(), 1);
}
Also used : MultiChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) Test(org.testng.annotations.Test)

Example 47 with PluginParameter

use of au.gov.asd.tac.constellation.plugins.parameters.PluginParameter in project constellation by constellation-app.

the class StructuredGraphBuilderPlugin method edit.

@Override
public void edit(final GraphWriteMethods graph, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
    interaction.setProgress(0, 0, "Building...", true);
    final Map<String, PluginParameter<?>> params = parameters.getParameters();
    final int backboneVertexCount = params.get(BACKBONE_SIZE_PARAMETER_ID).getIntegerValue();
    final int backboneDensity = params.get(BACKBONE_DENSITY_PARAMETER_ID).getIntegerValue();
    final int radiusFactor = params.get(RADIUS).getIntegerValue();
    long dt = new Date().getTime();
    // Icons will be chosen from the provided defaults.
    final ArrayList<String> iconNames = new ArrayList<>(IconManager.getIconNames(null));
    // "Name" is already the primary key.
    final int vxNameAttr = VisualConcept.VertexAttribute.LABEL.ensure(graph);
    final int vxIdentifierAttr = VisualConcept.VertexAttribute.IDENTIFIER.ensure(graph);
    final int vxColorAttr = VisualConcept.VertexAttribute.COLOR.ensure(graph);
    final int vxForegroundIconAttr = VisualConcept.VertexAttribute.FOREGROUND_ICON.ensure(graph);
    final int vxBackgroundIconAttr = VisualConcept.VertexAttribute.BACKGROUND_ICON.ensure(graph);
    final int vxSelectedAttr = VisualConcept.VertexAttribute.SELECTED.ensure(graph);
    final int vxVisibilityAttr = VisualConcept.VertexAttribute.VISIBILITY.ensure(graph);
    final int vxXAttr = VisualConcept.VertexAttribute.X.ensure(graph);
    final int vxYAttr = VisualConcept.VertexAttribute.Y.ensure(graph);
    final int vxZAttr = VisualConcept.VertexAttribute.Z.ensure(graph);
    final int vxInterestingAttr = graph.addAttribute(GraphElementType.VERTEX, BooleanAttributeDescription.ATTRIBUTE_NAME, "interesting", null, false, null);
    final int txColorAttr = VisualConcept.TransactionAttribute.COLOR.ensure(graph);
    final int txDateTimeAttr = TemporalConcept.TransactionAttribute.DATETIME.ensure(graph);
    float radius = (float) Math.sqrt(backboneVertexCount) * radiusFactor;
    for (int n = 0; n < backboneVertexCount; n++) {
        final int nodeId = graph.addVertex();
        graph.setStringValue(vxNameAttr, nodeId, NODE + n);
        graph.setStringValue(vxIdentifierAttr, nodeId, NODE + n);
        graph.setStringValue(vxBackgroundIconAttr, nodeId, "Background.Round Circle");
        graph.setStringValue(vxForegroundIconAttr, nodeId, getRandomIconName(iconNames, r));
        graph.setObjectValue(vxColorAttr, nodeId, randomColorWithAlpha(r));
        graph.setFloatValue(vxVisibilityAttr, nodeId, 1.0F);
        float x;
        float y;
        float z;
        float length;
        do {
            x = r.nextFloat() * 2 - 1;
            y = r.nextFloat() * 2 - 1;
            z = r.nextFloat() * 2 - 1;
            length = (float) Math.sqrt(x * x + y * y + z * z);
        } while (length > 1);
        graph.setFloatValue(vxXAttr, nodeId, x * radius);
        graph.setFloatValue(vxYAttr, nodeId, y * radius);
        graph.setFloatValue(vxZAttr, nodeId, z * radius);
    }
    float[] minDistances = new float[backboneVertexCount];
    Arrays.fill(minDistances, Float.MAX_VALUE);
    int[] closestNeighbour = new int[backboneVertexCount];
    for (int s = 0; s < backboneVertexCount; s++) {
        for (int d = s + 1; d < backboneVertexCount; d++) {
            int source = graph.getVertex(s);
            int destination = graph.getVertex(d);
            float sx = graph.getFloatValue(vxXAttr, source);
            float sy = graph.getFloatValue(vxYAttr, source);
            float sz = graph.getFloatValue(vxZAttr, source);
            float dx = graph.getFloatValue(vxXAttr, destination);
            float dy = graph.getFloatValue(vxYAttr, destination);
            float dz = graph.getFloatValue(vxZAttr, destination);
            float x = sx - dx;
            float y = sy - dy;
            float z = sz - dz;
            float distance = (float) Math.sqrt(x * x + y * y + z * z);
            if (minDistances[s] > distance) {
                minDistances[s] = distance;
                closestNeighbour[s] = d;
            }
            if (minDistances[d] > distance) {
                minDistances[d] = distance;
                closestNeighbour[d] = s;
            }
            int transactionCount = (int) (radius / (distance * distance) * r.nextInt(backboneDensity));
            for (int t = 0; t < transactionCount; t++) {
                createRandomTransaction(graph, source, destination, txDateTimeAttr, txColorAttr, r, dt);
            }
        }
    }
    for (int s = 0; s < backboneVertexCount; s++) {
        int source = graph.getVertex(s);
        int destination = closestNeighbour[s];
        createRandomTransaction(graph, source, destination, txDateTimeAttr, txColorAttr, r, dt);
        float cx = graph.getFloatValue(vxXAttr, source);
        float cy = graph.getFloatValue(vxYAttr, source);
        float cz = graph.getFloatValue(vxZAttr, source);
        float minDistance = minDistances[s];
        float pendants = minDistance * minDistance * r.nextFloat() / backboneVertexCount;
        double interestDensity = r.nextDouble() * 0.9;
        interestDensity *= interestDensity * interestDensity * interestDensity * interestDensity;
        for (int p = 0; p < pendants; p++) {
            int pendant = graph.addVertex();
            graph.setStringValue(vxNameAttr, pendant, NODE + pendant);
            graph.setStringValue(vxIdentifierAttr, pendant, NODE + pendant);
            graph.setStringValue(vxBackgroundIconAttr, pendant, "Background.Round Circle_64");
            graph.setStringValue(vxForegroundIconAttr, pendant, getRandomIconName(iconNames, r));
            graph.setObjectValue(vxColorAttr, pendant, randomColorWithAlpha(r));
            graph.setFloatValue(vxVisibilityAttr, pendant, 1.0F);
            float x = r.nextFloat() * 2 - 1;
            float y = r.nextFloat() * 2 - 1;
            float z = r.nextFloat() * 2 - 1;
            float length = (float) Math.sqrt(x * x + y * y + z * z);
            float pendantRadius = minDistance * 0.7F * r.nextFloat();
            graph.setFloatValue(vxXAttr, pendant, cx + x / length * pendantRadius);
            graph.setFloatValue(vxYAttr, pendant, cy + y / length * pendantRadius);
            graph.setFloatValue(vxZAttr, pendant, cz + z / length * pendantRadius);
            graph.setBooleanValue(vxInterestingAttr, pendant, r.nextDouble() < interestDensity);
            createRandomTransaction(graph, source, pendant, txDateTimeAttr, txColorAttr, r, dt);
        }
    }
    int selectedPosition = r.nextInt(backboneVertexCount);
    int selectedVertex = graph.getVertex(selectedPosition);
    graph.setBooleanValue(vxSelectedAttr, selectedVertex, true);
    PluginExecution.withPlugin(InteractiveGraphPluginRegistry.RESET_VIEW).executeNow(graph);
    interaction.setProgress(1, 0, "Completed successfully", true);
}
Also used : ArrayList(java.util.ArrayList) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) Date(java.util.Date)

Example 48 with PluginParameter

use of au.gov.asd.tac.constellation.plugins.parameters.PluginParameter in project constellation by constellation-app.

the class CompleteGraphBuilderPluginNGTest method testUpdateParameters.

/**
 * Test of updateParameters method, of class CompleteGraphBuilderPlugin.
 */
@Test
public void testUpdateParameters() {
    System.out.println("updateParameters");
    final CompleteGraphBuilderPlugin instance = new CompleteGraphBuilderPlugin();
    final PluginParameters params = instance.createParameters();
    final PluginParameter<MultiChoiceParameterValue> nAttribute = (PluginParameter<MultiChoiceParameterValue>) params.getParameters().get(NODE_TYPES_PARAMETER_ID);
    final PluginParameter<MultiChoiceParameterValue> tAttribute = (PluginParameter<MultiChoiceParameterValue>) params.getParameters().get(TRANSACTION_TYPES_PARAMETER_ID);
    assertTrue(MultiChoiceParameterType.getOptions(nAttribute).isEmpty());
    assertTrue(MultiChoiceParameterType.getOptions(tAttribute).isEmpty());
    instance.updateParameters(new DualGraph(graph.getSchema(), graph), params);
    assertEquals(MultiChoiceParameterType.getOptions(nAttribute).size(), 27);
    assertEquals(MultiChoiceParameterType.getChoices(nAttribute).size(), 1);
    assertEquals(MultiChoiceParameterType.getOptions(tAttribute).size(), 9);
    assertEquals(MultiChoiceParameterType.getChoices(tAttribute).size(), 1);
}
Also used : MultiChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) Test(org.testng.annotations.Test)

Example 49 with PluginParameter

use of au.gov.asd.tac.constellation.plugins.parameters.PluginParameter in project constellation by constellation-app.

the class LevenshteinDistancePlugin method updateParameters.

@Override
public void updateParameters(final Graph graph, final PluginParameters parameters) {
    final List<String> stringAttributes = new ArrayList<>();
    if (graph.getSchema() != null) {
        final Map<String, SchemaAttribute> attributes = graph.getSchema().getFactory().getRegisteredAttributes(GraphElementType.VERTEX);
        for (final String attr : attributes.keySet()) {
            final SchemaAttribute attribute = attributes.get(attr);
            final String attributeType = attribute.getAttributeType();
            if (attributeType.equals(StringAttributeDescription.ATTRIBUTE_NAME)) {
                stringAttributes.add(attr);
            }
        }
    }
    stringAttributes.sort(String::compareTo);
    if (parameters != null && parameters.getParameters() != null) {
        // ATTRIBUTE_PARAMETER_ID is created as a SingleChoiceParmeter in this class on line 71.
        @SuppressWarnings("unchecked") final PluginParameter<SingleChoiceParameterValue> compareAttribute = (PluginParameter<SingleChoiceParameterValue>) parameters.getParameters().get(ATTRIBUTE_PARAMETER_ID);
        SingleChoiceParameterType.setOptions(compareAttribute, stringAttributes);
        if (stringAttributes.contains(VisualConcept.VertexAttribute.IDENTIFIER.getName())) {
            SingleChoiceParameterType.setChoice(compareAttribute, VisualConcept.VertexAttribute.IDENTIFIER.getName());
        }
    }
}
Also used : ArrayList(java.util.ArrayList) SchemaAttribute(au.gov.asd.tac.constellation.graph.schema.attribute.SchemaAttribute) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) SingleChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue)

Example 50 with PluginParameter

use of au.gov.asd.tac.constellation.plugins.parameters.PluginParameter in project constellation by constellation-app.

the class DirectedShortestPathsPluginNGTest method testUpdateParameters.

/**
 * Test of updateParameters method, of class DirectedShortestPathsPlugin.
 */
@Test
public void testUpdateParameters() {
    System.out.println("updateParameters");
    final DirectedShortestPathsPlugin instance = new DirectedShortestPathsPlugin();
    final PluginParameters params = instance.createParameters();
    final PluginParameter<SingleChoiceParameterValue> sourceNode = (PluginParameter<SingleChoiceParameterType.SingleChoiceParameterValue>) params.getParameters().get(SOURCE_NODE_PARAMETER_ID);
    assertTrue(SingleChoiceParameterType.getOptions(sourceNode).isEmpty());
    instance.updateParameters(new DualGraph(graph.getSchema(), graph), params);
    assertEquals(SingleChoiceParameterType.getOptions(sourceNode).size(), 5);
    graph.setBooleanValue(vertexSelectedAttribute, vxId4, false);
    instance.updateParameters(new DualGraph(graph.getSchema(), graph), params);
    // confirm the options are only set once (i.e. the graph change won't affect this)
    assertEquals(SingleChoiceParameterType.getOptions(sourceNode).size(), 5);
}
Also used : SingleChoiceParameterType(au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) SingleChoiceParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue) DualGraph(au.gov.asd.tac.constellation.graph.locking.DualGraph) Test(org.testng.annotations.Test)

Aggregations

PluginParameter (au.gov.asd.tac.constellation.plugins.parameters.PluginParameter)93 PluginParameters (au.gov.asd.tac.constellation.plugins.parameters.PluginParameters)53 Test (org.testng.annotations.Test)52 ArrayList (java.util.ArrayList)36 MultiChoiceParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.MultiChoiceParameterType.MultiChoiceParameterValue)25 SingleChoiceParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.SingleChoiceParameterType.SingleChoiceParameterValue)21 Map (java.util.Map)16 PluginInteraction (au.gov.asd.tac.constellation.plugins.PluginInteraction)15 IntegerParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.IntegerParameterType.IntegerParameterValue)13 ReadableGraph (au.gov.asd.tac.constellation.graph.ReadableGraph)12 SchemaTransactionType (au.gov.asd.tac.constellation.graph.schema.type.SchemaTransactionType)11 ParameterChange (au.gov.asd.tac.constellation.plugins.parameters.ParameterChange)11 Graph (au.gov.asd.tac.constellation.graph.Graph)10 Plugin (au.gov.asd.tac.constellation.plugins.Plugin)10 BooleanParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.BooleanParameterType.BooleanParameterValue)10 HashMap (java.util.HashMap)10 PluginException (au.gov.asd.tac.constellation.plugins.PluginException)9 List (java.util.List)9 GraphWriteMethods (au.gov.asd.tac.constellation.graph.GraphWriteMethods)8 StringParameterValue (au.gov.asd.tac.constellation.plugins.parameters.types.StringParameterValue)8