From b8a05e777e760e1937258544da1494b2d93055d0 Mon Sep 17 00:00:00 2001
From: lizijie <lzjiiie@163.com>
Date: Thu, 17 Dec 2020 15:51:06 +0800
Subject: [PATCH] UV风向工具类修改,根据时间段获取五分钟数据
---
src/main/resources/mapper/HistoryFiveMinutelyMapper.xml | 15 +++++++
src/main/java/com/moral/service/impl/HistoryFiveMinutelyServiceImpl.java | 6 +++
src/main/java/com/moral/util/WindUtils.java | 58 +++++++++++++++++++----------
src/main/java/com/moral/service/HistoryFiveMinutelyService.java | 2 +
src/main/java/com/moral/controller/ScreenController.java | 36 +++++++++++++++---
5 files changed, 91 insertions(+), 26 deletions(-)
diff --git a/src/main/java/com/moral/controller/ScreenController.java b/src/main/java/com/moral/controller/ScreenController.java
index a617066..3f68ae4 100644
--- a/src/main/java/com/moral/controller/ScreenController.java
+++ b/src/main/java/com/moral/controller/ScreenController.java
@@ -3013,6 +3013,7 @@
@ApiImplicitParams(value = {
@ApiImplicitParam(name = "monitorPointId", value = "������Id", required = true, paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "sensorKey", value = "������", required = true, paramType = "query", dataType = "String"),
+ @ApiImplicitParam(name = "realTime", value = "������", required = true, paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "accountId", value = "������id", required = false, paramType = "query", dataType = "String")})
public ModelAndView unorganizedEmissionsBackupsV2(HttpServletRequest request, ModelAndView model) {
Map<String, Object> parameters = WebUtils.getParametersStartingWith(request, null);
@@ -3023,9 +3024,18 @@
List<Device> deviceList = deviceService.getDevicesByMonitorPointId(539);
//���������������������
Map<String,Object> pa = new HashMap<>();
+ //���������������������������������
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ Calendar beforeTime = Calendar.getInstance();
+ Date newTime = beforeTime.getTime();
+ beforeTime.add(Calendar.MINUTE,-5);
+ Date startTime = beforeTime.getTime();
+ beforeTime.add(Calendar.MINUTE,6);
+ Date endTime = beforeTime.getTime();
//pa.put("sensorKey","e1");
- pa.put("yearAndMonth","202012");
- pa.put("time","2020-12-03 10:10:00");
+ pa.put("yearAndMonth",sdf.format(newTime).substring(0,7).replace("-",""));
+ pa.put("startTime",startTime);
+ pa.put("endTime",endTime);
List<String> macs = new ArrayList<>();
List<String> sensorKeys = new ArrayList<>();
for (Device device:deviceList) {
@@ -3036,7 +3046,8 @@
sensorKeys.add("e23");
pa.put("macs",macs);
pa.put("sensorKeys",sensorKeys);
- List<Map<String, Object>> fiveMinuteDataList = historyFiveMinutelyService.getFiveMinutesSersorDataByMacsAndTime(pa);
+ pa.put("macNumber",macs.size());
+ List<Map<String, Object>> fiveMinuteDataList = historyFiveMinutelyService.getFiveMinutesDataByMacsAndTimeSolt(pa);
//������������������������������������������
double[] allDeviceData = new double[fiveMinuteDataList.size()];
System.out.println(fiveMinuteDataList);
@@ -3045,6 +3056,9 @@
List<Map<String,Object>> windList = new ArrayList<>();
for (Map map:fiveMinuteDataList) {
String[] wind_speed = map.get("e18").toString().split(",");
+ if (!map.containsKey("e23")){
+ continue;
+ }
String[] wind_direction = map.get("e23").toString().split(",");
Map<String,Object> windMap = new HashMap<>();
windMap.put("wind_speed",wind_speed[0].substring(1,wind_speed[0].length()));
@@ -3056,7 +3070,9 @@
i = i+1;
}
//���������������������������
+ System.out.println("windList:"+windList);
Map<String,Double> res = WindUtils.getWind_direction_speed(windList);
+ System.out.println("res:"+res);
//���������������������������������������������
Map<String,Double> angleMap = new HashMap();
MyLatLng pollutionSourcePoint_log_lat = new MyLatLng(pollutionSourcePoint.getLongitude(),pollutionSourcePoint.getLatitude());
@@ -3110,15 +3126,23 @@
double deviceDataAvg = sum/allDeviceData.length;
//���������������������������������������������
double distance = mapUtils.getDistance(pollutionSourcePoint.getLongitude(),pollutionSourcePoint.getLatitude(),referenceDevice.getLongitude(),referenceDevice.getLatitude());
+ System.out.println("distance:"+distance);
//���������������������������x,y
- double x = Math.cos(minDisparity.get().getValue())*distance;
- double y = Math.sin(minDisparity.get().getValue())*distance;
+ System.out.println(minDisparity.get().getValue());
+ double x = Math.cos(Math.toRadians(minDisparity.get().getValue()))*distance;
+ System.out.println("���������������"+Math.cos(minDisparity.get().getValue()));
+ System.out.println(x);
+ double y = Math.sin(Math.toRadians(minDisparity.get().getValue()))*distance;
//���������������������
- String[] fiveMinuteData = fiveMinuteDataMap.get("e21").toString().split(",");
+ String[] fiveMinuteData = fiveMinuteDataMap.get(sensorKey).toString().split(",");
double c = Double.parseDouble(fiveMinuteData[0].substring(1,fiveMinuteData[0].length()))-deviceDataAvg;
System.out.println(c);
//������������
double pollutionSourceIntensity = EmissionDataUtil.getPollutionSourceIntensity(c,x,y,res.get("wind_speed"));
+ System.out.println("c���"+c);
+ System.out.println("x���"+x);
+ System.out.println("y���"+y);
+ System.out.println("���������"+res.get("wind_speed"));
System.out.println(pollutionSourceIntensity);
//���������������������
diff --git a/src/main/java/com/moral/service/HistoryFiveMinutelyService.java b/src/main/java/com/moral/service/HistoryFiveMinutelyService.java
index 21972b8..78456b7 100644
--- a/src/main/java/com/moral/service/HistoryFiveMinutelyService.java
+++ b/src/main/java/com/moral/service/HistoryFiveMinutelyService.java
@@ -9,4 +9,6 @@
Map<String,Object> getFiveMinutesDataByMac(Map<String, Object> parameters);
List<Map<String, Object>> getFiveMinutesSersorDataByMacsAndTime(Map<String,Object> parameters);
+
+ List<Map<String, Object>> getFiveMinutesDataByMacsAndTimeSolt(Map<String,Object> parameters);
}
diff --git a/src/main/java/com/moral/service/impl/HistoryFiveMinutelyServiceImpl.java b/src/main/java/com/moral/service/impl/HistoryFiveMinutelyServiceImpl.java
index b2dc382..156b8ba 100644
--- a/src/main/java/com/moral/service/impl/HistoryFiveMinutelyServiceImpl.java
+++ b/src/main/java/com/moral/service/impl/HistoryFiveMinutelyServiceImpl.java
@@ -32,5 +32,11 @@
return historyFiveMinutelyMapper.getFiveMinutesSersorDataByMacsAndTime(parameters);
}
+ @Override
+ public List<Map<String, Object>> getFiveMinutesDataByMacsAndTimeSolt(Map<String, Object> parameters) {
+ ValidateUtil.notNull(parameters,"���������������������������������");
+ return historyFiveMinutelyMapper.getFiveMinutesDataByMacsAndTimeSolt(parameters);
+ }
+
}
diff --git a/src/main/java/com/moral/util/WindUtils.java b/src/main/java/com/moral/util/WindUtils.java
index 01d7073..80de618 100644
--- a/src/main/java/com/moral/util/WindUtils.java
+++ b/src/main/java/com/moral/util/WindUtils.java
@@ -1,5 +1,6 @@
package com.moral.util;
+import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -29,26 +30,26 @@
u1 = 0;
v1 = wind_speed*1;
}else if (0<wind_direction&&wind_direction<90){
- u1 = wind_speed*Math.sin(wind_direction);
- v1 = wind_speed*Math.cos(wind_direction);
+ u1 = wind_speed*Math.sin(Math.toRadians(wind_direction));
+ v1 = wind_speed*Math.cos(Math.toRadians(wind_direction));
}else if (wind_direction == 90){
u1 = wind_speed*1;
v1 = 0;
}else if (90<wind_direction&&wind_direction<180){
- u1 = wind_speed*Math.sin(180-wind_direction);
- v1 = -1*wind_speed*Math.cos(180-wind_direction);
+ u1 = wind_speed*Math.sin(Math.toRadians(180-wind_direction));
+ v1 = -1*wind_speed*Math.cos(Math.toRadians(180-wind_direction));
}else if (wind_direction == 180){
u1 = 0;
v1 = wind_speed*-1;
}else if (180<wind_direction&&wind_direction<270){
- u1 = -1*wind_speed*Math.sin(wind_direction-180);
- v1 = -1*wind_speed*Math.cos(wind_direction-180);
+ u1 = -1*wind_speed*Math.sin(Math.toRadians(wind_direction-180));
+ v1 = -1*wind_speed*Math.cos(Math.toRadians(wind_direction-180));
}else if (wind_direction == 270){
u1 = wind_speed*-1;
v1 = 0;
}else if (270<wind_direction&&wind_direction<360){
- u1 = wind_speed*Math.sin(360-wind_direction);
- v1 = -1*wind_speed*Math.cos(360-wind_direction);
+ u1 = wind_speed*Math.sin(Math.toRadians(360-wind_direction));
+ v1 = -1*wind_speed*Math.cos(Math.toRadians(360-wind_direction));
}
u = u+u1;
v = v+v1;
@@ -59,30 +60,47 @@
windDirectionSpeedMap.put("wind_speed",0.0);
}else if (u==0&&v>0){
windDirectionSpeedMap.put("wind_direction",0.0);
- windDirectionSpeedMap.put("wind_speed",v);
+ windDirectionSpeedMap.put("wind_speed",v/list.size());
}else if (u>0&&v>0){
- windDirectionSpeedMap.put("wind_direction",Math.atan2(u,v));
- windDirectionSpeedMap.put("wind_speed",Math.sqrt(u*u+v*v));
+ windDirectionSpeedMap.put("wind_direction",Math.toDegrees(Math.atan2(u,v)));
+ windDirectionSpeedMap.put("wind_speed",Math.sqrt(u*u+v*v)/list.size());
}else if (u>0&&v==0){
windDirectionSpeedMap.put("wind_direction",90.0);
- windDirectionSpeedMap.put("wind_speed",u);
+ windDirectionSpeedMap.put("wind_speed",u/list.size());
}else if (u>0&&v<0){
- windDirectionSpeedMap.put("wind_direction",Math.atan2(-v,u)+90);
- windDirectionSpeedMap.put("wind_speed",Math.sqrt(u*u+v*v));
+ windDirectionSpeedMap.put("wind_direction",Math.toDegrees(Math.atan2(-v,u))+90);
+ windDirectionSpeedMap.put("wind_speed",Math.sqrt(u*u+v*v)/list.size());
}else if (u==0&&v<0){
windDirectionSpeedMap.put("wind_direction",180.0);
- windDirectionSpeedMap.put("wind_speed",-v);
+ windDirectionSpeedMap.put("wind_speed",Math.abs(v)/list.size());
}else if (u<0&&v<0){
- windDirectionSpeedMap.put("wind_direction",Math.atan2(-u,-v)+180);
- windDirectionSpeedMap.put("wind_speed",Math.sqrt(u*u+v*v));
+ windDirectionSpeedMap.put("wind_direction",Math.toDegrees(Math.atan2(-u,-v))+180);
+ windDirectionSpeedMap.put("wind_speed",Math.sqrt(u*u+v*v)/list.size());
}else if (u<0&&v==0){
windDirectionSpeedMap.put("wind_direction",270.0);
- windDirectionSpeedMap.put("wind_speed",-u);
+ windDirectionSpeedMap.put("wind_speed",Math.abs(u)/list.size());
}else if (u<0&&v>0){
- windDirectionSpeedMap.put("wind_direction",Math.atan2(v,-u)+270);
- windDirectionSpeedMap.put("wind_speed",Math.sqrt(u*u+v*v));
+ windDirectionSpeedMap.put("wind_direction",Math.toDegrees(Math.atan2(v,-u))+270);
+ windDirectionSpeedMap.put("wind_speed",Math.sqrt(u*u+v*v)/list.size());
}
return windDirectionSpeedMap;
}
+ /*public static void main(String[] args) {
+ List list = new ArrayList();
+ Map map = new HashMap();
+ Map map2 = new HashMap();
+ map.put("wind_direction",45);
+ map.put("wind_speed",1);
+ map2.put("wind_direction",45);
+ map2.put("wind_speed",1);
+ list.add(map);
+ list.add(map2);
+ Map<String, Double> re = getWind_direction_speed(list);
+ System.out.println(re);
+ System.out.println(Math.toRadians(45));
+ System.out.println(Math.sin(Math.toRadians(45)));
+ System.out.println(Math.cos(Math.toRadians(45)));
+ }*/
+
}
diff --git a/src/main/resources/mapper/HistoryFiveMinutelyMapper.xml b/src/main/resources/mapper/HistoryFiveMinutelyMapper.xml
index 642d314..1c6c1fb 100644
--- a/src/main/resources/mapper/HistoryFiveMinutelyMapper.xml
+++ b/src/main/resources/mapper/HistoryFiveMinutelyMapper.xml
@@ -32,4 +32,19 @@
#{mac}
</foreach>
</select>
+
+ <select id="getFiveMinutesDataByMacsAndTimeSolt" resultType="map">
+ select h.mac,h.time,
+ <foreach collection="sensorKeys" separator="," item="sensorKey">
+ json->'$.${sensorKey}' AS '${sensorKey}'
+ </foreach>
+ FROM history_five_minutely_${yearAndMonth} h
+ WHERE mac IN
+ <foreach collection="macs" separator="," open="(" close=")" item="mac">
+ #{mac}
+ </foreach>
+ AND time BETWEEN #{startTime} AND #{endTime}
+ ORDER BY h.time DESC
+ LIMIT #{macNumber}
+ </select>
</mapper>
\ No newline at end of file
--
Gitblit v1.8.0