| | |
| | | package com.iailab.module.model.mcs.pre.enums; |
| | | |
| | | import com.iailab.module.data.api.point.dto.ApiPointValueDTO; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Getter; |
| | | |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.function.Function; |
| | | |
| | | /** |
| | |
| | | @AllArgsConstructor |
| | | public enum AutoAdjustValueRuleEnum { |
| | | |
| | | // 均值差 |
| | | AVERAGE_GAP_VALUE("average_gap_value",(map) -> { |
| | | if (!map.containsKey("startValue") || !map.containsKey("endValue")) { |
| | | return 0.0; |
| | | // 流量累计 |
| | | FLOW_RATE_ACCUMULATION("flow_rate_accumulation",(apiPointValues) -> { |
| | | // 基准值 |
| | | double refValue = apiPointValues.get(0).getV(); |
| | | double adjustValue = 0.0; |
| | | for (ApiPointValueDTO pointValue : apiPointValues) { |
| | | adjustValue += pointValue.getV() - refValue; |
| | | } |
| | | Double startValue = Double.valueOf(map.get("startValue").toString()); |
| | | Double endValue = Double.valueOf(map.get("endValue").toString()); |
| | | return endValue - startValue; |
| | | return adjustValue / 60; |
| | | }); |
| | | |
| | | |
| | | private final String code; |
| | | private final Function<HashMap<String,Object>, Double> calculator; |
| | | private final Function<List<ApiPointValueDTO>, Double> calculator; |
| | | |
| | | public Double calculate(HashMap<String,Object> map) { |
| | | return calculator.apply(map); |
| | | public Double calculate(List<ApiPointValueDTO> apiPointValues) { |
| | | return calculator.apply(apiPointValues); |
| | | } |
| | | |
| | | public static AutoAdjustValueRuleEnum fromCode(String code) { |
| | |
| | | return null; |
| | | } |
| | | |
| | | public static Double getAdjustValue(String code,HashMap<String,Object> map) { |
| | | public static Double getAdjustValue(String code, List<ApiPointValueDTO> apiPointValues) { |
| | | |
| | | AutoAdjustValueRuleEnum rule = AutoAdjustValueRuleEnum.fromCode(code); |
| | | |
| | | if (rule == null) { |
| | | return 0.0; |
| | | } |
| | | return rule.calculate(map); |
| | | return rule.calculate(apiPointValues); |
| | | } |
| | | } |