use of org.kie.kogito.tracing.typedvalue.UnitValue in project kogito-apps by kiegroup.
the class TrustyServiceTest method doGivenStoredExecutionWhenCounterfactualRequestIsMadeThenRequestIsStoredTest.
@SuppressWarnings("unchecked")
void doGivenStoredExecutionWhenCounterfactualRequestIsMadeThenRequestIsStoredTest(CounterfactualDomain domain) {
Storage<String, Decision> decisionStorage = mock(Storage.class);
Storage<String, CounterfactualExplainabilityRequest> counterfactualStorage = mock(Storage.class);
ArgumentCaptor<CounterfactualExplainabilityRequest> counterfactualArgumentCaptor = ArgumentCaptor.forClass(CounterfactualExplainabilityRequest.class);
when(decisionStorage.containsKey(eq(TEST_EXECUTION_ID))).thenReturn(true);
when(trustyStorageServiceMock.getDecisionsStorage()).thenReturn(decisionStorage);
when(trustyStorageServiceMock.getCounterfactualRequestStorage()).thenReturn(counterfactualStorage);
when(decisionStorage.get(eq(TEST_EXECUTION_ID))).thenReturn(TrustyServiceTestUtils.buildCorrectDecision(TEST_EXECUTION_ID));
// The Goals structures must be comparable to the original decisions outcomes.
// The Search Domain structures must be identical those of the original decision inputs.
trustyService.requestCounterfactuals(TEST_EXECUTION_ID, List.of(new NamedTypedValue("Fine", new StructureValue("tFine", Map.of("Amount", new UnitValue("number", "number", new IntNode(0)), "Points", new UnitValue("number", "number", new IntNode(0))))), new NamedTypedValue("Should the driver be suspended?", new UnitValue("string", "string", new TextNode("No")))), List.of(new CounterfactualSearchDomain("Violation", new CounterfactualSearchDomainStructureValue("tViolation", Map.of("Type", new CounterfactualSearchDomainUnitValue("string", "string", true, domain), "Actual Speed", new CounterfactualSearchDomainUnitValue("number", "number", true, domain), "Speed Limit", new CounterfactualSearchDomainUnitValue("number", "number", true, domain)))), new CounterfactualSearchDomain("Driver", new CounterfactualSearchDomainStructureValue("tDriver", Map.of("Age", new CounterfactualSearchDomainUnitValue("number", "number", true, domain), "Points", new CounterfactualSearchDomainUnitValue("number", "number", true, domain))))));
verify(counterfactualStorage).put(anyString(), counterfactualArgumentCaptor.capture());
CounterfactualExplainabilityRequest counterfactual = counterfactualArgumentCaptor.getValue();
assertNotNull(counterfactual);
assertEquals(TEST_EXECUTION_ID, counterfactual.getExecutionId());
}
use of org.kie.kogito.tracing.typedvalue.UnitValue in project kogito-apps by kiegroup.
the class DecisionsApiV1IT method buildValidDecision.
private Decision buildValidDecision(ListStatus inputsStatus, ListStatus outcomesStatus) throws Exception {
ObjectMapper mapper = new ObjectMapper();
Decision decision = new Decision();
decision.setExecutionId(TEST_EXECUTION_ID);
decision.setSourceUrl(TEST_SOURCE_URL);
decision.setExecutionTimestamp(TEST_EXECUTION_TIMESTAMP);
decision.setSuccess(true);
decision.setExecutedModelName(TEST_MODEL_NAME);
decision.setExecutedModelNamespace(TEST_MODEL_NAMESPACE);
switch(inputsStatus) {
case EMPTY:
decision.setInputs(List.of());
break;
case FULL:
decision.setInputs(List.of(new DecisionInput("1", "first", new UnitValue("string", "string", mapper.readTree("\"Hello\""))), new DecisionInput("2", "second", new UnitValue("number", "number", mapper.readTree("12345")))));
}
switch(outcomesStatus) {
case EMPTY:
decision.setOutcomes(List.of());
break;
case FULL:
decision.setOutcomes(List.of(new DecisionOutcome(TEST_OUTCOME_ID, "ONE", "SUCCEEDED", new UnitValue("string", "string", mapper.readTree("\"The First " + "Outcome\"")), Collections.emptyList(), List.of(getMessage(MessageLevel.WARNING, MessageCategory.INTERNAL, "TEST", "testSrc", "Test message", getMessageExceptionField("TestException", "Test exception message", getMessageExceptionField("TestExceptionCause", "Test exception " + "cause " + "message", null)))))));
}
return decision;
}
use of org.kie.kogito.tracing.typedvalue.UnitValue in project kogito-apps by kiegroup.
the class AbstractTrustyServiceIT method testStoreExplainabilityResult_Counterfactual.
@Test
public void testStoreExplainabilityResult_Counterfactual() {
String executionId = "myCFExecution1Store";
NamedTypedValue input1 = new NamedTypedValue("field1", new UnitValue("typeRef1", "typeRef1", new IntNode(25)));
NamedTypedValue input2 = new NamedTypedValue("field2", new UnitValue("typeRef2", "typeRef2", new IntNode(99)));
NamedTypedValue output1 = new NamedTypedValue("field3", new UnitValue("typeRef3", "typeRef3", new IntNode(200)));
NamedTypedValue output2 = new NamedTypedValue("field4", new UnitValue("typeRef4", "typeRef4", new IntNode(1000)));
trustyService.storeExplainabilityResult(executionId, new CounterfactualExplainabilityResult(executionId, "counterfactualId", "solutionId", 0L, ExplainabilityStatus.SUCCEEDED, "status", true, CounterfactualExplainabilityResult.Stage.FINAL, List.of(input1, input2), List.of(output1, output2)));
CounterfactualExplainabilityResult result = trustyService.getExplainabilityResultById(executionId, CounterfactualExplainabilityResult.class);
assertNotNull(result);
}
use of org.kie.kogito.tracing.typedvalue.UnitValue in project kogito-apps by kiegroup.
the class AbstractTrustyServiceIT method testStoreExplainabilityResult_Counterfactual_DuplicateRemoval_IntermediateThenFinal.
@Test
public void testStoreExplainabilityResult_Counterfactual_DuplicateRemoval_IntermediateThenFinal() {
String executionId = "myCFExecution1Store";
String counterfactualId = "myCFCounterfactualId";
NamedTypedValue input1 = new NamedTypedValue("field1", new UnitValue("typeRef1", "typeRef1", new IntNode(25)));
NamedTypedValue input2 = new NamedTypedValue("field2", new UnitValue("typeRef2", "typeRef2", new IntNode(99)));
NamedTypedValue output1 = new NamedTypedValue("field3", new UnitValue("typeRef3", "typeRef3", new IntNode(200)));
NamedTypedValue output2 = new NamedTypedValue("field4", new UnitValue("typeRef4", "typeRef4", new IntNode(1000)));
// First solution is the INTERMEDIATE then the FINAL
trustyService.storeExplainabilityResult(executionId, new CounterfactualExplainabilityResult(executionId, counterfactualId, "solutionId1", 0L, ExplainabilityStatus.SUCCEEDED, "status", true, CounterfactualExplainabilityResult.Stage.INTERMEDIATE, List.of(input1, input2), List.of(output1, output2)));
List<CounterfactualExplainabilityResult> result1 = trustyService.getCounterfactualResults(executionId, counterfactualId);
assertNotNull(result1);
assertEquals(1, result1.size());
assertEquals("solutionId1", result1.get(0).getSolutionId());
assertEquals(CounterfactualExplainabilityResult.Stage.INTERMEDIATE, result1.get(0).getStage());
trustyService.storeExplainabilityResult(executionId, new CounterfactualExplainabilityResult(executionId, counterfactualId, "solutionId2", 0L, ExplainabilityStatus.SUCCEEDED, "status", true, CounterfactualExplainabilityResult.Stage.FINAL, List.of(input1, input2), List.of(output1, output2)));
List<CounterfactualExplainabilityResult> result2 = trustyService.getCounterfactualResults(executionId, counterfactualId);
assertNotNull(result2);
assertEquals(1, result2.size());
assertEquals("solutionId2", result2.get(0).getSolutionId());
assertEquals(CounterfactualExplainabilityResult.Stage.FINAL, result2.get(0).getStage());
}
use of org.kie.kogito.tracing.typedvalue.UnitValue in project kogito-apps by kiegroup.
the class AbstractTrustyServiceIT method storeExecution.
private void storeExecution(String executionId, Long timestamp) {
DecisionInput decisionInput = new DecisionInput();
decisionInput.setId("inputId");
decisionInput.setName("test");
decisionInput.setValue(new UnitValue("number", "number", JsonNodeFactory.instance.numberNode(10)));
Decision decision = new Decision();
decision.setExecutionId(executionId);
decision.setExecutionTimestamp(timestamp);
decision.setServiceUrl("serviceUrl");
decision.setExecutedModelNamespace("executedModelNamespace");
decision.setExecutedModelName("executedModelName");
decision.setInputs(Collections.singletonList(decisionInput));
trustyService.storeDecision(decision.getExecutionId(), decision);
}
Aggregations