Skip to content

Commit

Permalink
fix: Rework raw user settings hierarchy
Browse files Browse the repository at this point in the history
These changes allow that all settings are null in the beginning and only the raw settings from the users are initialized. This allows to later differentiate what settings have been given by the user and which not.
What is missing is the remaining logic: Set the default_config as the next hierarchy and after all the remaining defaults, that are necessary.
  • Loading branch information
MichaelsJP committed Jul 30, 2024
1 parent 2db243d commit 476d1ad
Show file tree
Hide file tree
Showing 19 changed files with 460 additions and 361 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,24 @@
import org.heigit.ors.config.utils.PathSerializer;

import java.nio.file.Path;
import java.nio.file.Paths;

@Getter
@Setter(AccessLevel.PACKAGE)
@Setter(AccessLevel.PROTECTED)
public class ElevationProperties {
private boolean preprocessed = false;
@Getter
private Boolean preprocessed;
@JsonProperty("data_access")
private DataAccessEnum dataAccess = DataAccessEnum.MMAP;
private DataAccessEnum dataAccess;
@JsonProperty("cache_clear")
private boolean cacheClear = false;
private Boolean cacheClear;
@JsonProperty("provider")
private String provider = "multi";
private String provider;
@JsonProperty("cache_path")
@JsonDeserialize(using = PathDeserializer.class)
@JsonSerialize(using = PathSerializer.class)
private Path cachePath = Paths.get("./elevation_cache");
private Path cachePath;

public Boolean isPreprocessed() {
return preprocessed;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import lombok.Setter;
import org.heigit.ors.common.DataAccessEnum;
import org.heigit.ors.config.profile.ProfileProperties;
import org.heigit.ors.config.profile.defaults.*;
import org.heigit.ors.config.profile.defaults.DefaultElevationProperties;
import org.heigit.ors.config.profile.defaults.DefaultProfileProperties;
import org.heigit.ors.config.profile.defaults.DefaultProfiles;
import org.heigit.ors.config.utils.PathDeserializer;
import org.heigit.ors.config.utils.PathSerializer;
import org.heigit.ors.routing.configuration.RouteProfileConfiguration;
Expand All @@ -22,46 +24,54 @@
import java.util.Map;

@Getter
@Setter(AccessLevel.PACKAGE)
@Setter(AccessLevel.PROTECTED)
public class EngineProperties {

private static final Map<String, ProfileProperties> DEFAULT_PROFILES = new LinkedHashMap<>();
static {
DEFAULT_PROFILES.put("car", new DefaultProfilePropertiesCar());
DEFAULT_PROFILES.put("hgv", new DefaultProfilePropertiesHgv());
DEFAULT_PROFILES.put("bike-regular", new DefaultProfilePropertiesBikeRegular());
DEFAULT_PROFILES.put("bike-electric", new DefaultProfilePropertiesBikeElectric());
DEFAULT_PROFILES.put("bike-mountain", new DefaultProfilePropertiesBikeMountain());
DEFAULT_PROFILES.put("bike-road", new DefaultProfilePropertiesBikeRoad());
DEFAULT_PROFILES.put("walking", new DefaultProfilePropertiesWalking());
DEFAULT_PROFILES.put("hiking", new DefaultProfilePropertiesHiking());
DEFAULT_PROFILES.put("wheelchair", new DefaultProfilePropertiesWheelchair());
DEFAULT_PROFILES.put("public-transport", new DefaultProfilePropertiesPublicTransport());
}
@JsonIgnore
private Map<String, ProfileProperties> default_profiles = new LinkedHashMap<>();

@JsonProperty("source_file")
@JsonDeserialize(using = PathDeserializer.class)
@JsonSerialize(using = PathSerializer.class)
private Path sourceFile = Paths.get("");
private Path sourceFile;
@JsonProperty("init_threads")
private Integer initThreads = 1;
private Integer initThreads;
@JsonProperty("preparation_mode")
private Boolean preparationMode = false;
private Boolean preparationMode;
@JsonProperty("config_output_mode")
private Boolean configOutputMode = false;
private Boolean configOutputMode;
@JsonProperty("graphs_root_path")
@JsonDeserialize(using = PathDeserializer.class)
@JsonSerialize(using = PathSerializer.class)
private Path graphsRootPath = Paths.get("./graphs");
private Path graphsRootPath;
@JsonProperty("graphs_data_access")
private DataAccessEnum graphsDataAccess = DataAccessEnum.RAM_STORE;
private DataAccessEnum graphsDataAccess;

@JsonProperty("elevation")
private ElevationProperties elevation = new ElevationProperties();
private ElevationProperties elevation;
@JsonProperty("profile_default")
private ProfileProperties profileDefault = new DefaultProfileProperties();
private ProfileProperties profileDefault;
@JsonProperty("profiles")
private Map<String, ProfileProperties> profiles = DEFAULT_PROFILES;
private Map<String, ProfileProperties> profiles;

public EngineProperties() {
this(false);
}

public EngineProperties(Boolean setDefaults) {
setProfiles(new LinkedHashMap<>());
setProfileDefault(new DefaultProfileProperties(setDefaults));
setDefault_profiles(new DefaultProfiles(setDefaults).getProfiles());
setElevation(new DefaultElevationProperties(setDefaults));
if (setDefaults) {
setSourceFile(Paths.get(""));
setInitThreads(1);
setPreparationMode(false);
setConfigOutputMode(false);
setGraphsRootPath(Paths.get("./graphs"));
setGraphsDataAccess(DataAccessEnum.RAM_STORE);
}
}

@JsonIgnore
public RouteProfileConfiguration[] getConvertedProfiles() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;
Expand Down Expand Up @@ -53,7 +52,7 @@ public MethodsProperties(Boolean setDefaults) {
@Setter
@JsonInclude(JsonInclude.Include.NON_NULL)
public static class CHProperties {
@Getter(AccessLevel.NONE)
@JsonProperty("enabled")
private Boolean enabled;
private Integer threads;
private String weightings;
Expand All @@ -68,7 +67,7 @@ public Boolean isEnabled() {
@Setter
@JsonInclude(JsonInclude.Include.NON_NULL)
public static class LMProperties {
@Getter(AccessLevel.NONE)
@JsonProperty("enabled")
private Boolean enabled;
private Integer threads;
private String weightings;
Expand All @@ -84,7 +83,7 @@ public Boolean isEnabled() {
@Setter
@JsonInclude(JsonInclude.Include.NON_NULL)
public static class CoreProperties {
@Getter(AccessLevel.NONE)
@JsonProperty("enabled")
private Boolean enabled;
private Integer threads;
private String weightings;
Expand All @@ -101,7 +100,7 @@ public Boolean isEnabled() {
@Setter
@JsonInclude(JsonInclude.Include.NON_NULL)
public static class FastIsochroneProperties {
@Getter(AccessLevel.NONE)
@JsonProperty("enabled")
private Boolean enabled;
private Integer threads;
private String weightings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,49 +99,91 @@ public abstract class ProfileProperties {
private Map<String, ExtendedStorage> extStorages = new HashMap<>();

protected ProfileProperties() {
encoderOptions = new DefaultEncoderOptionsProperties();
preparation = new PreparationProperties();
execution = new ExecutionProperties();
this(false);
}

protected ProfileProperties(Boolean setDefaults) {
if (setDefaults) {
encoderOptions = new DefaultEncoderOptionsProperties();
preparation = new DefaultPreparationProperties();
execution = new DefaultExecutionProperties();
} else {
encoderOptions = new EncoderOptionsProperties();
preparation = new PreparationProperties();
execution = new ExecutionProperties();
}
}

@JsonSetter("encoder_options")
public void setEncoderOptions(EncoderOptionsProperties encoderOptions) {
if (encoderOptions != null) {
// TODO if null apply default values as is
// TODO after deserialization apply the profile_default values -> maybe move setter to getter logic
// TODO add getgraphpath override to the profile property classes
this.encoderOptions = encoderOptions;
}


public EncoderOptionsProperties getEncoderOptions(Boolean mergeWithDefault) {
if (mergeWithDefault) {
DefaultEncoderOptionsProperties defaultEncoderOptionsProperties = new DefaultEncoderOptionsProperties(this.getEncoderName());
encoderOptions = (EncoderOptionsProperties) PropertyUtils.deepCopyObjectsProperties(defaultEncoderOptionsProperties, encoderOptions, false, false);
if (this.encoderOptions == null) {
return defaultEncoderOptionsProperties;
}
EncoderOptionsProperties test = (EncoderOptionsProperties) PropertyUtils.deepCopyObjectsProperties(defaultEncoderOptionsProperties, this.encoderOptions, false, false);
return test;
}
this.encoderOptions = encoderOptions;
return this.encoderOptions;
}

@JsonSetter("preparation")
public void setPreparation(PreparationProperties preparation) {
if (preparation != null) {
this.preparation = preparation;
}

public PreparationProperties getPreparation(Boolean mergeWithDefault) {
if (mergeWithDefault) {
DefaultPreparationProperties defaultPreparationProperties = new DefaultPreparationProperties(this.getEncoderName());
preparation = (PreparationProperties) PropertyUtils.deepCopyObjectsProperties(defaultPreparationProperties, preparation, false, false);
if (this.preparation == null) {
return defaultPreparationProperties;
}
PreparationProperties test = (PreparationProperties) PropertyUtils.deepCopyObjectsProperties(defaultPreparationProperties, this.preparation, false, false);
return test;
}
this.preparation = preparation;
return this.preparation;
}

@JsonSetter("execution")
public void setExecution(ExecutionProperties execution) {
if (execution != null) {
this.execution = execution;
}

public ExecutionProperties getExecution(Boolean mergeWithDefault) {
if (mergeWithDefault) {
DefaultExecutionProperties defaultExecutionProperties = new DefaultExecutionProperties(this.getEncoderName());
execution = (ExecutionProperties) PropertyUtils.deepCopyObjectsProperties(defaultExecutionProperties, execution, false, false);
if (this.execution == null) {
return defaultExecutionProperties;
}
ExecutionProperties test = (ExecutionProperties) PropertyUtils.deepCopyObjectsProperties(defaultExecutionProperties, this.execution, false, false);
return test;
}
this.execution = execution;
return this.execution;
}

@JsonSetter("ext_storages")
public void setExtStorages(Map<String, ExtendedStorage> extStorages) {
if (extStorages == null) {
this.extStorages = new HashMap<>();
} else {
this.extStorages = extStorages;
}

public Map<String, ExtendedStorage> getExtStorages(Boolean mergeWithDefault) {
if (mergeWithDefault) {
DefaultExtendedStoragesProperties defaultExtendedStoragesProperties = new DefaultExtendedStoragesProperties(this.getEncoderName());
extStorages = PropertyUtils.deepCopyMapsProperties(defaultExtendedStoragesProperties.getExtStorages(), extStorages, false, false, false);
if (extStorages != null) {
this.extStorages = extStorages;
if (this.extStorages == null) {
return defaultExtendedStoragesProperties.getExtStorages();
}
Map<String, ExtendedStorage> test = PropertyUtils.deepCopyMapsProperties(defaultExtendedStoragesProperties.getExtStorages(), this.extStorages, false, false, false);
return test;
}
return this.extStorages;
}

@JsonIgnore
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.heigit.ors.config.profile.defaults;

import org.heigit.ors.common.DataAccessEnum;
import org.heigit.ors.config.ElevationProperties;

import java.nio.file.Paths;

public class DefaultElevationProperties extends ElevationProperties {

public DefaultElevationProperties() {
this(false);
}

public DefaultElevationProperties(Boolean setDefaults) {
if (setDefaults) {
setPreprocessed(false);
setDataAccess(DataAccessEnum.MMAP);
setCacheClear(false);
setProvider("multi");
setCachePath(Paths.get("./elevation_cache"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,52 @@
import org.heigit.ors.config.profile.EncoderOptionsProperties;

public class DefaultEncoderOptionsProperties extends EncoderOptionsProperties {
public DefaultEncoderOptionsProperties() {
setBlockFords(false);
setTurnCosts(true);
setConsiderElevation(false);
setUseAcceleration(false);
setConditionalAccess(false); // Default from EncodingManager.java

setMaximumGradeLevel(null); // TODO find default
setPreferredSpeedFactor(null); // TODO find default
setProblematicSpeedFactor(null); // TODO find default
setConditionalSpeed(false); // TODO find default
public DefaultEncoderOptionsProperties() {
this(false, null);
}

public DefaultEncoderOptionsProperties(EncoderNameEnum encoderName) {
this();
if (encoderName == null) {
encoderName = EncoderNameEnum.UNKNOWN;
public DefaultEncoderOptionsProperties(Boolean setDefaults, EncoderNameEnum encoderName) {
this(encoderName);
if (setDefaults) {
setBlockFords(false);
setTurnCosts(true);
setConsiderElevation(false);
setUseAcceleration(false);
setConditionalAccess(false); // Default from EncodingManager.java
setMaximumGradeLevel(null); // TODO find default
setPreferredSpeedFactor(null); // TODO find default
setProblematicSpeedFactor(null); // TODO find default
setConditionalSpeed(false); // TODO find default
}
}

switch (encoderName) {
case DRIVING_CAR -> {
// Just set the ones from below
setTurnCosts(true);
setBlockFords(false);
setUseAcceleration(true);
setConsiderElevation(false);
}
case DRIVING_HGV -> {
setTurnCosts(true);
setBlockFords(false);
setUseAcceleration(true);
}
case CYCLING_REGULAR, CYCLING_MOUNTAIN, CYCLING_ROAD, CYCLING_ELECTRIC -> {
setConsiderElevation(true);
setTurnCosts(true);
setBlockFords(false);
}
case FOOT_HIKING, FOOT_WALKING, WHEELCHAIR, PUBLIC_TRANSPORT -> // Just set the ones from below
public DefaultEncoderOptionsProperties(EncoderNameEnum encoderName) {
if (encoderName != null) {
switch (encoderName) {
case DRIVING_CAR -> {
// Just set the ones from below
setTurnCosts(true);
setBlockFords(false);
setUseAcceleration(true);
setConsiderElevation(false);
}
case DRIVING_HGV -> {
setTurnCosts(true);
setBlockFords(false);
default -> {
setUseAcceleration(true);
}
case CYCLING_REGULAR, CYCLING_MOUNTAIN, CYCLING_ROAD, CYCLING_ELECTRIC -> {
setConsiderElevation(true);
setTurnCosts(true);
setBlockFords(false);
}
case FOOT_HIKING, FOOT_WALKING, WHEELCHAIR, PUBLIC_TRANSPORT -> // Just set the ones from below
setBlockFords(false);
default -> {
}
}
}

}
}
Loading

0 comments on commit 476d1ad

Please sign in to comment.