Search in sources :

Example 11 with TypedValue

use of org.kie.kogito.tracing.typedvalue.TypedValue in project kogito-apps by kiegroup.

the class ConversionUtils method toFeatureList.

static List<Feature> toFeatureList(String name, CollectionValue collectionValue) {
    Collection<TypedValue> values = collectionValue.getValue();
    List<Feature> list = new ArrayList<>(values.size());
    int index = 0;
    for (TypedValue typedValue : values) {
        list.add(toFeature(name + "_" + index, typedValue));
        index++;
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) Feature(org.kie.kogito.explainability.model.Feature) NamedTypedValue(org.kie.kogito.explainability.api.NamedTypedValue) TypedValue(org.kie.kogito.tracing.typedvalue.TypedValue)

Example 12 with TypedValue

use of org.kie.kogito.tracing.typedvalue.TypedValue in project kogito-apps by kiegroup.

the class ConversionUtils method toTypedValue.

static TypedValue toTypedValue(Feature feature) {
    String name = feature.getName();
    Type type = feature.getType();
    Value value = feature.getValue();
    return toTypedValue(name, type, value);
}
Also used : Type(org.kie.kogito.explainability.model.Type) CounterfactualSearchDomainValue(org.kie.kogito.explainability.api.CounterfactualSearchDomainValue) Value(org.kie.kogito.explainability.model.Value) HasNameValue(org.kie.kogito.explainability.api.HasNameValue) NamedTypedValue(org.kie.kogito.explainability.api.NamedTypedValue) TypedValue(org.kie.kogito.tracing.typedvalue.TypedValue) UnitValue(org.kie.kogito.tracing.typedvalue.UnitValue) CollectionValue(org.kie.kogito.tracing.typedvalue.CollectionValue)

Example 13 with TypedValue

use of org.kie.kogito.tracing.typedvalue.TypedValue in project kogito-apps by kiegroup.

the class ExplainabilityApiV1IT method testCounterfactualRequestWithStructuredModel.

@Test
@SuppressWarnings("unchecked")
void testCounterfactualRequestWithStructuredModel() {
    ArgumentCaptor<List<NamedTypedValue>> goalsCaptor = ArgumentCaptor.forClass(List.class);
    ArgumentCaptor<List<CounterfactualSearchDomain>> searchDomainsCaptor = ArgumentCaptor.forClass(List.class);
    mockServiceWithCounterfactualRequest();
    CounterfactualRequestResponse response = given().filter(new RequestLoggingFilter()).filter(new ResponseLoggingFilter()).contentType(MediaType.APPLICATION_JSON).body(getCounterfactualWithStructuredModelJsonRequest()).when().post("/executions/decisions/" + TEST_EXECUTION_ID + "/explanations/counterfactuals").as(CounterfactualRequestResponse.class);
    assertNotNull(response);
    assertNotNull(response.getExecutionId());
    assertNotNull(response.getCounterfactualId());
    assertEquals(response.getExecutionId(), TEST_EXECUTION_ID);
    assertEquals(response.getCounterfactualId(), TEST_COUNTERFACTUAL_ID);
    verify(executionService).requestCounterfactuals(eq(TEST_EXECUTION_ID), goalsCaptor.capture(), searchDomainsCaptor.capture());
    List<NamedTypedValue> goalsParameter = goalsCaptor.getValue();
    assertNotNull(goalsParameter);
    assertEquals(1, goalsParameter.size());
    NamedTypedValue goal1 = goalsParameter.get(0);
    assertEquals(TypedValue.Kind.STRUCTURE, goal1.getValue().getKind());
    assertEquals("Fine", goal1.getName());
    assertEquals("tFine", goal1.getValue().getType());
    assertEquals(2, goal1.getValue().toStructure().getValue().size());
    Iterator<Map.Entry<String, TypedValue>> goal1ChildIterator = goal1.getValue().toStructure().getValue().entrySet().iterator();
    Map.Entry<String, TypedValue> goal1Child1 = goal1ChildIterator.next();
    Map.Entry<String, TypedValue> goal1Child2 = goal1ChildIterator.next();
    assertEquals(TypedValue.Kind.UNIT, goal1Child1.getValue().getKind());
    assertEquals("Amount", goal1Child1.getKey());
    assertEquals("number", goal1Child1.getValue().getType());
    assertEquals(100, goal1Child1.getValue().toUnit().getValue().asInt());
    assertEquals(TypedValue.Kind.UNIT, goal1Child2.getValue().getKind());
    assertEquals("Points", goal1Child2.getKey());
    assertEquals("number", goal1Child2.getValue().getType());
    assertEquals(0, goal1Child2.getValue().toUnit().getValue().asInt());
    List<CounterfactualSearchDomain> searchDomainsParameter = searchDomainsCaptor.getValue();
    assertNotNull(searchDomainsParameter);
    assertEquals(1, searchDomainsParameter.size());
    CounterfactualSearchDomain domain1 = searchDomainsParameter.get(0);
    assertEquals(TypedValue.Kind.STRUCTURE, domain1.getValue().getKind());
    assertEquals("Violation", domain1.getName());
    assertEquals("tViolation", domain1.getValue().getType());
    assertEquals(3, domain1.getValue().toStructure().getValue().size());
    Iterator<Map.Entry<String, CounterfactualSearchDomainValue>> domain1ChildIterator = domain1.getValue().toStructure().getValue().entrySet().iterator();
    Map.Entry<String, CounterfactualSearchDomainValue> domain1Child1 = domain1ChildIterator.next();
    Map.Entry<String, CounterfactualSearchDomainValue> domain1Child2 = domain1ChildIterator.next();
    Map.Entry<String, CounterfactualSearchDomainValue> domain1Child3 = domain1ChildIterator.next();
    assertEquals(TypedValue.Kind.UNIT, domain1Child1.getValue().getKind());
    assertFalse(domain1Child1.getValue().toUnit().isFixed());
    assertEquals("Type", domain1Child1.getKey());
    assertEquals("string", domain1Child1.getValue().getType());
    assertNotNull(domain1Child1.getValue().toUnit().getDomain());
    assertTrue(domain1Child1.getValue().toUnit().getDomain() instanceof CounterfactualDomainCategorical);
    CounterfactualDomainCategorical domain1Child1Def = (CounterfactualDomainCategorical) domain1Child1.getValue().toUnit().getDomain();
    assertEquals(2, domain1Child1Def.getCategories().size());
    assertTrue(domain1Child1Def.getCategories().stream().map(JsonNode::asText).collect(Collectors.toList()).containsAll(Arrays.asList("speed", "driving under the influence")));
    assertEquals(TypedValue.Kind.UNIT, domain1Child2.getValue().getKind());
    assertFalse(domain1Child2.getValue().toUnit().isFixed());
    assertEquals("Actual Speed", domain1Child2.getKey());
    assertEquals("number", domain1Child2.getValue().getType());
    assertNotNull(domain1Child2.getValue().toUnit().getDomain());
    assertTrue(domain1Child2.getValue().toUnit().getDomain() instanceof CounterfactualDomainRange);
    CounterfactualDomainRange domain1Child2Def = (CounterfactualDomainRange) domain1Child2.getValue().toUnit().getDomain();
    assertEquals(0, domain1Child2Def.getLowerBound().asInt());
    assertEquals(100, domain1Child2Def.getUpperBound().asInt());
    assertEquals(TypedValue.Kind.UNIT, domain1Child3.getValue().getKind());
    assertFalse(domain1Child3.getValue().toUnit().isFixed());
    assertEquals("Speed Limit", domain1Child3.getKey());
    assertEquals("number", domain1Child3.getValue().getType());
    assertNotNull(domain1Child3.getValue().toUnit().getDomain());
    assertTrue(domain1Child3.getValue().toUnit().getDomain() instanceof CounterfactualDomainRange);
    CounterfactualDomainRange domain1Child3Def = (CounterfactualDomainRange) domain1Child3.getValue().toUnit().getDomain();
    assertEquals(0, domain1Child3Def.getLowerBound().asInt());
    assertEquals(100, domain1Child3Def.getUpperBound().asInt());
}
Also used : CounterfactualDomainRange(org.kie.kogito.explainability.api.CounterfactualDomainRange) CounterfactualDomainCategorical(org.kie.kogito.explainability.api.CounterfactualDomainCategorical) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ResponseLoggingFilter(io.restassured.filter.log.ResponseLoggingFilter) NamedTypedValue(org.kie.kogito.explainability.api.NamedTypedValue) List(java.util.List) ArrayList(java.util.ArrayList) RequestLoggingFilter(io.restassured.filter.log.RequestLoggingFilter) CounterfactualRequestResponse(org.kie.kogito.trusty.service.common.responses.CounterfactualRequestResponse) Map(java.util.Map) CounterfactualSearchDomainValue(org.kie.kogito.explainability.api.CounterfactualSearchDomainValue) NamedTypedValue(org.kie.kogito.explainability.api.NamedTypedValue) TypedValue(org.kie.kogito.tracing.typedvalue.TypedValue) CounterfactualSearchDomain(org.kie.kogito.explainability.api.CounterfactualSearchDomain) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Example 14 with TypedValue

use of org.kie.kogito.tracing.typedvalue.TypedValue in project kogito-runtimes by kiegroup.

the class TraceEventTest method getTraceInputValue.

private TraceInputValue getTraceInputValue(int id) {
    String valueType = "type-" + id;
    TypedValue value = new UnitValue(valueType);
    List<Message> messages = IntStream.range(id + 1, id + 3).mapToObj(DecisionMessageTest::getDecisionMessage).collect(Collectors.toList());
    return new TraceInputValue("id-" + id, "name-" + id, value, messages);
}
Also used : Message(org.kie.kogito.tracing.event.message.Message) UnitValue(org.kie.kogito.tracing.typedvalue.UnitValue) TypedValue(org.kie.kogito.tracing.typedvalue.TypedValue)

Example 15 with TypedValue

use of org.kie.kogito.tracing.typedvalue.TypedValue in project kogito-runtimes by kiegroup.

the class TraceEventTest method getTraceOutputValue.

private TraceOutputValue getTraceOutputValue(int id) {
    String valueType = "type-" + id;
    TypedValue value = new UnitValue(valueType);
    Map<String, TypedValue> inputs = Collections.singletonMap(valueType, value);
    List<Message> messages = IntStream.range(id + 1, id + 3).mapToObj(DecisionMessageTest::getDecisionMessage).collect(Collectors.toList());
    return new TraceOutputValue("id-" + id, "name-" + id, "status-" + id, value, inputs, messages);
}
Also used : Message(org.kie.kogito.tracing.event.message.Message) UnitValue(org.kie.kogito.tracing.typedvalue.UnitValue) TypedValue(org.kie.kogito.tracing.typedvalue.TypedValue)

Aggregations

TypedValue (org.kie.kogito.tracing.typedvalue.TypedValue)15 NamedTypedValue (org.kie.kogito.explainability.api.NamedTypedValue)9 ArrayList (java.util.ArrayList)8 UnitValue (org.kie.kogito.tracing.typedvalue.UnitValue)8 List (java.util.List)7 Test (org.junit.jupiter.api.Test)6 CollectionValue (org.kie.kogito.tracing.typedvalue.CollectionValue)6 TextNode (com.fasterxml.jackson.databind.node.TextNode)4 Map (java.util.Map)4 CounterfactualSearchDomainValue (org.kie.kogito.explainability.api.CounterfactualSearchDomainValue)4 HasNameValue (org.kie.kogito.explainability.api.HasNameValue)4 Feature (org.kie.kogito.explainability.model.Feature)4 Type (org.kie.kogito.explainability.model.Type)4 Value (org.kie.kogito.explainability.model.Value)4 DoubleNode (com.fasterxml.jackson.databind.node.DoubleNode)3 Collection (java.util.Collection)3 Collections.emptyList (java.util.Collections.emptyList)3 Objects (java.util.Objects)3 Collectors (java.util.stream.Collectors)3 Output (org.kie.kogito.explainability.model.Output)3