Skip to content

Commit

Permalink
#1: Threshold implementation for Flood
Browse files Browse the repository at this point in the history
  • Loading branch information
gowthamnvv committed Oct 3, 2021
1 parent 1ae5802 commit cd2ab45
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*******************************************************************************/
package edu.illinois.ncsa.incore.service.hazard.models.flood;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import dev.morphia.annotations.Embedded;
Expand All @@ -20,6 +21,7 @@ public abstract class FloodHazardDataset {
private String datasetId;
private String demandType;
private String demandUnits;
private Double threshold = null;

public String getDatasetId() {
return datasetId;
Expand All @@ -44,4 +46,18 @@ public String getDemandUnits() {
public void setDemandUnits(String demandUnits) {
this.demandUnits = demandUnits;
}

public Double getThreshold() {
return threshold;
}

public void setThreshold(Double threshold) {
this.threshold = threshold;
}

@JsonIgnore
public String getThresholdJsonString(){
return String.format("{'%s': {'value': %s, 'unit': '%s'}}",
this.demandType, this.threshold, this.demandUnits);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@ public static FloodHazardResult getFloodHazardValue(Flood flood, String demandTy
try {
if (hazardValue != null) {
hazardValue = FloodUtil.convertHazard(hazardValue, demandType, hazardDataset.getDemandUnits(), demandUnits);

// convert demand type in keys to lower case
JSONObject floodThresholds = HazardUtil.toLowerKey(HazardUtil.FLOOD_THRESHOLDS);
JSONObject floodThresholds;
if (hazardDataset.getThreshold() != null){
floodThresholds = HazardUtil.toLowerKey(new JSONObject(hazardDataset.getThresholdJsonString()));
} else {
floodThresholds = HazardUtil.toLowerKey(HazardUtil.FLOOD_THRESHOLDS);
}

if (floodThresholds.has(demandType.toLowerCase())) {
JSONObject demandThreshold = ((JSONObject) floodThresholds.get(demandType.toLowerCase()));
Expand Down

0 comments on commit cd2ab45

Please sign in to comment.