lizijie
2020-12-17 b8a05e777e760e1937258544da1494b2d93055d0
UV风向工具类修改,根据时间段获取五分钟数据
5 files modified
117 ■■■■ changed files
src/main/java/com/moral/controller/ScreenController.java 36 ●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/HistoryFiveMinutelyService.java 2 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/service/impl/HistoryFiveMinutelyServiceImpl.java 6 ●●●●● patch | view | raw | blame | history
src/main/java/com/moral/util/WindUtils.java 58 ●●●●● patch | view | raw | blame | history
src/main/resources/mapper/HistoryFiveMinutelyMapper.xml 15 ●●●●● patch | view | raw | blame | history
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);
        //存放地图中心点
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);
}
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);
    }
}
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)));
    }*/
}
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>