Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: extractions from dataset and document #4444

Merged
merged 5 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -56,9 +58,9 @@ public static void replaceParameter(final ModelParameter parameter, final JsonNo
}
}

public static List<ModelParameter> getModelParameters(final JsonNode condition, final Model modelCopy) {
final List<ModelParameter> modelParameters = modelCopy.getParameters();
modelParameters.forEach(parameter -> {
public static List<ModelParameter> getModelParameters(final JsonNode condition, final Model model) {
final List<ModelParameter> 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")) {
Expand All @@ -67,18 +69,33 @@ public static List<ModelParameter> getModelParameters(final JsonNode condition,
replaceParameter(parameter, conditionParameter);
});
});
return modelParameters;
return parameters;
}

public static List<Initial> getModelInitials(final JsonNode condition, final Model modelCopy) {
final List<Initial> modelInitials = modelCopy.getInitials();
modelInitials.forEach(initial -> {
final String target = initial.getTarget();
public static List<Initial> getModelInitials(final JsonNode condition, final Model model) {
final List<Initial> 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 model) {
final List<Initial> initials = model.getInitials();
initials.forEach(initial -> {
initial.setExpression(null);
initial.setExpressionMathml(null);
});
}

public static void setNullDefaultModelParameters(final Model model) {
final List<ModelParameter> parameters = model.getParameters();
parameters.forEach(parameter -> {
parameter.setValue(null);
parameter.setDistribution(null);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,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<ModelParameter> modelParameters = ScenarioExtraction.getModelParameters(condition, modelCopy);
final List<Initial> modelInitials = ScenarioExtraction.getModelInitials(condition, modelCopy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ModelParameter> 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<Initial> modelInitials = ScenarioExtraction.getModelInitials(condition.get("initials"), modelCopy);
modelCopy.getSemantics().getOde().setInitials(modelInitials);
ScenarioExtraction.getModelInitials(condition.get("initials"), modelCopy);
}

// Create the new configuration
Expand Down
Loading