From 665a2e1098fb52800ac7624d4a32dfeb6ce15151 Mon Sep 17 00:00:00 2001 From: riku <risaku@163.com> Date: 星期三, 10 十一月 2021 11:03:36 +0800 Subject: [PATCH] 1. 网格化均值计算逻辑完成 --- src/main/resources/generator/generatorConfig.xml | 3 src/main/resources/mapper/RealTimeDataGridMinMapper.xml | 39 ++++ src/test/kotlin/com/flightfeather/uav/lightshare/service/impl/RealTimeDataServiceImplTest.kt | 9 + src/main/kotlin/com/flightfeather/uav/dataprocess/AvgPair.kt | 4 src/main/kotlin/com/flightfeather/uav/domain/entity/BaseRealTimeData.kt | 34 ++ src/main/kotlin/com/flightfeather/uav/domain/entity/RealTimeDataGridMin.java | 375 +++++++++++++++++++++++++++++++++++++++++ src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/RealTimeDataServiceImpl.kt | 18 - src/main/kotlin/com/flightfeather/uav/domain/mapper/RealTimeDataGridMinMapper.kt | 8 src/main/kotlin/com/flightfeather/uav/dataprocess/AverageUtil.kt | 6 9 files changed, 473 insertions(+), 23 deletions(-) diff --git a/src/main/kotlin/com/flightfeather/uav/dataprocess/AverageUtil.kt b/src/main/kotlin/com/flightfeather/uav/dataprocess/AverageUtil.kt index 316fe93..6cc7b95 100644 --- a/src/main/kotlin/com/flightfeather/uav/dataprocess/AverageUtil.kt +++ b/src/main/kotlin/com/flightfeather/uav/dataprocess/AverageUtil.kt @@ -6,21 +6,21 @@ * @param onTag 瀹氫箟鏁版嵁鏍囩鑾峰彇鍥炶皟鍑芥暟锛屽綋褰撳墠鏁版嵁鏍囩涓庝笂涓暟鎹爣绛句笉鍚屾椂锛屽嵆璁や负涓婁竴缁勬暟鎹负鍚屼竴缁勬暟鎹紝闇�姹傚嚭鍧囧�� * @param onAvg 瀹氫箟鍧囧�艰绠楁柟娉� */ -class AverageUtil<T : Any>(var onTag: (d: T) -> String, var onAvg: (list: List<T>) -> T) { +class AverageUtil<T, K>(var onTag: (d: T) -> String, var onAvg: (list: List<T>) -> K) { // 缂撳瓨鏈�鏂扮殑tag private var lastTag: String? = null // 涓存椂鏁版嵁缂撳瓨 private val dataSet = mutableListOf<T>() // 杞崲缁撴灉 - private val result = mutableListOf<T>() + private val result = mutableListOf<K>() /** * 灏嗘暟鎹泦杞崲涓哄潎鍊兼暟鎹� * @param list 鍘熷鏁版嵁 * @return 鍧囧�兼暟鎹� */ - fun avg(list: List<T>): List<T> { + fun avg(list: List<T>): List<K> { // 鍒濆鍖栨墍鏈夊彉閲� clear() // 璁$畻鍧囧�� diff --git a/src/main/kotlin/com/flightfeather/uav/dataprocess/AvgPair.kt b/src/main/kotlin/com/flightfeather/uav/dataprocess/AvgPair.kt index 02daa91..6267a69 100644 --- a/src/main/kotlin/com/flightfeather/uav/dataprocess/AvgPair.kt +++ b/src/main/kotlin/com/flightfeather/uav/dataprocess/AvgPair.kt @@ -1,11 +1,13 @@ package com.flightfeather.uav.dataprocess +import kotlin.math.round + data class AvgPair( var t: Float, var c: Int ){ fun avg(): Float = if (c == 0) { 0f } else { - t / c + round(t / c * 1000) / 1000 } } \ No newline at end of file diff --git a/src/main/kotlin/com/flightfeather/uav/domain/entity/BaseRealTimeData.kt b/src/main/kotlin/com/flightfeather/uav/domain/entity/BaseRealTimeData.kt index cb51649..e16d1f2 100644 --- a/src/main/kotlin/com/flightfeather/uav/domain/entity/BaseRealTimeData.kt +++ b/src/main/kotlin/com/flightfeather/uav/domain/entity/BaseRealTimeData.kt @@ -12,8 +12,7 @@ import java.util.* import javax.persistence.Column import javax.persistence.Id -import kotlin.math.cos -import kotlin.math.sin +import kotlin.math.* /** * 瀹炴椂鐩戞祴鏁版嵁鍩虹被 @@ -111,10 +110,10 @@ } } -fun List<RealTimeDataGrid>.avg(): RealTimeDataGrid { +fun List<RealTimeDataGrid>.avg(): RealTimeDataGridMin { //椋庡悜閲囩敤鍗曚綅鐭㈤噺娉曟眰鍙栧潎鍊� - var u = 0f//涓滆タ鏂逛綅鍒嗛噺鎬诲拰 - var v = 0f//鍗楀寳鏂逛綅鍒嗛噺鎬诲拰 + var u = .0//涓滆タ鏂逛綅鍒嗛噺鎬诲拰 + var v = .0//鍗楀寳鏂逛綅鍒嗛噺鎬诲拰 var c = 0//椋庡悜鏁版嵁璁℃暟 //闄ら鍚戝鐨勫叾浠栧洜瀛愰噰鐢ㄧ畻鏈钩鍧囨硶姹傚彇鍧囧�� @@ -126,8 +125,9 @@ forEach { //椋庡悜 it.windDirection?.let {w -> - u += sin(w) - v += cos(w) + val r = Math.toRadians(w.toDouble()) + u += sin(r) + v += cos(r) c++ } //鍏朵綑鍥犲瓙 @@ -235,7 +235,7 @@ } } - return RealTimeDataGrid().apply { + return RealTimeDataGridMin().apply { val time = LocalDateTime.ofInstant(get(0).dataTime?.toInstant(), ZoneId.systemDefault()).withSecond(0) deviceCode = get(0).deviceCode dataTime = Date.from(time.atZone(ZoneId.systemDefault()).toInstant()) @@ -257,5 +257,23 @@ velocity = tmpList[14].avg() windSpeed = tmpList[15].avg() height = tmpList[16].avg() + + if (c != 0) { + val avgU = u / c + val avgV = v / c + var a = atan(avgU / avgV) + /** + * 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 = round(a.toFloat()) + } } } \ No newline at end of file diff --git a/src/main/kotlin/com/flightfeather/uav/domain/entity/RealTimeDataGridMin.java b/src/main/kotlin/com/flightfeather/uav/domain/entity/RealTimeDataGridMin.java new file mode 100644 index 0000000..b5fcd00 --- /dev/null +++ b/src/main/kotlin/com/flightfeather/uav/domain/entity/RealTimeDataGridMin.java @@ -0,0 +1,375 @@ +package com.flightfeather.uav.domain.entity; + +import java.math.BigDecimal; +import java.util.Date; +import javax.persistence.*; + +@Table(name = "real_time_data_grid_min") +public class RealTimeDataGridMin { + @Id + private Integer id; + + @Column(name = "device_code") + private String deviceCode; + + private BigDecimal latitude; + + private BigDecimal longitude; + + private Float altitude; + + @Column(name = "data_time") + private Date dataTime; + + @Column(name = "create_time") + private Date createTime; + + @Column(name = "NO2") + private Float no2; + + @Column(name = "CO") + private Float co; + + @Column(name = "H2S") + private Float h2s; + + @Column(name = "SO2") + private Float so2; + + @Column(name = "O3") + private Float o3; + + @Column(name = "PM25") + private Float pm25; + + @Column(name = "PM10") + private Float pm10; + + private Float temperature; + + private Float humidity; + + @Column(name = "VOC") + private Float voc; + + @Column(name = "NOI") + private Float noi; + + private Float velocity; + + @Column(name = "wind_speed") + private Float windSpeed; + + @Column(name = "wind_direction") + private Float windDirection; + + private Float height; + + /** + * @return id + */ + public Integer getId() { + return id; + } + + /** + * @param id + */ + public void setId(Integer id) { + this.id = id; + } + + /** + * @return device_code + */ + public String getDeviceCode() { + return deviceCode; + } + + /** + * @param deviceCode + */ + public void setDeviceCode(String deviceCode) { + this.deviceCode = deviceCode == null ? null : deviceCode.trim(); + } + + /** + * @return latitude + */ + public BigDecimal getLatitude() { + return latitude; + } + + /** + * @param latitude + */ + public void setLatitude(BigDecimal latitude) { + this.latitude = latitude; + } + + /** + * @return longitude + */ + public BigDecimal getLongitude() { + return longitude; + } + + /** + * @param longitude + */ + public void setLongitude(BigDecimal longitude) { + this.longitude = longitude; + } + + /** + * @return altitude + */ + public Float getAltitude() { + return altitude; + } + + /** + * @param altitude + */ + public void setAltitude(Float altitude) { + this.altitude = altitude; + } + + /** + * @return data_time + */ + public Date getDataTime() { + return dataTime; + } + + /** + * @param dataTime + */ + public void setDataTime(Date dataTime) { + this.dataTime = dataTime; + } + + /** + * @return create_time + */ + public Date getCreateTime() { + return createTime; + } + + /** + * @param createTime + */ + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + /** + * @return NO2 + */ + public Float getNo2() { + return no2; + } + + /** + * @param no2 + */ + public void setNo2(Float no2) { + this.no2 = no2; + } + + /** + * @return CO + */ + public Float getCo() { + return co; + } + + /** + * @param co + */ + public void setCo(Float co) { + this.co = co; + } + + /** + * @return H2S + */ + public Float getH2s() { + return h2s; + } + + /** + * @param h2s + */ + public void setH2s(Float h2s) { + this.h2s = h2s; + } + + /** + * @return SO2 + */ + public Float getSo2() { + return so2; + } + + /** + * @param so2 + */ + public void setSo2(Float so2) { + this.so2 = so2; + } + + /** + * @return O3 + */ + public Float getO3() { + return o3; + } + + /** + * @param o3 + */ + public void setO3(Float o3) { + this.o3 = o3; + } + + /** + * @return PM25 + */ + public Float getPm25() { + return pm25; + } + + /** + * @param pm25 + */ + public void setPm25(Float pm25) { + this.pm25 = pm25; + } + + /** + * @return PM10 + */ + public Float getPm10() { + return pm10; + } + + /** + * @param pm10 + */ + public void setPm10(Float pm10) { + this.pm10 = pm10; + } + + /** + * @return temperature + */ + public Float getTemperature() { + return temperature; + } + + /** + * @param temperature + */ + public void setTemperature(Float temperature) { + this.temperature = temperature; + } + + /** + * @return humidity + */ + public Float getHumidity() { + return humidity; + } + + /** + * @param humidity + */ + public void setHumidity(Float humidity) { + this.humidity = humidity; + } + + /** + * @return VOC + */ + public Float getVoc() { + return voc; + } + + /** + * @param voc + */ + public void setVoc(Float voc) { + this.voc = voc; + } + + /** + * @return NOI + */ + public Float getNoi() { + return noi; + } + + /** + * @param noi + */ + public void setNoi(Float noi) { + this.noi = noi; + } + + /** + * @return velocity + */ + public Float getVelocity() { + return velocity; + } + + /** + * @param velocity + */ + public void setVelocity(Float velocity) { + this.velocity = velocity; + } + + /** + * @return wind_speed + */ + public Float getWindSpeed() { + return windSpeed; + } + + /** + * @param windSpeed + */ + public void setWindSpeed(Float windSpeed) { + this.windSpeed = windSpeed; + } + + /** + * @return wind_direction + */ + public Float getWindDirection() { + return windDirection; + } + + /** + * @param windDirection + */ + public void setWindDirection(Float windDirection) { + this.windDirection = windDirection; + } + + /** + * @return height + */ + public Float getHeight() { + return height; + } + + /** + * @param height + */ + public void setHeight(Float height) { + this.height = height; + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/flightfeather/uav/domain/mapper/RealTimeDataGridMinMapper.kt b/src/main/kotlin/com/flightfeather/uav/domain/mapper/RealTimeDataGridMinMapper.kt new file mode 100644 index 0000000..b8b4e8e --- /dev/null +++ b/src/main/kotlin/com/flightfeather/uav/domain/mapper/RealTimeDataGridMinMapper.kt @@ -0,0 +1,8 @@ +package com.flightfeather.uav.domain.mapper + +import com.flightfeather.uav.domain.MyMapper +import com.flightfeather.uav.domain.entity.RealTimeDataGridMin +import org.apache.ibatis.annotations.Mapper + +@Mapper +interface RealTimeDataGridMinMapper : MyMapper<RealTimeDataGridMin?> \ No newline at end of file diff --git a/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/RealTimeDataServiceImpl.kt b/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/RealTimeDataServiceImpl.kt index ed3f0f2..0336692 100644 --- a/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/RealTimeDataServiceImpl.kt +++ b/src/main/kotlin/com/flightfeather/uav/lightshare/service/impl/RealTimeDataServiceImpl.kt @@ -6,10 +6,7 @@ import com.flightfeather.uav.common.utils.GsonUtils import com.flightfeather.uav.dataprocess.AverageUtil import com.flightfeather.uav.domain.entity.* -import com.flightfeather.uav.domain.mapper.RealTimeDataGridMapper -import com.flightfeather.uav.domain.mapper.RealTimeDataMapper -import com.flightfeather.uav.domain.mapper.RealTimeDataUavMapper -import com.flightfeather.uav.domain.mapper.RealTimeDataVehicleMapper +import com.flightfeather.uav.domain.mapper.* import com.flightfeather.uav.lightshare.bean.* import com.flightfeather.uav.lightshare.service.RealTimeDataService import com.flightfeather.uav.model.epw.EPWDataPrep @@ -35,7 +32,8 @@ private val airDataRepository: AirDataRepository, private val realTimeDataVehicleMapper: RealTimeDataVehicleMapper, private val realTimeDataUavMapper: RealTimeDataUavMapper, - private val realTimeDataGridMapper: RealTimeDataGridMapper + private val realTimeDataGridMapper: RealTimeDataGridMapper, + private val realTimeDataGridMinMapper: RealTimeDataGridMinMapper ) : RealTimeDataService { private var dateFormatter = SimpleDateFormat("yyyy-MM-dd HH:mm:ss") @@ -253,7 +251,7 @@ var count = 0 while (total == -1 || page <= total) { - println("------start------") + println("------鏁版嵁棰勫鐞唖tart------") val res = getOriginData("0d0000000001", "2021-07-05 19:47:01", "2021-11-05 00:00:00", page, 50000) res.head?.let { total = it.totalPage @@ -272,20 +270,19 @@ } override fun averageData(): BaseResponse<String> { - val epwDataPrep = EPWDataPrep() var page = 1 var total = -1 var count = 0 val minFormatter = SimpleDateFormat("yyyy-MM-dd HH:mm") - val averageUtil = AverageUtil<RealTimeDataGrid>({d -> + val averageUtil = AverageUtil<RealTimeDataGrid, RealTimeDataGridMin>({d -> minFormatter.format(d.dataTime) },{list -> list.avg() }) while (total == -1 || page <= total) { - println("------start------") + println("------鍧囧�艰绠梥tart------") val p = PageHelper.startPage<RealTimeDataGrid>(page, 50000) val res = realTimeDataGridMapper.selectByExample(Example(RealTimeDataGrid::class.java).apply { @@ -299,7 +296,8 @@ } println("褰撳墠椤垫暟锛�$page") averageUtil.avg(res).forEach { - + realTimeDataGridMinMapper.insert(it) + count++ } page++ diff --git a/src/main/resources/generator/generatorConfig.xml b/src/main/resources/generator/generatorConfig.xml index d5572c1..13864e0 100644 --- a/src/main/resources/generator/generatorConfig.xml +++ b/src/main/resources/generator/generatorConfig.xml @@ -55,6 +55,7 @@ <!-- <table tableName="real_time_data_uav" domainObjectName="RealTimeDataUav" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>--> <!-- <table tableName="real_time_data_vehicle" domainObjectName="RealTimeDataVehicle" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>--> <!-- <table tableName="device_info" domainObjectName="DeviceInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>--> - <table tableName="factor_calibration" domainObjectName="FactorCalibration" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/> +<!-- <table tableName="factor_calibration" domainObjectName="FactorCalibration" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/>--> + <table tableName="real_time_data_grid_min" domainObjectName="RealTimeDataGridMin" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/> </context> </generatorConfiguration> \ No newline at end of file diff --git a/src/main/resources/mapper/RealTimeDataGridMinMapper.xml b/src/main/resources/mapper/RealTimeDataGridMinMapper.xml new file mode 100644 index 0000000..77bb6e2 --- /dev/null +++ b/src/main/resources/mapper/RealTimeDataGridMinMapper.xml @@ -0,0 +1,39 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> +<mapper namespace="com.flightfeather.uav.domain.mapper.RealTimeDataGridMinMapper"> + <resultMap id="BaseResultMap" type="com.flightfeather.uav.domain.entity.RealTimeDataGridMin"> + <!-- + WARNING - @mbg.generated + --> + <id column="id" jdbcType="INTEGER" property="id" /> + <result column="device_code" jdbcType="VARCHAR" property="deviceCode" /> + <result column="latitude" jdbcType="DECIMAL" property="latitude" /> + <result column="longitude" jdbcType="DECIMAL" property="longitude" /> + <result column="altitude" jdbcType="REAL" property="altitude" /> + <result column="data_time" jdbcType="TIMESTAMP" property="dataTime" /> + <result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> + <result column="NO2" jdbcType="REAL" property="no2" /> + <result column="CO" jdbcType="REAL" property="co" /> + <result column="H2S" jdbcType="REAL" property="h2s" /> + <result column="SO2" jdbcType="REAL" property="so2" /> + <result column="O3" jdbcType="REAL" property="o3" /> + <result column="PM25" jdbcType="REAL" property="pm25" /> + <result column="PM10" jdbcType="REAL" property="pm10" /> + <result column="temperature" jdbcType="REAL" property="temperature" /> + <result column="humidity" jdbcType="REAL" property="humidity" /> + <result column="VOC" jdbcType="REAL" property="voc" /> + <result column="NOI" jdbcType="REAL" property="noi" /> + <result column="velocity" jdbcType="REAL" property="velocity" /> + <result column="wind_speed" jdbcType="REAL" property="windSpeed" /> + <result column="wind_direction" jdbcType="REAL" property="windDirection" /> + <result column="height" jdbcType="REAL" property="height" /> + </resultMap> + <sql id="Base_Column_List"> + <!-- + WARNING - @mbg.generated + --> + id, device_code, latitude, longitude, altitude, data_time, create_time, NO2, CO, + H2S, SO2, O3, PM25, PM10, temperature, humidity, VOC, NOI, velocity, wind_speed, + wind_direction, height + </sql> +</mapper> \ No newline at end of file diff --git a/src/test/kotlin/com/flightfeather/uav/lightshare/service/impl/RealTimeDataServiceImplTest.kt b/src/test/kotlin/com/flightfeather/uav/lightshare/service/impl/RealTimeDataServiceImplTest.kt index 0e8ae72..9060825 100644 --- a/src/test/kotlin/com/flightfeather/uav/lightshare/service/impl/RealTimeDataServiceImplTest.kt +++ b/src/test/kotlin/com/flightfeather/uav/lightshare/service/impl/RealTimeDataServiceImplTest.kt @@ -18,6 +18,9 @@ import java.io.File import java.io.FileOutputStream import java.util.* +import kotlin.math.atan +import kotlin.math.cos +import kotlin.math.sin @RunWith(SpringRunner::class) @SpringBootTest @@ -122,4 +125,10 @@ val r = realTimeDataService.dataPreprocessing() println(r.data) } + + @Test + fun averageData() { + val r = realTimeDataService.averageData() + println(r.data) + } } \ No newline at end of file -- Gitblit v1.9.3