From 88ae069fcf657c1790bb04b444e150c06f04e5f6 Mon Sep 17 00:00:00 2001 From: feiyu02 <risaku@163.com> Date: 星期四, 30 十二月 2021 11:50:46 +0800 Subject: [PATCH] 1. 网格化风向权重分析完善 --- src/main/kotlin/com/flightfeather/uav/lightshare/bean/QuadrantInfo.kt | 114 +++++++++ src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/EPWModelServiceImpl.kt | 181 ++++++++++++-- src/main/kotlin/com/flightfeather/uav/lightshare/bean/ElectricDailyInfo.kt | 120 ++++++++- src/main/kotlin/com/flightfeather/uav/common/utils/FileExchange.kt | 40 ++ src/main/kotlin/com/flightfeather/uav/lightshare/service/EPWModelService.kt | 10 src/main/kotlin/com/flightfeather/uav/model/epw/WindDirWeight.kt | 1 src/main/kotlin/com/flightfeather/uav/dataprocess/ElectricDailyAnalysis.kt | 37 ++ src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/ElectricityServiceImpl.kt | 173 +++++++++---- 8 files changed, 560 insertions(+), 116 deletions(-) diff --git a/src/main/kotlin/com/flightfeather/uav/common/utils/FileExchange.kt b/src/main/kotlin/com/flightfeather/uav/common/utils/FileExchange.kt index c6dd971..380b3dd 100644 --- a/src/main/kotlin/com/flightfeather/uav/common/utils/FileExchange.kt +++ b/src/main/kotlin/com/flightfeather/uav/common/utils/FileExchange.kt @@ -33,6 +33,8 @@ val dataList = mutableListOf<RealTimeData>() + val lastData = mutableListOf<Double>() + for (i in 1 until sheet.lastRowNum) { val row = sheet.getRow(i) val time = row.getCell(2).numericCellValue.toLong() * 1000 @@ -44,11 +46,27 @@ val datetime = Date(time) //鐩戞祴鍥犲瓙 val jO = JSONObject.parseObject(value) - val tmp = jO.getDoubleValue(TMP) - val spC = jO.getDoubleValue(SPCOND) - val tur = jO.getDoubleValue(TUR) - val dO = jO.getDoubleValue(DO) - val ph = jO.getDoubleValue(PH) + var tmp = jO.getDoubleValue(TMP) + var spC = jO.getDoubleValue(SPCOND) + var tur = jO.getDoubleValue(TUR) + var dO = jO.getDoubleValue(DO) + var ph = jO.getDoubleValue(PH) + + if (lastData.isEmpty()) { + lastData.addAll(listOf(tmp, spC, tur, dO, ph)) + } else { + if (tmp == .0) tmp = lastData[0] + if (spC == .0) spC = lastData[1] + if (tur == .0) tur = lastData[2] + if (dO == .0) dO = lastData[3] + if (ph == .0) ph = lastData[4] + } + + lastData[0] = tmp + lastData[1] = spC + lastData[2] = tur + lastData[3] = dO + lastData[4] = ph val factorsList = mutableListOf<AirData>() @@ -83,6 +101,18 @@ factorData = ph physicalQuantity = 0.0 }) + add(AirData().apply { + factorId = "12" + factorName = "LNG" + factorData = lng + physicalQuantity = 0.0 + }) + add(AirData().apply { + factorId = "13" + factorName = "LAT" + factorData = lat + physicalQuantity = 0.0 + }) } val factors = JSONObject.toJSON(factorsList).toString() diff --git a/src/main/kotlin/com/flightfeather/uav/dataprocess/ElectricDailyAnalysis.kt b/src/main/kotlin/com/flightfeather/uav/dataprocess/ElectricDailyAnalysis.kt index a611d97..e6e9ebc 100644 --- a/src/main/kotlin/com/flightfeather/uav/dataprocess/ElectricDailyAnalysis.kt +++ b/src/main/kotlin/com/flightfeather/uav/dataprocess/ElectricDailyAnalysis.kt @@ -19,11 +19,11 @@ // 杩斿洖缁撴灉 val result = mutableListOf<ElectricDailyInfo>() // 姣忔棩缁熻淇℃伅 - val dailyInfoMap = mutableMapOf<String, ElectricDailyInfo>() + val dailyInfoMap = mutableMapOf<Int, ElectricDailyInfo>() // 1.鏁版嵁鍑嗗 val deviceMap = mutableMapOf<String, CompanyDevice>() - val dataMap = mutableMapOf<String, MutableMap<String, MutableList<ElectricMinuteValue>>>() + val dataMap = mutableMapOf<String, MutableMap<Int, MutableList<ElectricMinuteValue>>>() deviceList.forEach { // 鐩戞祴鏁版嵁 if (!dataMap.containsKey(it.cdDeviceCode)) { @@ -35,7 +35,8 @@ // 2.杞鏁版嵁锛岀粺璁℃瘡鏃ョ殑鍚勯」鐗瑰緛 dataList.forEach { // 鑾峰彇鏃ユ湡 - val day = DateUtil.instance.dateToString(it.mvDataTime, DateUtil.DateStyle.YYYY_MM_DD) ?: "" + val date = DateUtil.instance.dateToString(it.mvDataTime, DateUtil.DateStyle.YYYYMMDD) ?: "" + val day = date.toIntOrNull() ?: 0 // 姣忔棩瀵瑰簲涓�缁勬暟鎹� if (dataMap[it.mvStatCode]?.containsKey(day) != true) dataMap[it.mvStatCode]?.put(day, mutableListOf()) val dayList = dataMap[it.mvStatCode]?.get(day)!! @@ -47,7 +48,8 @@ // 2.1 鏍规嵁鏁版嵁鍒囨崲褰撳墠璁惧绫诲瀷 if (!dailyInfoMap.containsKey(day)) dailyInfoMap[day] = ElectricDailyInfo() val dayResult = dailyInfoMap[day]!! - dayResult.day = day + dayResult.day = DateUtil.instance.dateToString(it.mvDataTime, DateUtil.DateStyle.YYYY_MM_DD) ?: "" + dayResult.dayIndex = day dayResult.changeType(device) // 2.2 姣忔棩鑾峰彇鐨勯涓暟鎹紝鍗充负褰撴棩璇ヨ澶囧紑鍚椂闂� if (dayList.size == 1) dayResult.setStartTime(it.mvDataTime) @@ -58,18 +60,41 @@ // 2.5 缁熻褰撴棩璁惧杩愯鏃舵锛堝皬鏃讹級 val hour = LocalDateTime.ofInstant(it.mvDataTime.toInstant(), ZoneId.systemDefault()).hour dayResult.addRunPeriod(hour) + // 2.6 绱鐢ㄧ數閲� + dayResult.addPower(it) + // 2.7 璁惧棣栨浠庤繍琛屽彉涓哄緟鏈烘垨鍏抽棴鐘舵�佹椂锛岃涓烘槸璁惧鐨勫叧闂椂闂� + dayResult.setEndTime(status, it) } - // 2.6 缁熻鍚勫彴璁惧姣忔棩缁撴潫鏃堕棿鍙婂垎鏋愮粨鏋� + // 2.6 缁熻鍚勫彴璁惧鍒嗘瀽缁撴灉 dataMap.forEach { (dCode, dayMap) -> dayMap.forEach { (day, list) -> dailyInfoMap[day]?.apply { changeType(deviceMap[dCode]) - setEndTime(list.last().mvDataTime) + setEndTime2(list.last().mvDataTime) getResult() } } } dailyInfoMap.forEach { (_,v)-> result += v } + result.sortBy { it.dayIndex } + for (i in result.indices) { + if (i > 0) { + val last = result[i - 1] + val d = result[i] + + // 閽堝涓ょ璁惧锛屽綋鏄ㄥぉ鐨勮澶囨湭鍏抽棴锛屼笖浠婂ぉ鐨勫紑鍚椂闂翠负0鐐�0鍒嗗唴鏃讹紝璁や负璁惧璺ㄦ棩杩愯 + if (last.plETimeStr == null && d.plRTimeStr?.substring(11, 16) == "00:00") { + d.plRTimeStr = null + d.rTimeDiff = null + d.sResult = true + } + if (last.pfETimeStr == null && d.pfRTimeStr?.substring(11, 16) == "00:00") { + d.pfRTimeStr = null + d.rTimeDiff = null + d.sResult = true + } + } + } return result } diff --git a/src/main/kotlin/com/flightfeather/uav/lightshare/bean/ElectricDailyInfo.kt b/src/main/kotlin/com/flightfeather/uav/lightshare/bean/ElectricDailyInfo.kt index cf868ae..665551a 100644 --- a/src/main/kotlin/com/flightfeather/uav/lightshare/bean/ElectricDailyInfo.kt +++ b/src/main/kotlin/com/flightfeather/uav/lightshare/bean/ElectricDailyInfo.kt @@ -1,11 +1,13 @@ package com.flightfeather.uav.lightshare.bean +import com.flightfeather.uav.common.utils.DateUtil import com.flightfeather.uav.dataprocess.ElectricDailyAnalysis import com.flightfeather.uav.domain.entity.CompanyDevice import com.flightfeather.uav.domain.entity.ElectricMinuteValue import com.flightfeather.uav.lightshare.eunm.ElectricityStatus import com.flightfeather.uav.lightshare.eunm.ElectricityType import java.util.* +import kotlin.math.round /** * 鐢ㄧ數閲忔棩鍒嗘瀽缁撴灉 @@ -13,26 +15,33 @@ * Created by feiyu */ class ElectricDailyInfo { - var day: String = "" + var day = "" + var dayIndex = 0 /***********浜х嚎璁惧ProductionLine, pl************/ - private var plDCode: String? = null // 璁惧缂栧彿 + var plDCode: String? = null // 璁惧缂栧彿 private var plSTime: Date? = null // 寮�鍚椂闂� private var plRTime: Date? = null // 姝e紡杩愯鏃堕棿 private var plETime: Date? = null // 鍏抽棴鏃堕棿 - private var plRunTime: Int = 0 // 杩愯鏃堕暱锛堝垎閽燂級锛堢姸鎬佷负杩愯銆侀珮璐熻嵎鐨勬椂闀匡級 + var plRunTime: Int = 0 // 杩愯鏃堕暱锛堝垎閽燂級锛堢姸鎬佷负杩愯銆侀珮璐熻嵎鐨勬椂闀匡級 private var plRunPeriod = mutableListOf<Int>()// 杩愯鏃舵锛堝皬鏃讹級 + var plPower = .0 // 鐢ㄧ數閲忥紙鍗冪摝鏃讹級 /***********鍑�鍖栬澶嘝urify, pf********************/ - private var pfDCode: String? = null + var pfDCode: String? = null private var pfSTime: Date? = null private var pfRTime: Date? = null private var pfETime: Date? = null - private var pfRunTime: Int = 0 + var pfRunTime: Int = 0 private var pfRunPeriod = mutableListOf<Int>() + var pfPower = .0 - var rTimeDiff:Int = 0 //姝e紡杩愯鏃堕棿宸� + var plRTimeStr: String? = null + var plETimeStr: String? = null + var pfRTimeStr: String? = null + var pfETimeStr: String? = null + var rTimeDiff:Int? = 0 //姝e紡杩愯鏃堕棿宸� var sResult:Boolean = false //璁惧寮�鍚槸鍚﹀悎瑙� - var eTimeDiff: Int = 0 //鍏抽棴鏃堕棿宸� + var eTimeDiff: Int? = 0 //鍏抽棴鏃堕棿宸� var eResult: Boolean = false //璁惧鍏抽棴鏄惁鍚堣 var runningTimeDiff = 0 //杩愯鏃堕暱宸� var rResult:Boolean = false //杩愯杩囩▼鏄惁鍚堣 @@ -63,10 +72,62 @@ } } - fun setEndTime(date: Date) { + private var lastPlStatus = -2 // 涓婁釜鏃堕棿鐐圭殑浜х嚎璁惧鐘舵�� + private var plTag = false // true锛氬綋鏃ユ渶鍚庝竴鍒嗛挓鐨勬暟鎹緷鏃ф槸杩愯鐘舵�侊紝鏈叧闂骇绾胯澶� + private var lastPfStatus = -2 // 涓婁釜鏃堕棿鐐圭殑鍑�鍖栬澶囩姸鎬� + private var pfTag = false + fun setEndTime(s: Triple<String, String, Double>, e:ElectricMinuteValue?) { + val hourMinute = DateUtil.instance.dateToString(e?.mvDataTime, DateUtil.DateStyle.HH_MM) when (deviceType) { - ElectricityType.ProductionLine -> plETime = date - ElectricityType.Purify -> pfETime = date + ElectricityType.ProductionLine -> { + if (lastPlStatus == -1) { + return + } else if (lastPlStatus <= ElectricityStatus.A.value) { + lastPlStatus = s.first.toInt() + } else if (lastPlStatus >= ElectricityStatus.B.value) { + if (s.first.toInt() <= ElectricityStatus.A.value) { + plETime = e?.mvDataTime + lastPlStatus = -1 + } else { + if (hourMinute == "23:59") plTag = true + lastPlStatus = s.first.toInt() + } + } + } + ElectricityType.Purify -> { + if (lastPfStatus == -1) { + return + } else if (lastPfStatus <= ElectricityStatus.A.value) { + lastPfStatus = s.first.toInt() + } else if (lastPfStatus >= ElectricityStatus.B.value) { + if (s.first.toInt() <= ElectricityStatus.A.value) { + pfETime = e?.mvDataTime + lastPfStatus = -1 + } else { + if (hourMinute == "23:59") pfTag = true + lastPfStatus = s.first.toInt() + } + } + } + else -> Unit + } + } + + /** + * 濡傛灉璁惧鍏抽棴鏃舵槸鐩存帴浠庤繍琛岀姸鎬佹柇鐢碉紝鍒欏湪姝ゅ灏嗘渶鍚庝竴涓暟鎹殑鏃堕棿璁颁负鍏抽棴鏃堕棿 + */ + fun setEndTime2(date: Date) { + when (deviceType) { + ElectricityType.ProductionLine -> { + if (plETime == null && !plTag) { + plETime = date + } + } + ElectricityType.Purify -> { + if (pfETime == null && !pfTag) { + pfETime = date + } + } else -> Unit } } @@ -119,20 +180,49 @@ } /** + * 绱鐢ㄧ數閲� + */ + fun addPower(e: ElectricMinuteValue?) { + e?.let { + val avgElectric = (it.mvElectricityA + it.mvElectricityB + it.mvElectricityC) / 3 + val power = avgElectric * 1 / 60 + when (deviceType) { + ElectricityType.ProductionLine -> plPower += power + ElectricityType.Purify -> pfPower += power + else -> Unit + } + } + } + + /** * 缁熻寰楀嚭褰撴棩鍒嗘瀽缁撴灉 */ fun getResult() { - // TODO: 2021/12/1 1. 璁惧姝e紡杩愯鏃堕棿宸� =銆嬪紑鍚槸鍚﹀悎瑙� + // 鐢ㄧ數閲� + plPower = round(plPower * 100) / 100 + pfPower = round(pfPower * 100) / 100 + + // 寮�鍏虫椂闂存牸寮忓寲 + plRTimeStr = DateUtil.instance.dateToString(plRTime, DateUtil.DateStyle.YYYY_MM_DD_HH_MM_SS) + plETimeStr = DateUtil.instance.dateToString(plETime, DateUtil.DateStyle.YYYY_MM_DD_HH_MM_SS) + pfRTimeStr = DateUtil.instance.dateToString(pfRTime, DateUtil.DateStyle.YYYY_MM_DD_HH_MM_SS) + pfETimeStr = DateUtil.instance.dateToString(pfETime, DateUtil.DateStyle.YYYY_MM_DD_HH_MM_SS) + + // 1. 璁惧姝e紡杩愯鏃堕棿宸� =銆嬪紑鍚槸鍚﹀悎瑙� if (pfRTime != null && plRTime != null) { rTimeDiff = ((pfRTime!!.time - plRTime!!.time) / 1000 / 60).toInt() - sResult = rTimeDiff < 0 + sResult = rTimeDiff == null || rTimeDiff!! < 0 } - // TODO: 2021/12/1 2锛岃澶囧叧闂椂闂村樊 =銆嬪叧闂槸鍚﹀悎瑙� + // 2锛岃澶囧叧闂椂闂村樊 =銆嬪叧闂槸鍚﹀悎瑙� if (pfETime != null && plETime != null) { eTimeDiff = ((pfETime!!.time - plETime!!.time) / 1000 / 60).toInt() - eResult = eTimeDiff > 0 + eResult = eTimeDiff == null || eTimeDiff!! > 0 + } else { + // 褰撳叧闂椂闂村瓨鍦╪ull鏃讹紝璇存槑褰撴棩骞舵病鏈夊叧闂澶囷紝鍏抽棴鍚堣 + eTimeDiff = null + eResult = true } - // TODO: 2021/12/1 3. 杩愯鏃堕暱宸� =銆嬭繍琛岃繃绋嬫槸鍚﹀悎瑙� + // 3. 杩愯鏃堕暱宸� =銆嬭繍琛岃繃绋嬫槸鍚﹀悎瑙� runningTimeDiff = pfRunTime - plRunTime rResult = runningTimeDiff > 0 diff --git a/src/main/kotlin/com/flightfeather/uav/lightshare/bean/QuadrantInfo.kt b/src/main/kotlin/com/flightfeather/uav/lightshare/bean/QuadrantInfo.kt new file mode 100644 index 0000000..a868655 --- /dev/null +++ b/src/main/kotlin/com/flightfeather/uav/lightshare/bean/QuadrantInfo.kt @@ -0,0 +1,114 @@ +package com.flightfeather.uav.lightshare.bean + +import com.flightfeather.uav.common.utils.MapUtil +import kotlin.math.PI + +/** + * 缃戞牸鍖栨潈閲嶅垎鏋愯薄闄愬璞� + * 浠ョ洃娴嬬偣涓虹綉鏍肩嚎鐨勪腑蹇冪殑鍩虹涓婏紝鍚戝鎵╂暎鐨勬瘡涓�鍦堢綉鏍兼寜鐓у潗鏍囩郴鍒嗕负鍥涗釜璞¢檺 + * 姣忎釜璞¢檺涓殑缃戞牸鎸夌収瑙掍笂鐨勭綉鏍间綔涓哄垎鐣岋紝鍒嗘垚3閮ㄥ垎锛屽垎鍒湁涓嶅悓鐨勫悜澶栨墿鏁f満鍒� + */ +class QuadrantInfo{ + + val gridsHorizontal = mutableListOf<GridVo>() + val gridsCorner = mutableListOf<GridVo>() + val gridsVertical = mutableListOf<GridVo>() + + fun new(type: Quadrant, turns: Int, lng: Double, lat: Double, dx: Double, dy: Double) { + var plusMinusX = 1 // 缁忓害澧炲姞鎴栧噺灏� + var plusMinusY = 1 // 绾害澧炲姞鎴栧噺灏� + when (type) { + Quadrant.First -> { + plusMinusX = 1 + plusMinusY = 1 + } + Quadrant.Second -> { + plusMinusX = 1 + plusMinusY = -1 + } + Quadrant.Third -> { + plusMinusX = -1 + plusMinusY = -1 + } + Quadrant.Fourth -> { + plusMinusX = -1 + plusMinusY = 1 + } + } + // 瑙� + gridsCorner.add(GridVo("$turns-${type.value}-c").apply { + lb = Pair(lng + turns * dx * plusMinusX, lat + turns * dy * plusMinusY) + rt = Pair(lb!!.first + dx, lb!!.second + dy) + ciLongitude = (lb!!.first + dx / 2).toBigDecimal() + ciLatitude = (lb!!.second + dy / 2).toBigDecimal() + }) + // 姘村钩鏂瑰悜 + repeat(turns) { + gridsHorizontal.add(GridVo("$turns-${type.value}-l-$it").apply { + lb = Pair(lng + it * dx * plusMinusX, lat + turns * dy * plusMinusY) + rt = Pair(lb!!.first + dx, lb!!.second + dy) + ciLongitude = (lb!!.first + dx / 2).toBigDecimal() + ciLatitude = (lb!!.second + dy / 2).toBigDecimal() + }) + } + // 鍨傜洿鏂瑰悜 + repeat(turns) { + gridsVertical.add(GridVo("$turns-${type.value}-l-$it").apply { + lb = Pair(lng + turns * dx * plusMinusX, lat + it * dy * plusMinusY) + rt = Pair(lb!!.first + dx, lb!!.second + dy) + ciLongitude = (lb!!.first + dx / 2).toBigDecimal() + ciLatitude = (lb!!.second + dy / 2).toBigDecimal() + }) + } + } + + fun next() { + + } +} + +enum class Quadrant(val des: String, val value:Int){ + First("鍙充笂璞¢檺", 1), + Second("鍙充笅璞¢檺", 2), + Third("宸︿笅璞¢檺", 3), + Fourth("宸︿笂璞¢檺", 4), +} + +object GridFactory { + + // 鐩戞祴鐐瑰潗鏍� + private var lng = .0 + private var lat = .0 + private var dx = .0 + private var dy = .0 + + /** + * 璁剧疆鐩戞祴鐐瑰潗鏍� + */ + fun setCenter(lng: Double, lat: Double): GridFactory { + this.lng = lng + this.lat = lat + return this + } + + /** + * 璁剧疆缃戞牸闀垮害 + * @param len 缃戞牸闀垮害锛堢背锛� + */ + fun setGridLength(len: Double): GridFactory { + val center = Pair(lng, lat) + val p1 = MapUtil.getPointByLen(center, len, PI / 2)//姝d笢鏂瑰悜锛�90掳锛夌殑鍧愭爣鐐� + val p2 = MapUtil.getPointByLen(center, len, PI)//姝e崡鏂瑰悜锛�180掳锛夌殑鍧愭爣鐐� + this.dx = p1.first - center.first + this.dy = center.second - p2.second + return this + } + + /** + * 鏂板缓涓�鍦堢綉鏍� + * @param turns 鍦堟暟锛堜粠0寮�濮嬶級 + */ +// fun newGridsByTurns(turns: Int): List<QuadrantInfo> { +// +// } +} \ No newline at end of file diff --git a/src/main/kotlin/com/flightfeather/uav/lightshare/service/EPWModelService.kt b/src/main/kotlin/com/flightfeather/uav/lightshare/service/EPWModelService.kt index f05de7c..041686d 100644 --- a/src/main/kotlin/com/flightfeather/uav/lightshare/service/EPWModelService.kt +++ b/src/main/kotlin/com/flightfeather/uav/lightshare/service/EPWModelService.kt @@ -7,10 +7,18 @@ interface EPWModelService { /** - * 缃戞牸鍒嗘瀽鍒嗘瀽 + * 缃戞牸鍒嗘瀽 + * 鎸夌収鍥哄畾鐨勬�婚潰绉紝鏍规嵁缁欏畾鐨勭綉鏍艰竟闀匡紝鍔ㄦ�佺敓鎴愬搴旀暟閲忕殑缃戞牸 * @param type 鏁版嵁婧愮被鍨� @see [UWDeviceType], 0a,0b,0c,0d * @param len 缃戞牸闀垮害 */ fun getEpwModelResult(deviceCode: String, startTime: String, endTime: String, len: Double): BaseResponse<List<GridVo>> + /** + * 鍔ㄦ�佺綉鏍煎垎鏋� + * 鐩墠鍙拡瀵瑰畾鐐圭洃娴� + * 鍙嚜鍔ㄨ绠楀嚭鎵�鏈夌殑楂橀闄╁強涓闄╁尯鍩� + */ + fun getEpwModelResultDynamic(deviceCode: String, startTime: String, endTime: String, len: Double): BaseResponse<List<GridVo>> + } \ No newline at end of file diff --git a/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/EPWModelServiceImpl.kt b/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/EPWModelServiceImpl.kt index e18a148..494a8dc 100644 --- a/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/EPWModelServiceImpl.kt +++ b/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/EPWModelServiceImpl.kt @@ -3,20 +3,22 @@ import com.flightfeather.uav.common.GridLat import com.flightfeather.uav.common.GridLng import com.flightfeather.uav.common.utils.MapUtil -import com.flightfeather.uav.lightshare.bean.BaseResponse -import com.flightfeather.uav.lightshare.bean.GridVo +import com.flightfeather.uav.lightshare.bean.* import com.flightfeather.uav.lightshare.service.EPWModelService import com.flightfeather.uav.lightshare.service.RealTimeDataService import com.flightfeather.uav.model.epw.EPWGridModel -import com.flightfeather.uav.model.epw.EPWModel import com.flightfeather.uav.socket.eunm.UWDeviceType import org.springframework.stereotype.Service -import kotlin.math.PI +import kotlin.math.* @Service class EPWModelServiceImpl( private val realTimeDataService: RealTimeDataService, ) : EPWModelService { + + companion object { + private const val LEN = 3// 鏍规嵁椋庡悜缃戞牸鍚戝鎷撳睍鍦堟暟 + } val epwModel = EPWGridModel() @@ -34,6 +36,60 @@ if (gridType == 'f') return BaseResponse(false) val points = mutableListOf<GridVo>() + + // 鑾峰彇鍏ㄩ儴鏁版嵁璁$畻骞冲潎椋庡悜 + val dataList = mutableListOf<DataVo>() + var page = 1 + var totalPage = -1 + //椋庡悜閲囩敤鍗曚綅鐭㈤噺娉曟眰鍙栧潎鍊� + var u = .0//涓滆タ鏂逛綅鍒嗛噺鎬诲拰 + var v = .0//鍗楀寳鏂逛綅鍒嗛噺鎬诲拰 + var c = 0//椋庡悜鏁版嵁璁℃暟 + var windDirection = .0 // 骞冲潎椋庡悜瑙掑害 + while (totalPage == -1 || page <= totalPage) { + realTimeDataService.getSecondData(deviceCode, startTime, endTime, 0, page, 5000).apply { + if (totalPage == -1) { + totalPage = head?.totalPage ?: 0 + } + val list = data ?: emptyList() + + // FIXME: 2021/7/13 姝ゅ涓轰簡娴嬭瘯鏆傛椂灏嗙珯鐐圭粡绾害鍐欐锛屽悗缁�氳繃鏁版嵁搴撻厤缃幏鍙� + list.forEach { + if (it.lng == 0.0 && it.lat == 0.0) { + it.lng = GridLng + it.lat = GridLat + } + + val r = Math.toRadians(it.values?.get(16)?.factorData ?: .0) + u += sin(r) + v += cos(r) + c++ + } + + dataList.addAll(list) + page++ + } + } + + if (c != 0) { + val avgU = u / c + val avgV = v / c + var a = atan(avgU / avgV) + a = Math.toDegrees(a) + /** + * avgU>0;avgV>0: 鐪熷疄瑙掑害澶勪簬绗竴璞¢檺锛屼慨姝e�间负+0掳 + * avgU>0;avgV<0: 鐪熷疄瑙掑害澶勪簬绗簩璞¢檺锛屼慨姝e�间负+180掳 + * avgU<0;avgV<0: 鐪熷疄瑙掑害澶勪簬绗笁璞¢檺锛屼慨姝e�间负+180掳 + * avgU<0;avgV>0: 鐪熷疄瑙掑害澶勪簬绗洓璞¢檺锛屼慨姝e�间负+360掳 + */ + a += if (avgV > 0) { + if (avgU > 0) 0 else 360 + } else { + 180 + } + windDirection = a + } + // 鏍规嵁涓嶅悓绫诲瀷锛岀‘瀹氫笉鍚岀殑缃戞牸鐢熸垚鏂瑰紡锛屽緱鍑虹綉鏍间腑蹇冪偣闆嗗悎(缃戞牸榛樿閲囩敤姝f柟褰�) // 璧拌埅鐩戞祴 if (gridType == '0') { @@ -42,26 +98,51 @@ // 瀹氱偣鐩戞祴 else if (gridType == '1') { // FIXME: 2021/12/6 姝ゅ涓轰簡娴嬭瘯鏆傛椂灏嗙珯鐐圭粡绾害鍐欐锛屽悗缁�氳繃鏁版嵁搴撻厤缃幏鍙� - val center = Pair(121.235813, 30.835898) + val center = Pair(GridLng, GridLat) // a.纭畾缃戞牸闀垮害瀵瑰簲鐨勫潗鏍囧樊鍊� + // FIXME: 2021/12/16 姝ゅ缃戞牸鍧愭爣鐨勮绠楁瘮杈冪畝鍗曪紝杩戜技灏嗗叾褰撲綔骞抽潰鍧愭爣鏉ュ仛锛屽悗缁彲鏀硅繘 val p1 = MapUtil.getPointByLen(center, len, PI / 2)//姝d笢鏂瑰悜锛�90掳锛夌殑鍧愭爣鐐� val p2 = MapUtil.getPointByLen(center, len, PI)//姝e崡鏂瑰悜锛�180掳锛夌殑鍧愭爣鐐� val dx = p1.first - center.first val dy = center.second - p2.second // b.纭畾鍗曡竟鏈夊灏戜釜缃戞牸(瑙勫畾鐩戞祴鐐瑰湪涓績缃戞牸鐨勪腑鐐逛笂锛屽洜姝ゅ崟杈圭綉鏍兼暟涓�瀹氫负濂囨暟) - val totalLen = 2000 // 缃戞牸鑼冨洿锛岃竟闀夸负20鍗冪背鐨勬鏂瑰舰 + val totalLen = 2000 // FIXME: 2021/12/16 缃戞牸鑼冨洿锛岃竟闀夸负20鍗冪背鐨勬鏂瑰舰 val gridNum = ((totalLen / 2 / len).toInt() - 1) * 2 + 1 // c.纭畾宸︿笂瑙掔綉鏍煎乏涓嬪拰鍙充笂鐨勪袱涓瑙掔偣鍧愭爣 + var len1 = gridNum//姘村钩鏂瑰悜缃戞牸鏁� + var width = gridNum//鍨傜洿鏂瑰悜缃戞牸鏁� //涓績鐐瑰潗鏍� - val g1CenterLng = center.first - (gridNum - 1) / 2 * dx//缁忓害鍑忓皬 - val g1CenterLat = center.second + (gridNum - 1) / 2 * dy//绾害澧炲姞 + var g1CenterLng = center.first - (gridNum - 1) / 2 * dx//缁忓害鍑忓皬 + var g1CenterLat = center.second + (gridNum - 1) / 2 * dy//绾害澧炲姞 + when (windDirection) { + in .0..90.0 -> { + g1CenterLat += LEN * dy + width += LEN + len1 += LEN + } + in 90.0..180.0 -> { + len1 += LEN + width += LEN + } + in 180.0..270.0 -> { + g1CenterLng -= LEN * dx + len1 += LEN + width += LEN + } + in 270.0..360.0 -> { + g1CenterLng -= LEN * dx + g1CenterLat += LEN * dy + len1 += LEN + width += LEN + } + } //宸︿笅鍧愭爣 val g1LB = Pair(g1CenterLng - dx / 2, g1CenterLat - dy / 2) //鍙充笂鍧愭爣 val g1RT = Pair(g1CenterLng + dx / 2, g1CenterLat + dy / 2) // d.寰楀嚭鎵�鏈夌綉鏍肩殑涓や釜瀵硅鐐瑰潗鏍� - for (x in 0 until gridNum) { - for (y in 0 until gridNum) { + for (x in 0 until len1) { + for (y in 0 until width) { points.add(GridVo("$x-$y").apply { this.lb = Pair(g1LB.first + dx * x, g1LB.second - dy * y) this.rt = Pair(g1RT.first + dx * x, g1RT.second - dy * y) @@ -72,27 +153,7 @@ } } // 璁$畻鍚勪腑蹇冪偣姹℃煋椋庨櫓鏉冮噸缁撴灉骞惰祴浜堝搴斿奖鍝嶇瓑绾� - var page = 1 - var totalPage = -1 - while (totalPage == -1 || page <= totalPage) { - realTimeDataService.getSecondData(deviceCode, startTime, endTime, 0, page, 5000).apply { - if (totalPage == -1) { - totalPage = head?.totalPage ?: 0 - } - val dataList = data ?: emptyList() - - // FIXME: 2021/7/13 姝ゅ涓轰簡娴嬭瘯鏆傛椂灏嗙珯鐐圭粡绾害鍐欐锛屽悗缁�氳繃鏁版嵁搴撻厤缃幏鍙� - dataList.forEach { - if (it.lng == 0.0 && it.lat == 0.0) { - it.lng = GridLng - it.lat = GridLat - } - } - - epwModel.execute(dataList, points, true) - page++ - } - } + epwModel.execute(dataList, points, true) val r = epwModel.outputResult() val max = mutableMapOf<String, Double>()//璁板綍姣忕鐩戞祴鍥犲瓙鐨勬渶澶у�� @@ -138,4 +199,62 @@ } return BaseResponse(true, data = points) } + + /** + * 浠ョ洃娴嬬偣涓虹綉鏍肩嚎涓婄殑涓績锛屽悜澶栨寜鐓ф鏂瑰舰杩涜鎵╂暎銆� + * 棣栧厛榛樿灞曠ず鐩戞祴鐐瑰懆鍥翠竴鍦�16涓綉鏍硷紝鐒跺悗鍐嶄互澶栧湀12涓綉鏍间负鍩虹鍚戝鎵╂暎锛屾瘡娆℃渶澶氭墿鏁d竴鍦堬紝鍒ゆ柇鏉冮噸缁撴灉锛屼繚鐣欐墍鏈夌殑楂橀闄╁拰涓闄╃綉鏍硷紝骞朵繚鐣欎袱鍦堜綆椋庨櫓缃戞牸 + * 鍏朵腑鐨勯珮銆佷腑銆佷綆椋庨櫓鍒ゆ柇渚濇嵁涓虹綉鏍兼潈閲嶅�煎搴斿綋鍓嶆渶澶у�肩殑姣斾緥锛堝垎鐣屼负66.66%鍜�33.33%锛� + */ + override fun getEpwModelResultDynamic(deviceCode: String, startTime: String, endTime: String, len: Double): BaseResponse<List<GridVo>> { +// if (deviceCode.length < 2) return BaseResponse(false, "璁惧缂栧彿鏍煎紡閿欒") +// // 纭畾鏁版嵁婧愮被鍨嬶紝鍖哄垎涓衡�樺畾鐐圭洃娴嬫暟鎹�欏拰鈥樼Щ鍔ㄧ洃娴嬫暟鎹袱绉嶁�� +// val gridType = when (deviceCode.substring(0, 2)) { +// UWDeviceType.UAV.value -> '0' +// UWDeviceType.VEHICLE.value -> '0' +// UWDeviceType.GRID.value -> '1' +// UWDeviceType.BOAT.value -> 'f' +// else -> 'f' +// } +// if (gridType == 'f' || gridType == '0') return BaseResponse(false, "璇ヨ澶囩被鍨嬩笉鏀寔鍔ㄦ�佺綉鏍奸闄╄绠楋紝鍙湁瀹氱偣缃戞牸鍖栬澶囧彲琛�") +// val points = mutableListOf<GridVo>() +// // FIXME: 2021/12/6 姝ゅ涓轰簡娴嬭瘯鏆傛椂灏嗙珯鐐圭粡绾害鍐欐锛屽悗缁�氳繃鏁版嵁搴撻厤缃幏鍙� +// val center = Pair(GridLng, GridLat) +// +// // a.纭畾缃戞牸闀垮害瀵瑰簲鐨勫潗鏍囧樊鍊� +// // FIXME: 2021/12/16 姝ゅ缃戞牸鍧愭爣鐨勮绠楁瘮杈冪畝鍗曪紝杩戜技灏嗗叾褰撲綔骞抽潰鍧愭爣鏉ュ仛锛屽悗缁彲鏀硅繘 +// val p1 = MapUtil.getPointByLen(center, len, PI / 2)//姝d笢鏂瑰悜锛�90掳锛夌殑鍧愭爣鐐� +// val p2 = MapUtil.getPointByLen(center, len, PI)//姝e崡鏂瑰悜锛�180掳锛夌殑鍧愭爣鐐� +// val dx = p1.first - center.first +// val dy = center.second - p2.second +// +// val grids = mutableListOf<QuadrantInfo>()// 鎵�鏈夌綉鏍� +// val outerMost = mutableMapOf<Quadrant, QuadrantInfo>()// 褰撳墠鏈�澶栧湀鐨勭綉鏍� +// // b.鍏堣绠楀唴閮ㄤ袱鍦堢殑缁撴灉 +// grids.addAll(listOf( +// // 绗竴鍦� +// QuadrantInfo(Quadrant.First, 0), +// QuadrantInfo(Quadrant.Second, 0), +// QuadrantInfo(Quadrant.Third, 0), +// QuadrantInfo(Quadrant.Fourth, 0), +// // 绗簩鍦� +// QuadrantInfo(Quadrant.First, 1), +// QuadrantInfo(Quadrant.Second, 1), +// QuadrantInfo(Quadrant.Third, 1), +// QuadrantInfo(Quadrant.Fourth, 1), +// )) +// //褰撳墠鏈�澶栧湀锛堢浜屽湀锛� +// outerMost[Quadrant.First] = grids[4] +// outerMost[Quadrant.Second] = grids[5] +// outerMost[Quadrant.Third] = grids[6] +// outerMost[Quadrant.Fourth] = grids[7] +// //涓績鐐瑰潗鏍� +// val g1CenterLng = center.first - (gridNum - 1) / 2 * dx//缁忓害鍑忓皬 +// val g1CenterLat = center.second + (gridNum - 1) / 2 * dy//绾害澧炲姞 +// //宸︿笅鍧愭爣 +// val g1LB = Pair(g1CenterLng - dx / 2, g1CenterLat - dy / 2) +// //鍙充笂鍧愭爣 +// val g1RT = Pair(g1CenterLng + dx / 2, g1CenterLat + dy / 2) + + return BaseResponse(true) + } } \ No newline at end of file diff --git a/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/ElectricityServiceImpl.kt b/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/ElectricityServiceImpl.kt index 967c5a0..28cd86f 100644 --- a/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/ElectricityServiceImpl.kt +++ b/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/ElectricityServiceImpl.kt @@ -189,26 +189,20 @@ // 鏍规嵁涓ゅ彴璁惧鐨勬渶闀胯捣濮嬫椂闂达紝璁$畻鍏朵腑姣忎竴鍒嗛挓鐨勫搴斿潎鍊� while (!lsT.isAfter(leT)) { - // 涓ゅ彴璁惧鐨勬暟鎹牴鎹椂闂村悎骞朵负涓�涓粨鏋勪綋 - val vo = ElectricVo(lsT.format(dateFormatter2)) - // FIXME: 2021/11/22 姝ゅ鐢变簬鍓嶇璁惧鐨勯噰鏍锋椂闂翠笉鏍囧噯 锛岄噰鏍峰懆鏈熷苟涓嶆槸涓ユ牸鐨�1鍒嗛挓锛屽鑷撮噰鏍锋椂闂存湁鏃朵細缂哄皯1鍒嗛挓鐨勬暟鎹� // FIXME: 2021/11/22 鍥犳锛屽綋鏌愪竴鍒嗛挓璇ヨ澶囨暟鎹疆绌烘椂锛岄噰鐢ㄥ墠涓�涓暟鎹綔涓哄~鍏� - if (dataList1.isNotEmpty()) { - val d = dataList1[0] - val t = LocalDateTime.ofInstant(d?.mvDataTime?.toInstant(), ZoneId.systemDefault()).withSecond(0) - if (lsT.isEqual(t)) { - vo.apply { - d1eA = d?.mvElectricityA ?: .0 - d1eB = d?.mvElectricityB ?: .0 - d1eC = d?.mvElectricityC ?: .0 - val s = ElectricDailyAnalysis.getStatus(d, d1) - d1Status = s.first - d1StatusName = s.second - d1Avg = s.third - } - dataList1.removeAt(0) - } else { + val data1 = if (dataList1.isNotEmpty()) dataList1[0] else null + val t1 = data1?.let { LocalDateTime.ofInstant(it.mvDataTime?.toInstant(), ZoneId.systemDefault()).withSecond(0) } + val data2 = if (dataList2.isNotEmpty()) dataList2[0] else null + val t2 = data2?.let { LocalDateTime.ofInstant(it.mvDataTime?.toInstant(), ZoneId.systemDefault()).withSecond(0) } + if ((data1 == null || !lsT.isEqual(t1)) + && (data2 == null || !lsT.isEqual(t2)) + ) { + + } else { + // 涓ゅ彴璁惧鐨勬暟鎹牴鎹椂闂村悎骞朵负涓�涓粨鏋勪綋 + val vo = ElectricVo(lsT.format(dateFormatter2)) + if (data1 == null || !lsT.isEqual(t1)) { result.lastOrNull()?.let { vo.apply { d1eA = it.d1eA @@ -219,34 +213,20 @@ d1Avg = it.d1Avg } } - } - } else { - result.lastOrNull()?.let { - vo.apply { - d1eA = it.d1eA - d1eB = it.d1eB - d1eC = it.d1eC - d1Status = it.d1Status - d1StatusName = it.d1StatusName - d1Avg = it.d1Avg - } - } - } - if (dataList2.isNotEmpty()) { - val d = dataList2[0] - val t = LocalDateTime.ofInstant(d?.mvDataTime?.toInstant(), ZoneId.systemDefault()).withSecond(0) - if (lsT.isEqual(t)) { - vo.apply { - d2eA = d?.mvElectricityA ?: .0 - d2eB = d?.mvElectricityB ?: .0 - d2eC = d?.mvElectricityC ?: .0 - val s = ElectricDailyAnalysis.getStatus(d, d2) - d2Status = s.first - d2StatusName = s.second - d2Avg = s.third - } - dataList2.removeAt(0) } else { + vo.apply { + d1eA = data1.mvElectricityA ?: .0 + d1eB = data1.mvElectricityB ?: .0 + d1eC = data1.mvElectricityC ?: .0 + val s = ElectricDailyAnalysis.getStatus(data1, d1) + d1Status = s.first + d1StatusName = s.second + d1Avg = s.third + } + dataList1.removeAt(0) + } + + if (data2 == null || !lsT.isEqual(t2)) { result.lastOrNull()?.let { vo.apply { d2eA = it.d2eA @@ -257,20 +237,97 @@ d2Avg = it.d2Avg } } - } - } else { - result.lastOrNull()?.let { + } else { vo.apply { - d2eA = it.d2eA - d2eB = it.d2eB - d2eC = it.d2eC - d2Status = it.d2Status - d2StatusName = it.d2StatusName - d2Avg = it.d2Avg + d2eA = data2.mvElectricityA ?: .0 + d2eB = data2.mvElectricityB ?: .0 + d2eC = data2.mvElectricityC ?: .0 + val s = ElectricDailyAnalysis.getStatus(data2, d2) + d2Status = s.first + d2StatusName = s.second + d2Avg = s.third } + dataList2.removeAt(0) } + + result.add(vo) } - result.add(vo) +// if (dataList1.isNotEmpty()) { +// val d = dataList1[0] +// val t = LocalDateTime.ofInstant(d?.mvDataTime?.toInstant(), ZoneId.systemDefault()).withSecond(0) +// if (lsT.isEqual(t)) { +// vo.apply { +// d1eA = d?.mvElectricityA ?: .0 +// d1eB = d?.mvElectricityB ?: .0 +// d1eC = d?.mvElectricityC ?: .0 +// val s = ElectricDailyAnalysis.getStatus(d, d1) +// d1Status = s.first +// d1StatusName = s.second +// d1Avg = s.third +// } +// dataList1.removeAt(0) +// } else { +// result.lastOrNull()?.let { +// vo.apply { +// d1eA = it.d1eA +// d1eB = it.d1eB +// d1eC = it.d1eC +// d1Status = it.d1Status +// d1StatusName = it.d1StatusName +// d1Avg = it.d1Avg +// } +// } +// } +// } else { +// result.lastOrNull()?.let { +// vo.apply { +// d1eA = it.d1eA +// d1eB = it.d1eB +// d1eC = it.d1eC +// d1Status = it.d1Status +// d1StatusName = it.d1StatusName +// d1Avg = it.d1Avg +// } +// } +// } +// if (dataList2.isNotEmpty()) { +// val d = dataList2[0] +// val t = LocalDateTime.ofInstant(d?.mvDataTime?.toInstant(), ZoneId.systemDefault()).withSecond(0) +// if (lsT.isEqual(t)) { +// vo.apply { +// d2eA = d?.mvElectricityA ?: .0 +// d2eB = d?.mvElectricityB ?: .0 +// d2eC = d?.mvElectricityC ?: .0 +// val s = ElectricDailyAnalysis.getStatus(d, d2) +// d2Status = s.first +// d2StatusName = s.second +// d2Avg = s.third +// } +// dataList2.removeAt(0) +// } else { +// result.lastOrNull()?.let { +// vo.apply { +// d2eA = it.d2eA +// d2eB = it.d2eB +// d2eC = it.d2eC +// d2Status = it.d2Status +// d2StatusName = it.d2StatusName +// d2Avg = it.d2Avg +// } +// } +// } +// } else { +// result.lastOrNull()?.let { +// vo.apply { +// d2eA = it.d2eA +// d2eB = it.d2eB +// d2eC = it.d2eC +// d2Status = it.d2Status +// d2StatusName = it.d2StatusName +// d2Avg = it.d2Avg +// } +// } +// } lsT = lsT.plusMinutes(1) } @@ -301,10 +358,10 @@ // 褰撴湁寮�濮嬬粨鏉熸椂闂存椂锛屽垽鏂牸寮忔槸鍚︽纭� else { try { - st = LocalDateTime.parse(startTime, dateFormatter3).withHour(0).withMinute(0).withSecond(0) - et = LocalDateTime.parse(endTime, dateFormatter3).withHour(23).withMinute(59).withSecond(59) + st = LocalDateTime.parse("$startTime 00:00:00", dateFormatter3) + et = LocalDateTime.parse("$endTime 23:59:59", dateFormatter3) } catch (e: DateTimeParseException) { - return BaseResponse(false, "鏃堕棿鏍煎紡閿欒锛屽簲涓簓yyy-MM-dd hh:mm:dd") + return BaseResponse(false, "鏃堕棿鏍煎紡閿欒锛屽簲涓簓yyy-MM-dd") } } diff --git a/src/main/kotlin/com/flightfeather/uav/model/epw/WindDirWeight.kt b/src/main/kotlin/com/flightfeather/uav/model/epw/WindDirWeight.kt index 73335b8..927fae2 100644 --- a/src/main/kotlin/com/flightfeather/uav/model/epw/WindDirWeight.kt +++ b/src/main/kotlin/com/flightfeather/uav/model/epw/WindDirWeight.kt @@ -39,6 +39,7 @@ x1 = abs(x2 - x1) if (x1 > 180) x1 = 360 - x1 // println("澶硅锛�$x1") + x1 = 180 - x1 return x1 } } \ No newline at end of file -- Gitblit v1.9.3