Search in sources :

Example 41 with PluginParameter

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

the class CompleteGraphBuilderPlugin 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 n = params.get(N_PARAMETER_ID).getIntegerValue();
    final boolean randomWeights = params.get(RANDOM_WEIGHTS_PARAMETER_ID).getBooleanValue();
    final List<String> nodeTypes = params.get(NODE_TYPES_PARAMETER_ID).getMultiChoiceValue().getChoices();
    final List<String> transactionTypes = params.get(TRANSACTION_TYPES_PARAMETER_ID).getMultiChoiceValue().getChoices();
    // Random countries to put in the graph
    final List<String> countries = new ArrayList<>();
    countries.add("Australia");
    countries.add("Brazil");
    countries.add("China");
    countries.add("France");
    countries.add("Japan");
    countries.add("New Zealand");
    countries.add("South Africa");
    countries.add("United Arab Emirates");
    countries.add("United Kingdom");
    countries.add("United States");
    final int vxIdentifierAttr = VisualConcept.VertexAttribute.IDENTIFIER.ensure(graph);
    final int vxTypeAttr = AnalyticConcept.VertexAttribute.TYPE.ensure(graph);
    final int vxIsGoodAttr = graph.addAttribute(GraphElementType.VERTEX, BooleanAttributeDescription.ATTRIBUTE_NAME, "isGood", null, false, null);
    final int vxCountryAttr = SpatialConcept.VertexAttribute.COUNTRY.ensure(graph);
    final int vxPinnedAttr = VisualConcept.VertexAttribute.PINNED.ensure(graph);
    final int txIdAttr = VisualConcept.TransactionAttribute.IDENTIFIER.ensure(graph);
    final int txTypeAttr = AnalyticConcept.TransactionAttribute.TYPE.ensure(graph);
    final int txDateTimeAttr = TemporalConcept.TransactionAttribute.DATETIME.ensure(graph);
    final VertexDecorators decorators;
    decorators = new VertexDecorators(graph.getAttributeName(vxCountryAttr), graph.getAttributeName(vxPinnedAttr), null, graph.getAttributeName(vxIsGoodAttr));
    final int decoratorsAttr = VisualConcept.GraphAttribute.DECORATORS.ensure(graph);
    graph.setObjectValue(decoratorsAttr, 0, decorators);
    final int[] vxIds = new int[n];
    int vx = 0;
    while (vx < n) {
        final int vxId = graph.addVertex();
        final String label = "Node_" + vxId;
        graph.setStringValue(vxIdentifierAttr, vxId, label);
        graph.setStringValue(vxTypeAttr, vxId, nodeTypes.get(r.nextInt(nodeTypes.size())));
        graph.setBooleanValue(vxIsGoodAttr, vxId, r.nextInt(10) == 0);
        graph.setStringValue(vxCountryAttr, vxId, countries.get(r.nextInt(countries.size())));
        if (graph.getSchema() != null) {
            graph.getSchema().completeVertex(graph, vxId);
        }
        vxIds[vx] = vxId;
        vx++;
        if (Thread.interrupted()) {
            throw new InterruptedException();
        }
    }
    // Create transactions between the nodes.
    final Date d = new Date();
    final int fourDays = 4 * 24 * 60 * 60 * 1000;
    for (final int x : vxIds) {
        for (final int y : vxIds) {
            if (x == y) {
                continue;
            }
            final int reciprocity = r.nextInt(3);
            int numTimes = 1;
            if (randomWeights) {
                numTimes = r.nextInt(1 + r.nextInt(100));
            }
            for (int i = 0; i < numTimes; i++) {
                int sxId = x;
                int dxId = y;
                if (randomWeights) {
                    switch(reciprocity) {
                        case 0:
                            final boolean random0 = r.nextBoolean();
                            if (random0) {
                                sxId = y;
                                dxId = x;
                            }
                            break;
                        case 1:
                            final int random1 = r.nextInt(5);
                            if (random1 == 0) {
                                sxId = y;
                                dxId = x;
                            }
                            break;
                        default:
                            final int randomDefault = r.nextInt(5);
                            if (randomDefault != 0) {
                                sxId = y;
                                dxId = x;
                            }
                            break;
                    }
                }
                final int e = graph.addTransaction(sxId, dxId, true);
                graph.setLongValue(txDateTimeAttr, e, d.getTime() - r.nextInt(fourDays));
                graph.setStringValue(txTypeAttr, e, transactionTypes.get(r.nextInt(transactionTypes.size())));
                graph.setIntValue(txIdAttr, e, e);
                if (graph.getSchema() != null) {
                    graph.getSchema().completeTransaction(graph, e);
                }
                if (Thread.interrupted()) {
                    throw new InterruptedException();
                }
            }
            if (Thread.interrupted()) {
                throw new InterruptedException();
            }
        }
        if (Thread.interrupted()) {
            throw new InterruptedException();
        }
    }
    try {
        if (n < 10000) {
            // Do a trees layout.
            PluginExecutor.startWith(ArrangementPluginRegistry.TREES).followedBy(InteractiveGraphPluginRegistry.RESET_VIEW).executeNow(graph);
        } else {
            // Do a grid layout.
            PluginExecutor.startWith(ArrangementPluginRegistry.GRID_COMPOSITE).followedBy(InteractiveGraphPluginRegistry.RESET_VIEW).executeNow(graph);
        }
    } catch (final PluginException ex) {
        LOGGER.log(Level.SEVERE, ex.getLocalizedMessage(), ex);
    }
    interaction.setProgress(1, 0, "Completed successfully", true);
}
Also used : VertexDecorators(au.gov.asd.tac.constellation.graph.schema.visual.VertexDecorators) PluginException(au.gov.asd.tac.constellation.plugins.PluginException) ArrayList(java.util.ArrayList) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) Date(java.util.Date)

Example 42 with PluginParameter

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

the class SynchronizerPlugin method createParameters.

@Override
public PluginParameters createParameters() {
    final PluginParameters parameters = new PluginParameters();
    parameters.addParameter(StringParameterType.build(NAME_PARAMETER_ID));
    parameters.addParameter(StringParameterType.build(COPY_PARAMETER_ID));
    parameters.addController(NAME_PARAMETER_ID, (final PluginParameter<?> master, final Map<String, PluginParameter<?>> params, final ParameterChange change) -> {
        if (change == ParameterChange.VALUE) {
            // COPY_PARAMETER will be of type StringParameter
            @SuppressWarnings("unchecked") final PluginParameter<StringParameterValue> slave = (PluginParameter<StringParameterValue>) params.get(COPY_PARAMETER_ID);
            slave.setStringValue("COPY: " + master.getStringValue());
        }
    });
    return parameters;
}
Also used : ParameterChange(au.gov.asd.tac.constellation.plugins.parameters.ParameterChange) StringParameterValue(au.gov.asd.tac.constellation.plugins.parameters.types.StringParameterValue) PluginParameters(au.gov.asd.tac.constellation.plugins.parameters.PluginParameters) PluginParameter(au.gov.asd.tac.constellation.plugins.parameters.PluginParameter) Map(java.util.Map)

Example 43 with PluginParameter

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

the class PreferentialAttachmentGraphBuilderPluginNGTest method testUpdateParameters.

/**
 * Test of updateParameters method, of class PreferentialAttachmentGraphBuilderPlugin.
 */
@Test
public void testUpdateParameters() {
    System.out.println("updateParameters");
    final PreferentialAttachmentGraphBuilderPlugin instance = new PreferentialAttachmentGraphBuilderPlugin();
    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 44 with PluginParameter

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

the class PreferentialAttachmentGraphBuilderPluginNGTest method testUpdateParametersNullGraph.

/**
 * Test of updateParameters method, of class PreferentialAttachmentGraphBuilderPlugin. Null graph
 */
@Test
public void testUpdateParametersNullGraph() {
    System.out.println("updateParametersNullGraph");
    final PreferentialAttachmentGraphBuilderPlugin instance = new PreferentialAttachmentGraphBuilderPlugin();
    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(null, params);
    assertTrue(MultiChoiceParameterType.getOptions(nAttribute).isEmpty());
    assertTrue(MultiChoiceParameterType.getOptions(tAttribute).isEmpty());
}
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) Test(org.testng.annotations.Test)

Example 45 with PluginParameter

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

the class SmallWorldGraphBuilderPluginNGTest method testUpdateParametersNullGraph.

/**
 * Test of updateParameters method, of class SmallWorldGraphBuilderPlugin. Null graph
 */
@Test
public void testUpdateParametersNullGraph() {
    System.out.println("updateParametersNullGraph");
    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(null, params);
    assertTrue(MultiChoiceParameterType.getOptions(nAttribute).isEmpty());
    assertTrue(MultiChoiceParameterType.getOptions(tAttribute).isEmpty());
}
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) 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