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);
}
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;
}
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);
}
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());
}
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());
}
Aggregations