From dfb6837d419d30222dcea8f8f96a95096ec2d77f Mon Sep 17 00:00:00 2001 From: Cole Blanchard Date: Tue, 13 Aug 2024 14:55:39 -0400 Subject: [PATCH 1/4] fix: extractions from dataset and document --- .../terarium/hmiserver/service/gollm/ScenarioExtraction.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/gollm/ScenarioExtraction.java b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/gollm/ScenarioExtraction.java index cad4c1bea7..0e7da2cba9 100644 --- a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/gollm/ScenarioExtraction.java +++ b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/gollm/ScenarioExtraction.java @@ -40,6 +40,8 @@ public static void replaceParameter(final ModelParameter parameter, final JsonNo if (conditionParameter.has("value")) { final double value = conditionParameter.get("value").doubleValue(); parameter.setValue(value); + // set distribution to null if it is a value + parameter.setDistribution(null); } if (conditionParameter.has("distribution")) { try { From d362ee39de282039629cbeb8d523b480ec297f08 Mon Sep 17 00:00:00 2001 From: Cole Blanchard Date: Tue, 13 Aug 2024 15:58:39 -0400 Subject: [PATCH 2/4] nullify inits and params --- .../service/gollm/ScenarioExtraction.java | 16 ++++++++++++++++ .../ConfigureFromDatasetResponseHandler.java | 4 ++++ .../tasks/ConfigureModelResponseHandler.java | 12 ++++-------- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/gollm/ScenarioExtraction.java b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/gollm/ScenarioExtraction.java index 0e7da2cba9..c104b36ece 100644 --- a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/gollm/ScenarioExtraction.java +++ b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/gollm/ScenarioExtraction.java @@ -83,4 +83,20 @@ public static List getModelInitials(final JsonNode condition, final Mod }); return modelInitials; } + + public static void setNullDefaultModelInitials(final Model modelCopy) { + final List modelInitials = modelCopy.getInitials(); + modelInitials.forEach(initial -> { + initial.setExpression(null); + initial.setExpressionMathml(null); + }); + } + + public static void setNullDefaultModelParameters(final Model modelCopy) { + final List modelParameters = modelCopy.getParameters(); + modelParameters.forEach(parameter -> { + parameter.setValue(null); + parameter.setDistribution(null); + }); + } } diff --git a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/tasks/ConfigureFromDatasetResponseHandler.java b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/tasks/ConfigureFromDatasetResponseHandler.java index e78030c527..1da8bb4359 100644 --- a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/tasks/ConfigureFromDatasetResponseHandler.java +++ b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/tasks/ConfigureFromDatasetResponseHandler.java @@ -72,6 +72,7 @@ public static class Properties { @Override public TaskResponse onSuccess(final TaskResponse resp) { try { + System.out.println("ConfigureFromDatasetResponseHandler.onSuccess"); final Properties props = resp.getAdditionalProperties(Properties.class); final Model model = modelService .getAsset(props.getModelId(), ASSUME_WRITE_PERMISSION_ON_BEHALF_OF_USER) @@ -81,6 +82,9 @@ public TaskResponse onSuccess(final TaskResponse resp) { // Map the parameters values to the model final Model modelCopy = (Model) model.clone(); modelCopy.setId(model.getId()); + ScenarioExtraction.setNullDefaultModelInitials(modelCopy); + ScenarioExtraction.setNullDefaultModelParameters(modelCopy); + final JsonNode condition = configurations.getResponse().get("values"); final List modelParameters = ScenarioExtraction.getModelParameters(condition, modelCopy); final List modelInitials = ScenarioExtraction.getModelInitials(condition, modelCopy); diff --git a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/tasks/ConfigureModelResponseHandler.java b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/tasks/ConfigureModelResponseHandler.java index 3e23f23172..424caf0112 100644 --- a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/tasks/ConfigureModelResponseHandler.java +++ b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/tasks/ConfigureModelResponseHandler.java @@ -78,20 +78,16 @@ public TaskResponse onSuccess(final TaskResponse resp) { for (final JsonNode condition : configurations.response.get("conditions")) { final Model modelCopy = model.clone(); modelCopy.setId(model.getId()); - + ScenarioExtraction.setNullDefaultModelInitials(modelCopy); + ScenarioExtraction.setNullDefaultModelParameters(modelCopy); // Map the parameters values to the model if (condition.has("parameters")) { - final List modelParameters = ScenarioExtraction.getModelParameters( - condition.get("parameters"), - modelCopy - ); - modelCopy.getSemantics().getOde().setParameters(modelParameters); + ScenarioExtraction.getModelParameters(condition.get("parameters"), modelCopy); } // Map the initials values to the model if (condition.has("initials")) { - final List modelInitials = ScenarioExtraction.getModelInitials(condition.get("initials"), modelCopy); - modelCopy.getSemantics().getOde().setInitials(modelInitials); + ScenarioExtraction.getModelInitials(condition.get("initials"), modelCopy); } // Create the new configuration From 6d75c163dd3cfb4fdb455b31147f7dfec28711db Mon Sep 17 00:00:00 2001 From: asylves1 Date: Wed, 14 Aug 2024 12:12:11 -0400 Subject: [PATCH 3/4] remove system.out statement --- .../service/tasks/ConfigureFromDatasetResponseHandler.java | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/tasks/ConfigureFromDatasetResponseHandler.java b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/tasks/ConfigureFromDatasetResponseHandler.java index 1da8bb4359..3ca89ccb10 100644 --- a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/tasks/ConfigureFromDatasetResponseHandler.java +++ b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/tasks/ConfigureFromDatasetResponseHandler.java @@ -72,7 +72,6 @@ public static class Properties { @Override public TaskResponse onSuccess(final TaskResponse resp) { try { - System.out.println("ConfigureFromDatasetResponseHandler.onSuccess"); final Properties props = resp.getAdditionalProperties(Properties.class); final Model model = modelService .getAsset(props.getModelId(), ASSUME_WRITE_PERMISSION_ON_BEHALF_OF_USER) From 83e73ffb13e3a39ea34947b1b3c9c5a92ccb1418 Mon Sep 17 00:00:00 2001 From: asylves1 Date: Wed, 14 Aug 2024 13:13:10 -0400 Subject: [PATCH 4/4] suggested changes --- .../service/gollm/ScenarioExtraction.java | 29 +++++++++---------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/gollm/ScenarioExtraction.java b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/gollm/ScenarioExtraction.java index c104b36ece..5b1ac6f3ba 100644 --- a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/gollm/ScenarioExtraction.java +++ b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/service/gollm/ScenarioExtraction.java @@ -58,9 +58,9 @@ public static void replaceParameter(final ModelParameter parameter, final JsonNo } } - public static List getModelParameters(final JsonNode condition, final Model modelCopy) { - final List modelParameters = modelCopy.getParameters(); - modelParameters.forEach(parameter -> { + public static List getModelParameters(final JsonNode condition, final Model model) { + final List parameters = model.getParameters(); + parameters.forEach(parameter -> { condition.forEach(conditionParameter -> { // Test if type exist and is parameter for Dataset extraction if (conditionParameter.has("type") && conditionParameter.get("type").asText().equals("initial")) { @@ -69,32 +69,31 @@ public static List getModelParameters(final JsonNode condition, replaceParameter(parameter, conditionParameter); }); }); - return modelParameters; + return parameters; } - public static List getModelInitials(final JsonNode condition, final Model modelCopy) { - final List modelInitials = modelCopy.getInitials(); - modelInitials.forEach(initial -> { - final String target = initial.getTarget(); + public static List getModelInitials(final JsonNode condition, final Model model) { + final List initials = model.getInitials(); + initials.forEach(initial -> { condition.forEach(conditionInitial -> { if (conditionInitial.has("type") && conditionInitial.get("type").asText().equals("parameter")) return; replaceInitial(initial, conditionInitial); }); }); - return modelInitials; + return initials; } - public static void setNullDefaultModelInitials(final Model modelCopy) { - final List modelInitials = modelCopy.getInitials(); - modelInitials.forEach(initial -> { + public static void setNullDefaultModelInitials(final Model model) { + final List initials = model.getInitials(); + initials.forEach(initial -> { initial.setExpression(null); initial.setExpressionMathml(null); }); } - public static void setNullDefaultModelParameters(final Model modelCopy) { - final List modelParameters = modelCopy.getParameters(); - modelParameters.forEach(parameter -> { + public static void setNullDefaultModelParameters(final Model model) { + final List parameters = model.getParameters(); + parameters.forEach(parameter -> { parameter.setValue(null); parameter.setDistribution(null); });