1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package com.flightfeather.uav.dataprocess
 
import com.flightfeather.uav.common.utils.DateUtil
import com.flightfeather.uav.common.utils.ExcelUtil
import com.flightfeather.uav.domain.entity.RealTimeData
import com.flightfeather.uav.domain.mapper.RealTimeDataMapper
import com.flightfeather.uav.lightshare.service.RealTimeDataService
import com.github.pagehelper.PageHelper
import org.apache.poi.xssf.streaming.SXSSFWorkbook
import org.junit.Assert.*
import org.junit.Test
import org.junit.runner.RunWith
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.junit4.SpringRunner
import tk.mybatis.mapper.entity.Example
import java.text.SimpleDateFormat
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import java.util.*
 
@RunWith(SpringRunner::class)
@SpringBootTest
class DataProcessTest {
 
    @Autowired
    lateinit var realTimeDataMapper: RealTimeDataMapper
 
    @Autowired
    lateinit var realTimeDataService: RealTimeDataService
 
    @Test
    fun dataProcess() {
        val fileName = "网格化监测数据预处理${Date().time}.xls"
        val filePath = "C:\\work\\工作\\走航监测\\走航监测\\$fileName"
//        val filePath = "E:\\工作\\开发\\走航监测\\数据预处理\\$fileName"
        val process = DataProcess(filePath)
 
        /**
         * 按每日间隔循环获取数据,进行数处理
         * 数据为4秒钟1个值,因此一天的数据量最多为21600个
         */
        //截止时间
        val endDateTime = LocalDateTime.of(2021, 10, 5, 10, 0, 0)
        var sTime = LocalDateTime.of(2021, 6, 19, 0, 0, 0)
        var eTime = LocalDateTime.of(2021, 6, 19, 23, 59, 59)
 
        while (sTime.isBefore(endDateTime)) {
            if (eTime.isAfter(endDateTime)) {
                eTime = endDateTime
            }
            val deviceCode = "0d0000000001"
            val dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")
            val s = sTime.format(dateFormatter)
            val e = eTime.format(dateFormatter)
            val data = realTimeDataService.getSecondData(deviceCode, s, e, 1, 30000).data
            data?.let {
                process.process(it)
            }
            sTime = sTime.plusDays(1)
            eTime = eTime.plusDays(1)
        }
 
        process.outPutDailyVariation()
        process.done()
    }
}