Skip to content
Snippets Groups Projects
Commit 7a3dc737 authored by ThanKarab's avatar ThanKarab
Browse files

Added map to the exareme2 parameters conversion.

parent dc765f63
No related branches found
No related tags found
No related merge requests found
package hbp.mip.models.DTOs.exareme2;
import com.google.gson.JsonSyntaxException;
import hbp.mip.models.DTOs.ExperimentExecutionDTO;
import hbp.mip.utils.JsonConverters;
import java.util.*;
import java.util.stream.Collectors;
public record Exareme2AlgorithmRequestDTO(
String request_id,
......@@ -27,12 +27,12 @@ public record Exareme2AlgorithmRequestDTO(
}
private static Exareme2InputDataRequestDTO getInputData(List<ExperimentExecutionDTO.AlgorithmExecutionDTO.AlgorithmParameterExecutionDTO> exaremeAlgorithmRequestParamDTOs) {
if(exaremeAlgorithmRequestParamDTOs == null){
if (exaremeAlgorithmRequestParamDTOs == null) {
return null;
}
Map<String, String> parameters = new HashMap<>();
for(var parameter: exaremeAlgorithmRequestParamDTOs){
for (var parameter : exaremeAlgorithmRequestParamDTOs) {
parameters.put(parameter.name(), parameter.value());
}
......@@ -66,7 +66,7 @@ public record Exareme2AlgorithmRequestDTO(
}
private static Map<String, Object> getParameters(List<ExperimentExecutionDTO.AlgorithmExecutionDTO.AlgorithmParameterExecutionDTO> exaremeAlgorithmRequestParamDTOs) {
if(exaremeAlgorithmRequestParamDTOs == null){
if (exaremeAlgorithmRequestParamDTOs == null) {
return null;
}
......@@ -82,24 +82,15 @@ public record Exareme2AlgorithmRequestDTO(
}
private static Map<String, Object> getPreprocessing(List<ExperimentExecutionDTO.AlgorithmExecutionDTO.TransformerExecutionDTO> exaremeTransformers) {
if(exaremeTransformers == null){
if (exaremeTransformers == null) {
return null;
}
HashMap<String, Object> exareme2Preprocessing = new HashMap<>();
exaremeTransformers.forEach(transformer -> {
HashMap<String, Object> transformerParameterDTOs = new HashMap<>();
for (ExperimentExecutionDTO.AlgorithmExecutionDTO.AlgorithmParameterExecutionDTO parameter : transformer.parameters()) {
if (parameter.name().equals("strategies")) { // TODO Add this to the proper type conversion, should handle dict as well
transformerParameterDTOs.put(parameter.name(),
JsonConverters.convertJsonStringToObject(parameter.value(), HashMap.class)
);
continue;
}
for (ExperimentExecutionDTO.AlgorithmExecutionDTO.AlgorithmParameterExecutionDTO parameter : transformer.parameters())
transformerParameterDTOs.put(parameter.name(), convertStringToProperExareme2ParameterType(parameter.value()));
}
exareme2Preprocessing.put(transformer.name(), transformerParameterDTOs);
});
......@@ -107,6 +98,9 @@ public record Exareme2AlgorithmRequestDTO(
}
private static Object convertStringToProperExareme2ParameterType(String str) {
if (isMap(str))
return JsonConverters.convertJsonStringToObject(str, Map.class);
String[] stringValues = str.split(",");
if (stringValues.length == 0)
return "";
......@@ -155,6 +149,18 @@ public record Exareme2AlgorithmRequestDTO(
return true;
}
private static boolean isMap(String strMap) {
if (strMap == null) {
return false;
}
try {
JsonConverters.convertJsonStringToObject(strMap, Map.class);
} catch (JsonSyntaxException e) {
return false;
}
return true;
}
public record Exareme2InputDataRequestDTO(String data_model, List<String> datasets, List<String> x, List<String> y,
Exareme2FilterRequestDTO filters) {
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment