src/main/java/com/flightfeather/monitor/analysis/BaseDataAnalysis.kt
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,27 @@ package com.flightfeather.monitor.analysis /** * æ°æ®åæåºç±» */ abstract class BaseDataAnalysis<T, V, Y>(val config: V) { //åæç»æ val resultList = mutableListOf<Y>() /** * é ç½®åå§å */ open fun init(){ resultList.clear() } /** * æ¥æ¶ä¸ä¸ä¸ªæ¶é´ç¹çæ°æ® */ abstract fun onNextData(data: T) /** * æ°æ®å¾ªç¯ç»æ */ abstract fun onDone() } src/main/java/com/flightfeather/monitor/analysis/DataAnalysisInterface.kt
ÎļþÒÑɾ³ý src/main/java/com/flightfeather/monitor/analysis/dust/BaseDustExceptionAnalysis.kt
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,46 @@ package com.flightfeather.monitor.analysis.dust import com.flightfeather.monitor.analysis.BaseDataAnalysis import com.flightfeather.monitor.domain.ds1.entity.DustExceptionData import com.flightfeather.monitor.domain.ds1.entity.DustExceptionSetting import com.flightfeather.monitor.domain.ds1.entity.DustSiteData import com.flightfeather.monitor.enumration.dust.ExceptionType import java.time.Duration /** * æ¬å°çæµæ°æ®å¼å¸¸åæåºç±» */ abstract class BaseDustExceptionAnalysis(config: DustExceptionSetting) : BaseDataAnalysis<DustSiteData, DustExceptionSetting, DustExceptionData>(config) { /** * ç¡®å®å¼å¸¸ç±»å */ abstract fun getExceptionType(): ExceptionType /** * 夿ç¸é»æ°æ®æ¯å¦è¿ç» */ open fun isContinuous(d1: DustSiteData?, d2: DustSiteData): Boolean { if (d1 == null) return true val t1 = d1.lst val t2 = d2.lst return Duration.between(t1?.toInstant(), t2.toInstant()).toMinutes() <= 30 } /** * çæä¸æ¡å¼å¸¸åæç»æ */ protected fun newResult(p: DustSiteData?, n: DustSiteData): DustExceptionData { val eType = getExceptionType() return DustExceptionData().apply { mnCode = n.mnCode exception = eType.des exceptionType = eType.value region = config.region beginTime = if (p == null) n.lst else p.lst endTime = n.lst } } } src/main/java/com/flightfeather/monitor/analysis/dust/BaseExceptionContinuous.kt
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,59 @@ package com.flightfeather.monitor.analysis.dust import com.flightfeather.monitor.domain.ds1.entity.DustExceptionSetting import com.flightfeather.monitor.domain.ds1.entity.DustSiteData /** * è¿ç»ç±»åçå¼å¸¸åæåºç±» */ abstract class BaseExceptionContinuous(config: DustExceptionSetting) : BaseDustExceptionAnalysis(config) { private var sIndex = 0 private var startData: DustSiteData? = null private var eIndex = -1 private var lastData: DustSiteData? = null /** * 夿æ¯å¦æ»¡è¶³å¼å¸¸æ¡ä»¶ */ abstract fun judgeException(p: DustSiteData?, n: DustSiteData): Boolean /** * 夿å¼å¸¸åºç°çè¿ç»æ¶é¿æ¯å¦æ»¡è¶³æ¡ä»¶ */ abstract fun judgeDuration(sIndex: Int, eIndex: Int): Boolean override fun init() { startData = null lastData = null sIndex = 0 eIndex = -1 } override fun onNextData(data: DustSiteData) { eIndex++ if (lastData == null) { startData = data } // 夿ç¸é»æ°æ®æ¯å¦è¿ç»å¹¶ä¸æ¯å¦æ»¡è¶³å¼å¸¸å¤æ if (!(isContinuous(lastData, data) && judgeException(lastData, data))) { checkResult() sIndex = eIndex startData = data } lastData = data } override fun onDone() { checkResult() } /** * æ£æ¥è¿ç»å¼å¸¸ç»ææ¶ï¼æ¯å¦ç¬¦åå¼å¸¸å卿¡ä»¶ */ private fun checkResult() { if (judgeDuration(sIndex, eIndex)) { resultList.add(newResult(lastData, startData!!)) } } } src/main/java/com/flightfeather/monitor/analysis/dust/ExceptionApproachExceeding.kt
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,23 @@ package com.flightfeather.monitor.analysis.dust import com.flightfeather.monitor.domain.ds1.entity.DustExceptionSetting import com.flightfeather.monitor.domain.ds1.entity.DustSiteData import com.flightfeather.monitor.enumration.dust.ExceptionType /** * æ°æ®ä¸´è¿è¶ æ å¼å¸¸åæ */ class ExceptionApproachExceeding(config: DustExceptionSetting) : BaseExceptionContinuous(config) { override fun getExceptionType(): ExceptionType = ExceptionType.TYPE5 override fun judgeException(p: DustSiteData?, n: DustSiteData): Boolean { // å¤ææ°æ®æ¯å¦å¨è®¾å®ç临è¿è¶ æ èå´å return n.dustValue >= config.nearExceedLowValue && n.dustValue <= config.nearExceedHighValue } override fun judgeDuration(sIndex: Int, eIndex: Int): Boolean { // å¤ææ°æ®ä¸´è¿è¶ æ æ°éæ¯å¦è¿ç»è¶ è¿éå®ä¸ªæ° return (eIndex - sIndex) >= config.nearExceedNum } } src/main/java/com/flightfeather/monitor/analysis/dust/ExceptionDataMissing.kt
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,31 @@ package com.flightfeather.monitor.analysis.dust import com.flightfeather.monitor.domain.ds1.entity.DustExceptionSetting import com.flightfeather.monitor.domain.ds1.entity.DustSiteData import com.flightfeather.monitor.enumration.dust.ExceptionType import java.time.Duration /** * æ°æ®ç¼ºå¤±å¼å¸¸åæ */ class ExceptionDataMissing(config: DustExceptionSetting) : BaseDustExceptionAnalysis(config) { private var lastData: DustSiteData? = null override fun getExceptionType(): ExceptionType = ExceptionType.TYPE0 override fun onNextData(data: DustSiteData) { lastData?.let { val t1 = it.lst val t2 = data.lst if (Duration.between(t1?.toInstant(), t2.toInstant()).toMinutes() > config.missDataMinutes) { resultList.add(newResult(it, data)) } } lastData = data } override fun onDone() { //do noting } } src/main/java/com/flightfeather/monitor/analysis/dust/ExceptionExceedingTimes.kt
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,47 @@ package com.flightfeather.monitor.analysis.dust import com.flightfeather.monitor.domain.ds1.entity.DustExceptionData import com.flightfeather.monitor.domain.ds1.entity.DustExceptionSetting import com.flightfeather.monitor.domain.ds1.entity.DustSiteData import com.flightfeather.monitor.enumration.dust.ExceptionType import java.time.LocalDateTime import java.time.ZoneId import java.util.* /** * åæ¥è¶ æ æ¬¡æ°ä¸´è¿å¤ç½æ åå¼å¸¸åæ */ class ExceptionExceedingTimes(config: DustExceptionSetting) : BaseDustExceptionAnalysis(config) { private var exceedingCount = 0 private var startData: DustSiteData? = null override fun getExceptionType(): ExceptionType = ExceptionType.TYPE6 override fun onNextData(data: DustSiteData) { if (startData == null) startData = data if (data.dustValue >= config.exceedingStandard) { exceedingCount++ } } override fun onDone() { if (exceedingCount >= config.dayExceedBorderlineLowNum && exceedingCount < config.dayExceedBorderlineHighNum) { startData?.let { val eType = getExceptionType() val t = LocalDateTime.ofInstant(it.lst.toInstant(), ZoneId.systemDefault()) t.withHour(0) val sT = resultList.add(DustExceptionData().apply { mnCode = it.mnCode exception = eType.des exceptionType = eType.value region = config.region // beginTime = if (p == null) n.lst else p.lst // endTime = n.lst }) } } } } src/main/java/com/flightfeather/monitor/analysis/dust/ExceptionNoFluctuation.kt
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,22 @@ package com.flightfeather.monitor.analysis.dust import com.flightfeather.monitor.domain.ds1.entity.DustExceptionSetting import com.flightfeather.monitor.domain.ds1.entity.DustSiteData import com.flightfeather.monitor.enumration.dust.ExceptionType /** * æ°æ®é¿æ¶é´æ æ³¢å¨å¼å¸¸åæ */ class ExceptionNoFluctuation(config: DustExceptionSetting) : BaseExceptionContinuous(config) { override fun getExceptionType(): ExceptionType = ExceptionType.TYPE3 override fun judgeException(p: DustSiteData?, n: DustSiteData): Boolean { if (p == null) return false return p.dustValue == n.dustValue } override fun judgeDuration(sIndex: Int, eIndex: Int): Boolean { return (eIndex - sIndex) >= config.longTimeNoChange } } src/main/java/com/flightfeather/monitor/analysis/dust/ExceptionValueMutation.kt
@@ -1,39 +1,23 @@ package com.flightfeather.monitor.analysis.dust import com.flightfeather.monitor.analysis.DataAnalysisInterface import com.flightfeather.monitor.domain.ds1.entity.DustExceptionSetting import com.flightfeather.monitor.domain.ds1.entity.DustSiteData import java.util.* import kotlin.properties.Delegates import com.flightfeather.monitor.enumration.dust.ExceptionType import kotlin.math.abs /** * é级çªåå¼å¸¸åæ */ class ExceptionValueMutation(config: DustExceptionSetting) : DataAnalysisInterface<DustSiteData, DustExceptionSetting>(config) { class ExceptionValueMutation(config: DustExceptionSetting) : BaseExceptionContinuous(config) { private var mutationNum by Delegates.notNull<Int>() override fun getExceptionType(): ExceptionType = ExceptionType.TYPE4 private var mutationRate by Delegates.notNull<Double>() private var lastDataTime: Date? = null override fun initConfig(config: DustExceptionSetting) { mutationNum = config.mutationNum mutationRate = config.mutationRate override fun judgeException(p: DustSiteData?, n: DustSiteData): Boolean { if (p == null) return false return abs((p.dustValue - n.dustValue) / p.dustValue) >= config.mutationRate } override fun onNextData(data: DustSiteData) { if (lastDataTime != null) { // ç¸é»æ°æ®æ¶é´å°äºæçäº30åéå为ä¸ç» override fun judgeDuration(sIndex: Int, eIndex: Int): Boolean { return (eIndex - sIndex) >= config.mutationNum } lastDataTime = data.lst } override fun toDb() { TODO("Not yet implemented") } } src/main/java/com/flightfeather/monitor/domain/ds1/entity/DustExceptionSetting.java
@@ -13,6 +13,8 @@ @Column(name = "update_time") private Date updateTime; private String region; private String version; @Column(name = "miss_data_minutes") @@ -100,6 +102,20 @@ } /** * @return region */ public String getRegion() { return region; } /** * @param region */ public void setRegion(String region) { this.region = region == null ? null : region.trim(); } /** * @return version */ public String getVersion() { src/main/java/com/flightfeather/monitor/enumration/dust/ExceptionType.kt
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,9 @@ package com.flightfeather.monitor.enumration.dust enum class ExceptionType(val value:Int, val des:String) { TYPE0(0, "æç½ææçº¿"), TYPE3(3, "æ°æ®é¿æ¶æ®µæ æ³¢å¨"), TYPE4(4, "é级çªåå¼å¸¸"), TYPE5(5, "临è¿è¶ æ å¼å¸¸"), TYPE6(6, "åæ¥è¶ æ æ¬¡æ°ä¸´è¿å¤ç½å¼å¸¸"), } src/main/resources/generator/generatorConfig4ds1.xml
@@ -43,44 +43,44 @@ <property name="enableSubPackages" value="true"/> </javaClientGenerator> <!-- è¦çæç表 tableNameæ¯æ°æ®åºä¸ç表åæè§å¾å domainObjectNameæ¯å®ä½ç±»å--> <table tableName="du_js_t_login_info" domainObjectName="LoginInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/> <table tableName="du_js_t_request_task_setting" domainObjectName="RequestTaskSetting" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/> <table tableName="du_js_t_site_latest_time" domainObjectName="DustSiteLatestTime" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/> <table tableName="du_js_t_site_map" domainObjectName="DustSiteMap" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/> <table tableName="dust_exception_data" domainObjectName="DustExceptionData" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/> <!-- <table tableName="du_js_t_login_info" domainObjectName="LoginInfo" enableCountByExample="false"--> <!-- enableUpdateByExample="false" enableDeleteByExample="false"--> <!-- enableSelectByExample="false" selectByExampleQueryId="false"/>--> <!-- <table tableName="du_js_t_request_task_setting" domainObjectName="RequestTaskSetting"--> <!-- enableCountByExample="false"--> <!-- enableUpdateByExample="false" enableDeleteByExample="false"--> <!-- enableSelectByExample="false" selectByExampleQueryId="false"/>--> <!-- <table tableName="du_js_t_site_latest_time" domainObjectName="DustSiteLatestTime"--> <!-- enableCountByExample="false"--> <!-- enableUpdateByExample="false" enableDeleteByExample="false"--> <!-- enableSelectByExample="false" selectByExampleQueryId="false"/>--> <!-- <table tableName="du_js_t_site_map" domainObjectName="DustSiteMap"--> <!-- enableCountByExample="false"--> <!-- enableUpdateByExample="false" enableDeleteByExample="false"--> <!-- enableSelectByExample="false" selectByExampleQueryId="false"/>--> <!-- <table tableName="dust_exception_data" domainObjectName="DustExceptionData"--> <!-- enableCountByExample="false"--> <!-- enableUpdateByExample="false" enableDeleteByExample="false"--> <!-- enableSelectByExample="false" selectByExampleQueryId="false"/>--> <table tableName="dust_exception_setting" domainObjectName="DustExceptionSetting" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/> <table tableName="dust_global_setting" domainObjectName="DustGlobalSetting" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/> <table tableName="dust_statistics_value" domainObjectName="DustStatisticsValue" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/> <table tableName="ja_t_dust_site_data_info" domainObjectName="DustSiteData" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/> <table tableName="ja_t_dust_site_info" domainObjectName="DustSiteInfo" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"/> <!-- <table tableName="dust_global_setting" domainObjectName="DustGlobalSetting"--> <!-- enableCountByExample="false"--> <!-- enableUpdateByExample="false" enableDeleteByExample="false"--> <!-- enableSelectByExample="false" selectByExampleQueryId="false"/>--> <!-- <table tableName="dust_statistics_value" domainObjectName="DustStatisticsValue"--> <!-- enableCountByExample="false"--> <!-- enableUpdateByExample="false" enableDeleteByExample="false"--> <!-- enableSelectByExample="false" selectByExampleQueryId="false"/>--> <!-- <table tableName="ja_t_dust_site_data_info" domainObjectName="DustSiteData"--> <!-- enableCountByExample="false"--> <!-- enableUpdateByExample="false" enableDeleteByExample="false"--> <!-- enableSelectByExample="false" selectByExampleQueryId="false"/>--> <!-- <table tableName="ja_t_dust_site_info" domainObjectName="DustSiteInfo"--> <!-- enableCountByExample="false"--> <!-- enableUpdateByExample="false" enableDeleteByExample="false"--> <!-- enableSelectByExample="false" selectByExampleQueryId="false"/>--> </context> </generatorConfiguration> src/main/resources/mapper/ds1/DustExceptionSettingMapper.xml
@@ -8,6 +8,7 @@ <id column="id" jdbcType="INTEGER" property="id" /> <result column="user" jdbcType="VARCHAR" property="user" /> <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" /> <result column="region" jdbcType="VARCHAR" property="region" /> <result column="version" jdbcType="VARCHAR" property="version" /> <result column="miss_data_minutes" jdbcType="INTEGER" property="missDataMinutes" /> <result column="data_low" jdbcType="DOUBLE" property="dataLow" /> @@ -28,7 +29,7 @@ <!-- WARNING - @mbg.generated --> id, user, update_time, version, miss_data_minutes, data_low, long_time_no_change, id, user, update_time, region, version, miss_data_minutes, data_low, long_time_no_change, mutation_num, mutation_rate, near_exceed_low_value, near_exceed_high_value, near_exceed_num, day_exceed_borderline_low_num, day_exceed_borderline_high_num, change_trend_group, change_trend_interval, change_trend_rate, exceeding_standard src/test/java/com/flightfeather/monitor/QianduanApplicationTests.java
@@ -1,14 +1,12 @@ package com.flightfeather.monitor; import com.flightfeather.monitor.analysis.database.DustRepository; import com.flightfeather.monitor.pojo.DustExceptionSetting; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.*; import java.util.Date; import java.util.Locale; @SpringBootTest class QianduanApplicationTests { @@ -29,26 +27,6 @@ System.out.print(date1); //return df2.format(date1); } @Autowired private DustRepository dustRepository; @Test void readSiteData(){ // DustExceptionSetting dustExceptionSetting = DustExceptionSetting.getInstance(); // 读åå¼å¸¸åæå¤å®çé ç½® List<DustExceptionSetting> list= dustRepository.readExceptionSetting(); System.out.println("11111"); System.out.println(list.size()); System.out.println(list.get(0)); // List<DustSiteData> dustData = dustRepository.getDustData("2023-10-01 00:00:00","2023-10-01 01:00:00"); //// System.out.println(dustData.get(0).getMnCode()); // int a = Exceeding.main(dustData); // System.out.println(a); }