|
@@ -30,10 +30,10 @@ func TestService() {
|
|
|
var t_tupper float64 // 高温上限
|
|
|
var t_r_hlower float64 // 湿度下限
|
|
|
var t_r_hupper float64 // 湿度上限
|
|
|
- sn := "2023477814765836"
|
|
|
+ sn := "2024332675927850"
|
|
|
t_id := "1"
|
|
|
- startTime := "2024-09-25 00:00:00"
|
|
|
- endTime := "2024-09-25 15:32:00"
|
|
|
+ startTime := "2024-09-30 00:00:00"
|
|
|
+ endTime := "2024-10-09 10:04:00"
|
|
|
sql := fmt.Sprintf("SELECT * FROM z_device_data_%s WHERE t_id=%s and t_time BETWEEN '%s' AND '%s';", sn, t_id, startTime, endTime)
|
|
|
fmt.Println(sql)
|
|
|
devices := make([]DeviceData, 0)
|
|
@@ -85,28 +85,29 @@ func adjustData(devices []DeviceData, t_save_t, t_warn, sn string, t_tlower, t_t
|
|
|
// 检查是否为报警数据
|
|
|
isAlarm := devices[i].T_T < t_tlower || devices[i].T_T > t_tupper || devices[i].T_Rh < t_r_hlower || devices[i].T_Rh > t_r_hupper
|
|
|
isNextAlarm := devices[i+1].T_T < t_tlower || devices[i+1].T_T > t_tupper || devices[i+1].T_Rh < t_r_hlower || devices[i+1].T_Rh > t_r_hupper
|
|
|
- if isAlarm && !isNextAlarm {
|
|
|
- fmt.Printf("报警数据与正常数据:%s 和 %s\n", devices[i].T_Time, devices[i+1].T_Time)
|
|
|
- newTime := t1.Add(time.Duration(int(floatWarn-rand.Float64()*rand.Float64())) * time.Second)
|
|
|
- //newTime.Sub()
|
|
|
- fmt.Println(newTime.Format(timeFormat))
|
|
|
- T_T, T_Rh := IsNotWarn(devices, t_tlower, t_tupper, t_r_hlower, t_r_hupper)
|
|
|
- devi := DeviceData{
|
|
|
- T_Id: devices[i].T_Id,
|
|
|
- T_Sp: devices[i].T_Sp,
|
|
|
- T_Time: newTime.Format(timeFormat),
|
|
|
- T_T: T_T,
|
|
|
- T_Rh: T_Rh,
|
|
|
- T_Site: devices[i].T_Site,
|
|
|
- Create_time: devices[i].Create_time,
|
|
|
- }
|
|
|
- insertSql := fmt.Sprintf("INSERT INTO z_device_data_%s (t_id, t_sp, t_time, t_t, t_rh, t_site, create_time) VALUES (?, ?, ?, ?, ?, ?, ?)", sn)
|
|
|
- _, err := databases.Db.Exec(insertSql, devi.T_Id, devi.T_Sp, devi.T_Time, devi.T_T, devi.T_Rh, devi.T_Site.String, devi.Create_time)
|
|
|
- if err != nil {
|
|
|
- fmt.Println("插入新时间点失败:", err)
|
|
|
- }
|
|
|
- log.Println("sn:", sn, "连续报警补漏数据:", devi, " 插入时间点:", newTime.Format(timeFormat))
|
|
|
- }
|
|
|
+ // 处理报警数据与正常数据之间的间隔
|
|
|
+ //if isAlarm && !isNextAlarm {
|
|
|
+ // fmt.Printf("报警数据与正常数据:%s 和 %s\n", devices[i].T_Time, devices[i+1].T_Time)
|
|
|
+ // newTime := t1.Add(time.Duration(int(floatWarn-rand.Float64()*rand.Float64())) * time.Second)
|
|
|
+ // //newTime.Sub()
|
|
|
+ // fmt.Println(newTime.Format(timeFormat))
|
|
|
+ // T_T, T_Rh := IsNotWarn(devices, t_tlower, t_tupper, t_r_hlower, t_r_hupper)
|
|
|
+ // devi := DeviceData{
|
|
|
+ // T_Id: devices[i].T_Id,
|
|
|
+ // T_Sp: devices[i].T_Sp,
|
|
|
+ // T_Time: newTime.Format(timeFormat),
|
|
|
+ // T_T: T_T,
|
|
|
+ // T_Rh: T_Rh,
|
|
|
+ // T_Site: devices[i].T_Site,
|
|
|
+ // Create_time: devices[i].Create_time,
|
|
|
+ // }
|
|
|
+ // insertSql := fmt.Sprintf("INSERT INTO z_device_data_%s (t_id, t_sp, t_time, t_t, t_rh, t_site, create_time) VALUES (?, ?, ?, ?, ?, ?, ?)", sn)
|
|
|
+ // _, err := databases.Db.Exec(insertSql, devi.T_Id, devi.T_Sp, devi.T_Time, devi.T_T, devi.T_Rh, devi.T_Site.String, devi.Create_time)
|
|
|
+ // if err != nil {
|
|
|
+ // fmt.Println("插入新时间点失败:", err)
|
|
|
+ // }
|
|
|
+ // log.Println("sn:", sn, "连续报警补漏数据:", devi, " 插入时间点:", newTime.Format(timeFormat))
|
|
|
+ //}
|
|
|
// 处理报警与正常数据之间的间隔
|
|
|
if isAlarm && !isNextAlarm {
|
|
|
fmt.Println("处理报警数据与正常数据之间的间隔", devices[i].T_Time, devices[i+1].T_Time)
|
|
@@ -123,7 +124,7 @@ func adjustData(devices []DeviceData, t_save_t, t_warn, sn string, t_tlower, t_t
|
|
|
T_T: T_T,
|
|
|
T_Rh: T_Rh,
|
|
|
T_Site: devices[i].T_Site,
|
|
|
- Create_time: devices[i].Create_time,
|
|
|
+ Create_time: newTime.Format(timeFormat),
|
|
|
}
|
|
|
insertSql := fmt.Sprintf("INSERT INTO z_device_data_%s (t_id, t_sp, t_time, t_t, t_rh, t_site, create_time) VALUES (?, ?, ?, ?, ?, ?, ?)", sn)
|
|
|
_, err := databases.Db.Exec(insertSql, devi.T_Id, devi.T_Sp, devi.T_Time, devi.T_T, devi.T_Rh, devi.T_Site.String, devi.Create_time)
|
|
@@ -136,6 +137,7 @@ func adjustData(devices []DeviceData, t_save_t, t_warn, sn string, t_tlower, t_t
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ // 处理时间差大于系统设置时间的情况
|
|
|
if timeDiff > floatSave {
|
|
|
fmt.Printf("时间差大于系统设置时间:%s 和 %s\n", devices[i].T_Time, devices[i+1].T_Time)
|
|
|
numInserts := int(timeDiff / floatSave)
|
|
@@ -149,7 +151,7 @@ func adjustData(devices []DeviceData, t_save_t, t_warn, sn string, t_tlower, t_t
|
|
|
T_T: T_T,
|
|
|
T_Rh: T_Rh,
|
|
|
T_Site: devices[i].T_Site,
|
|
|
- Create_time: devices[i].Create_time,
|
|
|
+ Create_time: newTime.Format(timeFormat),
|
|
|
}
|
|
|
insertSql := fmt.Sprintf("INSERT INTO z_device_data_%s (t_id, t_sp, t_time, t_t, t_rh, t_site, create_time) VALUES (?, ?, ?, ?, ?, ?, ?)", sn)
|
|
|
_, err := databases.Db.Exec(insertSql, devi.T_Id, devi.T_Sp, devi.T_Time, devi.T_T, devi.T_Rh, devi.T_Site.String, devi.Create_time)
|
|
@@ -159,11 +161,15 @@ func adjustData(devices []DeviceData, t_save_t, t_warn, sn string, t_tlower, t_t
|
|
|
log.Println("sn:", sn, "补漏数据:", devi, " 插入时间点:", newTime.Format(timeFormat))
|
|
|
}
|
|
|
}
|
|
|
+ // 处理连续报警数据
|
|
|
if isAlarm && isNextAlarm {
|
|
|
- if timeDiff <= floatWarn {
|
|
|
- fmt.Printf("连续报警时间差小于报警间隔时间:%s 和 %s\n", devices[i].T_Time, devices[i+1].T_Time)
|
|
|
- newTime := t1.Add(time.Duration(int(timeDiff-rand.Float64()*0.4-0.2)) * time.Second)
|
|
|
- fmt.Println(newTime.Format(timeFormat))
|
|
|
+ if timeDiff > floatWarn {
|
|
|
+ fmt.Printf("连续报警时间差大于报警间隔时间:%s 和 %s\n", devices[i].T_Time, devices[i+1].T_Time)
|
|
|
+ newTimeWarn := devices[i].T_Time
|
|
|
+ parse, _ := time.Parse(timeFormat, newTimeWarn)
|
|
|
+ newTime := parse.Add(time.Duration(int(floatWarn-rand.Float64()*10-0.2)) * time.Second)
|
|
|
+ //newTime := t1.Add(time.Duration(int(timeDiff-rand.Float64()*10-0.2)) * time.Second)
|
|
|
+ fmt.Println("报警新时间:", newTime.Format(timeFormat))
|
|
|
T_T, T_Rh := IsNotWarn(devices, t_tlower, t_tupper, t_r_hlower, t_r_hupper)
|
|
|
devi := DeviceData{
|
|
|
T_Id: devices[i].T_Id,
|
|
@@ -172,7 +178,7 @@ func adjustData(devices []DeviceData, t_save_t, t_warn, sn string, t_tlower, t_t
|
|
|
T_T: T_T,
|
|
|
T_Rh: T_Rh,
|
|
|
T_Site: devices[i].T_Site,
|
|
|
- Create_time: devices[i].Create_time,
|
|
|
+ Create_time: newTime.Format(timeFormat),
|
|
|
}
|
|
|
insertSql := fmt.Sprintf("INSERT INTO z_device_data_%s (t_id, t_sp, t_time, t_t, t_rh, t_site, create_time) VALUES (?, ?, ?, ?, ?, ?, ?)", sn)
|
|
|
_, err := databases.Db.Exec(insertSql, devi.T_Id, devi.T_Sp, devi.T_Time, devi.T_T, devi.T_Rh, devi.T_Site.String, devi.Create_time)
|
|
@@ -182,7 +188,6 @@ func adjustData(devices []DeviceData, t_save_t, t_warn, sn string, t_tlower, t_t
|
|
|
log.Println("sn:", sn, "连续报警补漏数据:", devi, " 插入时间点:", newTime.Format(timeFormat))
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
func IsNotWarn(deviceDatas []DeviceData, t_tlower, t_tupper, t_r_hlower, t_r_hupper float64) (T_T float64, T_Rh float64) {
|