|
|
@@ -3,7 +3,7 @@ package com.yunfeiyun.agmp.iot.common.util.dev;
|
|
|
import com.yunfeiyun.agmp.iot.common.util.BigDecimalUtil;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.util.HashMap;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
import java.util.Map;
|
|
|
|
|
|
public class WindUtil {
|
|
|
@@ -13,9 +13,31 @@ public class WindUtil {
|
|
|
* @param windDirection 风向
|
|
|
* @return 风向
|
|
|
*/
|
|
|
-// public static String getWindDirection(String windDirection) {
|
|
|
-//
|
|
|
-// }
|
|
|
+ public static String getWindDirection(String windDirection) {
|
|
|
+ Map<String, String> directionNameMap = new LinkedHashMap<>();
|
|
|
+ directionNameMap.put("22.25", "北风");
|
|
|
+ directionNameMap.put("67.5", "东北风");
|
|
|
+ directionNameMap.put("112.5", "东风");
|
|
|
+ directionNameMap.put("157.5", "东南风");
|
|
|
+ directionNameMap.put("202.5", "南风");
|
|
|
+ directionNameMap.put("247.5", "西南风");
|
|
|
+ directionNameMap.put("292.5", "西风");
|
|
|
+ directionNameMap.put("337.5", "西北风");
|
|
|
+ directionNameMap.put("360", "北风");
|
|
|
+ String directionName = "未知";
|
|
|
+ try{
|
|
|
+ BigDecimal standValue = BigDecimalUtil.format(windDirection, scale);
|
|
|
+ for(Map.Entry<String, String> entry : directionNameMap.entrySet()) {
|
|
|
+ if (standValue.compareTo(BigDecimalUtil.format(entry.getKey(), scale)) <= 0) {
|
|
|
+ directionName = entry.getValue();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }catch (Exception e){
|
|
|
+
|
|
|
+ }
|
|
|
+ return directionName;
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 获取风速
|
|
|
@@ -23,24 +45,7 @@ public class WindUtil {
|
|
|
* @return 风速
|
|
|
*/
|
|
|
public static String getWindSpeed(String windSpeed) {
|
|
|
-
|
|
|
- String[] speedArray = {
|
|
|
- "0.2",
|
|
|
- "1.5",
|
|
|
- "3.3",
|
|
|
- "5.4",
|
|
|
- "7.9",
|
|
|
- "10.7",
|
|
|
- "13.8",
|
|
|
- "17.1",
|
|
|
- "20.7",
|
|
|
- "24.4",
|
|
|
- "28.4",
|
|
|
- "32.6",
|
|
|
- "36.9",
|
|
|
- };
|
|
|
-
|
|
|
- Map<String, String> speedNameMap = new HashMap<>();
|
|
|
+ Map<String, String> speedNameMap = new LinkedHashMap<>();
|
|
|
speedNameMap.put("0.2", "0级 无风");
|
|
|
speedNameMap.put("1.5", "1级 软风");
|
|
|
speedNameMap.put("3.3", "2级 轻风");
|
|
|
@@ -57,10 +62,10 @@ public class WindUtil {
|
|
|
|
|
|
String speedName = "未知";
|
|
|
try{
|
|
|
- BigDecimal speed = BigDecimalUtil.format(windSpeed, scale);
|
|
|
- for (String s : speedArray) {
|
|
|
- if (speed.compareTo(BigDecimalUtil.format(s, scale)) <= 0) {
|
|
|
- speedName = speedNameMap.getOrDefault(s, "未知");
|
|
|
+ BigDecimal standValue = BigDecimalUtil.format(windSpeed, scale);
|
|
|
+ for(Map.Entry<String, String> entry : speedNameMap.entrySet()) {
|
|
|
+ if (standValue.compareTo(BigDecimalUtil.format(entry.getKey(), scale)) <= 0) {
|
|
|
+ speedName = entry.getValue();
|
|
|
break;
|
|
|
}
|
|
|
}
|