use of org.drools.scenariosimulation.api.model.ScesimModelDescriptor in project drools-wb by kiegroup.
the class ScenarioCsvImportExportTest method generateHeader.
@Test
public void generateHeader() throws IOException {
ScesimModelDescriptor simulationDescriptor = new ScesimModelDescriptor();
FactMapping test1FactMapping = createFactMapping(simulationDescriptor, 1);
FactMapping test2FactMapping = createFactMapping(simulationDescriptor, 2);
scenarioCsvImportExport.generateHeader(Arrays.asList(test1FactMapping, test2FactMapping), printer);
System.out.println("output.toString() = " + output.toString());
String[] result = output.toString().split("\r\n");
assertEquals(3, result.length);
assertEquals("GIVEN,GIVEN", result[0]);
assertEquals(instanceName + 1 + "," + instanceName + 2, result[1]);
assertEquals(propertyName + 1 + "," + propertyName + 2, result[2]);
}
use of org.drools.scenariosimulation.api.model.ScesimModelDescriptor in project drools-wb by kiegroup.
the class ScenarioCsvImportExportTest method createDummySimulation.
private Simulation createDummySimulation(int numberOfColumn, int numberOfRow) {
Simulation simulation = new Simulation();
ScesimModelDescriptor simulationDescriptor = simulation.getScesimModelDescriptor();
simulationDescriptor.addFactMapping(FactIdentifier.INDEX, ExpressionIdentifier.INDEX).setExpressionAlias("Index");
simulationDescriptor.addFactMapping(FactIdentifier.DESCRIPTION, ExpressionIdentifier.DESCRIPTION).setExpressionAlias("Description");
for (int col = 0; col < numberOfColumn; col += 1) {
createFactMapping(simulationDescriptor, col);
}
for (int row = 0; row < numberOfRow; row += 1) {
Scenario scenario = simulation.addData();
scenario.addMappingValue(FactIdentifier.INDEX, ExpressionIdentifier.INDEX, row);
scenario.setDescription("My scenario " + row);
for (int col = 2; col < numberOfColumn + 2; col += 1) {
FactMapping factMappingByIndex = simulationDescriptor.getFactMappingByIndex(col);
scenario.addMappingValue(factMappingByIndex.getFactIdentifier(), factMappingByIndex.getExpressionIdentifier(), "value_" + row + "_" + (col - 2));
}
}
return simulation;
}
use of org.drools.scenariosimulation.api.model.ScesimModelDescriptor in project drools-wb by kiegroup.
the class DMNSimulationSettingsCreationStrategyTest method addEmptyColumnIfNeeded.
@Test
public void addEmptyColumnIfNeeded() {
Simulation simulation = new Simulation();
ScenarioWithIndex scenarioWithIndex = new ScenarioWithIndex(1, simulation.addData());
ExpressionIdentifier givenExpressionIdentifier = ExpressionIdentifier.create("given1", GIVEN);
ScesimModelDescriptor simulationDescriptor = simulation.getScesimModelDescriptor();
simulationDescriptor.addFactMapping(FactIdentifier.EMPTY, givenExpressionIdentifier);
dmnSimulationCreationStrategy.addEmptyColumnsIfNeeded(simulation, scenarioWithIndex);
assertEquals(2, simulationDescriptor.getFactMappings().size());
assertTrue(simulationDescriptor.getFactMappings().stream().anyMatch(elem -> EXPECT.equals(elem.getExpressionIdentifier().getType())));
simulation = new Simulation();
scenarioWithIndex = new ScenarioWithIndex(1, simulation.addData());
ExpressionIdentifier expectExpressionIdentifier = ExpressionIdentifier.create("expect1", EXPECT);
simulationDescriptor = simulation.getScesimModelDescriptor();
simulationDescriptor.addFactMapping(FactIdentifier.EMPTY, expectExpressionIdentifier);
dmnSimulationCreationStrategy.addEmptyColumnsIfNeeded(simulation, scenarioWithIndex);
assertEquals(2, simulationDescriptor.getFactMappings().size());
assertTrue(simulationDescriptor.getFactMappings().stream().anyMatch(elem -> GIVEN.equals(elem.getExpressionIdentifier().getType())));
}
use of org.drools.scenariosimulation.api.model.ScesimModelDescriptor in project drools-wb by kiegroup.
the class DMNSimulationSettingsCreationStrategyTest method findNewIndexOfGroup.
@Test
public void findNewIndexOfGroup() {
ScesimModelDescriptor simulationDescriptorGiven = new ScesimModelDescriptor();
ExpressionIdentifier givenExpressionIdentifier = ExpressionIdentifier.create("given1", GIVEN);
simulationDescriptorGiven.addFactMapping(FactIdentifier.EMPTY, givenExpressionIdentifier);
assertEquals(1, dmnSimulationCreationStrategy.findNewIndexOfGroup(simulationDescriptorGiven, GIVEN));
assertEquals(1, dmnSimulationCreationStrategy.findNewIndexOfGroup(simulationDescriptorGiven, EXPECT));
ScesimModelDescriptor simulationDescriptorExpect = new ScesimModelDescriptor();
ExpressionIdentifier expectExpressionIdentifier = ExpressionIdentifier.create("expect1", EXPECT);
simulationDescriptorExpect.addFactMapping(FactIdentifier.EMPTY, expectExpressionIdentifier);
assertEquals(0, dmnSimulationCreationStrategy.findNewIndexOfGroup(simulationDescriptorExpect, GIVEN));
assertEquals(1, dmnSimulationCreationStrategy.findNewIndexOfGroup(simulationDescriptorExpect, EXPECT));
assertThatThrownBy(() -> dmnSimulationCreationStrategy.findNewIndexOfGroup(new ScesimModelDescriptor(), OTHER)).isInstanceOf(IllegalArgumentException.class).hasMessage("This method can be invoked only with GIVEN or EXPECT as FactMappingType");
}
use of org.drools.scenariosimulation.api.model.ScesimModelDescriptor in project drools-wb by kiegroup.
the class DMNSimulationSettingsCreationStrategy method createSimulation.
@Override
public Simulation createSimulation(Path context, String dmnFilePath) {
final FactModelTuple factModelTuple = getFactModelTuple(context, dmnFilePath);
Simulation toReturn = new Simulation();
ScesimModelDescriptor simulationDescriptor = toReturn.getScesimModelDescriptor();
simulationDescriptor.addFactMapping(FactIdentifier.INDEX.getName(), FactIdentifier.INDEX, ExpressionIdentifier.INDEX);
simulationDescriptor.addFactMapping(FactIdentifier.DESCRIPTION.getName(), FactIdentifier.DESCRIPTION, ExpressionIdentifier.DESCRIPTION);
ScenarioWithIndex scenarioWithIndex = createScesimDataWithIndex(toReturn, simulationDescriptor, ScenarioWithIndex::new);
AtomicInteger id = new AtomicInteger(1);
final Collection<FactModelTree> visibleFactTrees = factModelTuple.getVisibleFacts().values();
final Map<String, FactModelTree> hiddenValues = factModelTuple.getHiddenFacts();
visibleFactTrees.stream().sorted((a, b) -> {
Type aType = a.getType();
Type bType = b.getType();
int inputFirstOrder = Type.INPUT.equals(aType) ? -1 : 1;
return aType.equals(bType) ? 0 : inputFirstOrder;
}).forEach(factModelTree -> {
FactIdentifier factIdentifier = FactIdentifier.create(factModelTree.getFactName(), factModelTree.getFactName(), factModelTree.getImportPrefix());
FactMappingExtractor factMappingExtractor = new FactMappingExtractor(factIdentifier, scenarioWithIndex.getIndex(), id, convert(factModelTree.getType()), simulationDescriptor, scenarioWithIndex.getScesimData());
addFactMapping(factMappingExtractor, factModelTree, new ArrayList<>(), hiddenValues);
});
addEmptyColumnsIfNeeded(toReturn, scenarioWithIndex);
return toReturn;
}
Aggregations