feiyu02
2023-10-20 3371ed856d8712732b3f46e30e41e652ff5d7781
新增数据分析模块
已修改5个文件
已删除1个文件
已添加8个文件
443 ■■■■ 文件已修改
src/main/java/com/flightfeather/monitor/analysis/BaseDataAnalysis.kt 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/flightfeather/monitor/analysis/DataAnalysisInterface.kt 30 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/flightfeather/monitor/analysis/dust/BaseDustExceptionAnalysis.kt 46 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/flightfeather/monitor/analysis/dust/BaseExceptionContinuous.kt 59 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/flightfeather/monitor/analysis/dust/ExceptionApproachExceeding.kt 23 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/flightfeather/monitor/analysis/dust/ExceptionDataMissing.kt 31 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/flightfeather/monitor/analysis/dust/ExceptionExceedingTimes.kt 47 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/flightfeather/monitor/analysis/dust/ExceptionNoFluctuation.kt 22 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/flightfeather/monitor/analysis/dust/ExceptionValueMutation.kt 34 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/flightfeather/monitor/domain/ds1/entity/DustExceptionSetting.java 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/flightfeather/monitor/enumration/dust/ExceptionType.kt 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/generator/generatorConfig4ds1.xml 70 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/resources/mapper/ds1/DustExceptionSettingMapper.xml 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/test/java/com/flightfeather/monitor/QianduanApplicationTests.java 26 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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);
    }