Skip to content

Commit

Permalink
display gollm extractions (#3204)
Browse files Browse the repository at this point in the history
  • Loading branch information
YohannParis authored Mar 28, 2024
1 parent 157016d commit 5f4fd64
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import software.uncharted.terarium.hmiserver.models.dataservice.modelparts.ModelMetadata;
import software.uncharted.terarium.hmiserver.models.dataservice.modelparts.ModelParameter;
import software.uncharted.terarium.hmiserver.models.dataservice.modelparts.ModelSemantics;
import software.uncharted.terarium.hmiserver.models.dataservice.modelparts.semantics.Initial;

import java.io.Serial;
import java.sql.Timestamp;
Expand Down Expand Up @@ -91,6 +92,19 @@ public List<ModelParameter> getParameters() {
}
}

@JsonIgnore
@TSIgnore
public List<Initial> getInitials() {
final ObjectMapper objectMapper = new ObjectMapper();
if (this.isRegnet()) {
return objectMapper.convertValue(this.getModel().get("initials"), new TypeReference<List<Initial>>() {
});
} else {
return this.getSemantics().getOde().getInitials();
}

}

@JsonIgnore
@TSIgnore
public boolean isRegnet() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import software.uncharted.terarium.hmiserver.models.dataservice.model.Model;
import software.uncharted.terarium.hmiserver.models.dataservice.model.ModelConfiguration;
import software.uncharted.terarium.hmiserver.models.dataservice.modelparts.ModelParameter;
import software.uncharted.terarium.hmiserver.models.dataservice.modelparts.semantics.Initial;
import software.uncharted.terarium.hmiserver.models.dataservice.provenance.Provenance;
import software.uncharted.terarium.hmiserver.models.dataservice.provenance.ProvenanceRelationType;
import software.uncharted.terarium.hmiserver.models.dataservice.provenance.ProvenanceType;
Expand Down Expand Up @@ -67,20 +68,16 @@ public TaskResponse onSuccess(final TaskResponse resp) {
final Model model = modelService.getAsset(props.getModelId())
.orElseThrow();
final Response configurations = objectMapper.readValue(resp.getOutput(), Response.class);

// Map the parameters values to the model
final Model modelCopy = new Model(model);
final List<ModelParameter> modelParameters = modelCopy.getParameters();
modelParameters.forEach((parameter) -> {
final JsonNode conditionParameters = configurations.getResponse().get("parameters");
conditionParameters.forEach((conditionParameter) -> {
if (parameter.getId().equals(conditionParameter.get("id").asText())) {
parameter.setValue(conditionParameter.get("value").doubleValue());
}
});
});
final JsonNode condition = configurations.getResponse();
final List<ModelParameter> modelParameters = ScenarioExtraction.getModelParameters(condition, modelCopy);
final List<Initial> modelInitials = ScenarioExtraction.getModelInitials(condition, modelCopy);

if (modelCopy.isRegnet()) {
modelCopy.getModel().put("parameters", objectMapper.convertValue(modelParameters, JsonNode.class));
modelCopy.getModel().put("initials", objectMapper.convertValue(modelInitials, JsonNode.class));
}

// Create the new configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import software.uncharted.terarium.hmiserver.models.dataservice.model.Model;
import software.uncharted.terarium.hmiserver.models.dataservice.model.ModelConfiguration;
import software.uncharted.terarium.hmiserver.models.dataservice.modelparts.ModelParameter;
import software.uncharted.terarium.hmiserver.models.dataservice.modelparts.semantics.Initial;
import software.uncharted.terarium.hmiserver.models.dataservice.provenance.Provenance;
import software.uncharted.terarium.hmiserver.models.dataservice.provenance.ProvenanceRelationType;
import software.uncharted.terarium.hmiserver.models.dataservice.provenance.ProvenanceType;
Expand Down Expand Up @@ -69,25 +70,15 @@ public TaskResponse onSuccess(final TaskResponse resp) {

// For each configuration, create a new model configuration with parameters set
for (final JsonNode condition : configurations.response.get("conditions")) {

// Map the parameters values to the model
final Model modelCopy = new Model(model);
final List<ModelParameter> modelParameters = modelCopy.getParameters();
modelParameters.forEach((parameter) -> {
final String parameterId = parameter.getId();
final JsonNode conditionParameters = condition.get("parameters");
conditionParameters.forEach((conditionParameter) -> {
// Get the parameter value from the condition
final String id = conditionParameter.get("id").asText();

// Test against the id of the parameter in greek alphabet or english
if (parameterId.equals(id) || parameterId.equals(GreekDictionary.englishToGreek(id))) {
parameter.setValue(conditionParameter.get("value").doubleValue());
}
});
});
final List<ModelParameter> modelParameters = ScenarioExtraction.getModelParameters(condition, modelCopy);
final List<Initial> modelInitials = ScenarioExtraction.getModelInitials(condition, modelCopy);

if (modelCopy.isRegnet()) {
modelCopy.getModel().put("parameters", objectMapper.convertValue(modelParameters, JsonNode.class));
modelCopy.getModel().put("initials", objectMapper.convertValue(modelInitials, JsonNode.class));
}

// Create the new configuration
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package software.uncharted.terarium.hmiserver.service.tasks;

import com.fasterxml.jackson.databind.JsonNode;
import software.uncharted.terarium.hmiserver.models.dataservice.model.Model;
import software.uncharted.terarium.hmiserver.models.dataservice.modelparts.ModelParameter;
import software.uncharted.terarium.hmiserver.models.dataservice.modelparts.semantics.Initial;
import software.uncharted.terarium.hmiserver.utils.GreekDictionary;

import java.util.List;

public class ScenarioExtraction {
public static List<ModelParameter> getModelParameters(JsonNode condition, Model modelCopy) {
final List<ModelParameter> modelParameters = modelCopy.getParameters();
modelParameters.forEach((parameter) -> {
final String parameterId = parameter.getId();
final JsonNode conditionParameters = condition.get("parameters");
conditionParameters.forEach((conditionParameter) -> {
// Get the parameter value from the condition
final String id = conditionParameter.get("id").asText();

// Test against the id of the parameter in greek alphabet or english
if (parameterId.equals(id) || parameterId.equals(GreekDictionary.englishToGreek(id))) {
parameter.setValue(conditionParameter.get("value").doubleValue());
}
});
});
return modelParameters;
}

public static List<Initial> getModelInitials(JsonNode condition, Model modelCopy) {
final List<Initial> modelInitials = modelCopy.getInitials();
modelInitials.forEach((initial) -> {
final String target = initial.getTarget();
final JsonNode conditionInitials = condition.get("initials");
conditionInitials.forEach((conditionInitial) -> {
// Get the initial value from the condition
final String id = conditionInitial.get("id").asText();

// Test against the id of the initial in greek alphabet or english
if (target.equals(id) || target.equals(GreekDictionary.englishToGreek(id))) {
initial.setExpression(String.valueOf(conditionInitial.get("value").doubleValue()));
}
});
});
return modelInitials;
}
}

0 comments on commit 5f4fd64

Please sign in to comment.