Sfoglia il codice sorgente

补漏逻辑修改

huangyan 1 mese fa
parent
commit
1e5df92ef3
2 ha cambiato i file con 38 aggiunte e 66 eliminazioni
  1. 0 33
      log.txt
  2. 38 33
      service/test.go

+ 0 - 33
log.txt

@@ -1,33 +0,0 @@
-2024/09/26 sn: 2023477814765836 补漏数据: {1 136149 2024-09-25 10:39:00 25.577922508203677 45.42932478276064 {106.64535522461,26.654289245605 true} 2024-08-20 13:39:03}  插入时间点: 2024-09-25 10:39:00
-2024/09/26 sn: 2023477814765836 补漏数据: {1 136149 2024-09-25 11:09:00 25.530009989245194 45.49717871567268 {106.64535522461,26.654289245605 true} 2024-08-20 13:39:03}  插入时间点: 2024-09-25 11:09:00
-2024/09/26 sn: 2023477814765836 补漏数据: {1 136149 2024-09-25 11:39:00 25.843398068553032 45.43428625357036 {106.64535522461,26.654289245605 true} 2024-08-20 13:39:03}  插入时间点: 2024-09-25 11:39:00
-2024/09/26 sn: 2023477814765836 补漏数据: {1 136149 2024-09-25 12:09:00 25.833369681522072 45.64911301740725 {106.64535522461,26.654289245605 true} 2024-08-20 13:39:03}  插入时间点: 2024-09-25 12:09:00
-2024/09/26 sn: 2023477814765836 补漏数据: {1 136149 2024-09-25 12:39:00 25.611850378429487 45.51905637584843 {106.64535522461,26.654289245605 true} 2024-08-20 13:39:03}  插入时间点: 2024-09-25 12:39:00
-2024/09/26 sn: 2023477814765836 补漏数据: {1 136149 2024-09-25 13:09:00 25.812513926760566 45.3913243425126 {106.64535522461,26.654289245605 true} 2024-08-20 13:39:03}  插入时间点: 2024-09-25 13:09:00
-2024/09/26 sn: 2023477814765836 补漏数据: {1 136149 2024-09-25 13:39:00 25.59118334346904 45.64149933950623 {106.64535522461,26.654289245605 true} 2024-08-20 13:39:03}  插入时间点: 2024-09-25 13:39:00
-2024/09/26 sn: 2023477814765836 补漏数据: {1 136149 2024-09-25 14:09:00 25.753855552715194 45.53924065338275 {106.64535522461,26.654289245605 true} 2024-08-20 13:39:03}  插入时间点: 2024-09-25 14:09:00
-2024/09/26 sn: 2023477814765836 补漏数据: {1 136149 2024-09-25 14:39:00 25.531676144840397 45.4006708735189 {106.64535522461,26.654289245605 true} 2024-08-20 13:39:03}  插入时间点: 2024-09-25 14:39:00
-2024/09/26 sn: 2023477814765836 补漏数据: {1 136149 2024-09-25 15:09:00 25.84620752267359 45.396297105073 {106.64535522461,26.654289245605 true} 2024-08-20 13:39:03}  插入时间点: 2024-09-25 15:09:00
-2024/09/26 sn: 2023477814765836 连续报警补漏数据: {1 136149 2024-09-25 13:38:58 25.56259890616579 45.56726664519685 {106.64535522461,26.654289245605 true} 2024-08-20 13:39:03}  插入时间点: 2024-09-25 13:38:58
-2024/09/26 sn: 2023477814765836 连续报警补漏数据: {1 136149 2024-09-25 13:10:59 25.54766767737276 45.59264285466801 {106.64535522461,26.654289245605 true} 2024-08-20 13:39:03}  插入时间点: 2024-09-25 13:10:59
-2024/09/26 sn: 2023477814765836 连续报警补漏数据: {1 136149 2024-09-25 13:10:58 25.80056844663136 45.58444450642123 {106.64535522461,26.654289245605 true} 2024-08-20 13:39:03}  插入时间点: 2024-09-25 13:10:58
-2024/09/26 sn: 2023477814765836 连续报警补漏数据: {1 136149 2024-09-25 13:12:58 25.75693254528304 45.50710595099833 {106.64535522461,26.654289245605 true} 2024-08-20 13:39:03}  插入时间点: 2024-09-25 13:12:58
-2024/09/26 sn: 2023477814765836 连续报警补漏数据: {1 136149 2024-09-25 13:10:59 25.54799176580378 45.597210245410125 {106.64535522461,26.654289245605 true} 2024-08-20 13:39:03}  插入时间点: 2024-09-25 13:10:59
-2024/09/26 sn: 2023477814765836 连续报警补漏数据: {1 136149 2024-09-25 13:12:39 25.532565835928498 45.55801861836022 {106.64535522461,26.654289245605 true} 2024-08-20 13:39:03}  插入时间点: 2024-09-25 13:12:39
-2024/09/26 sn: 2023477814765836 连续报警补漏数据: {1 136149 2024-09-25 13:42:39 25.775616978620924 45.60865446909313 {106.64535522461,26.654289245605 true} 2024-08-20 13:39:03}  插入时间点: 2024-09-25 13:42:39
-2024/09/26 sn: 2023477814765836 连续报警补漏数据: {1 136149 2024-09-25 14:12:39 25.886088510887067 45.453480934533864 {106.64535522461,26.654289245605 true} 2024-08-20 13:39:03}  插入时间点: 2024-09-25 14:12:39
-2024/09/26 sn: 2023477814765836 连续报警补漏数据: {1 136149 2024-09-25 14:42:39 25.769305736851056 45.506668188495226 {106.64535522461,26.654289245605 true} 2024-08-20 13:39:03}  插入时间点: 2024-09-25 14:42:39
-2024/09/26 sn: 2023477814765836 连续报警补漏数据: {1 136149 2024-09-25 15:12:39 25.860119062180342 45.56004234956082 {106.64535522461,26.654289245605 true} 2024-08-20 13:39:03}  插入时间点: 2024-09-25 15:12:39
-2024/09/26 sn: 2023477814765836 连续报警补漏数据: {1 136149 2024-09-25 13:12:58 25.745954679267623 45.53408929810416 {106.64535522461,26.654289245605 true} 2024-08-20 13:39:03}  插入时间点: 2024-09-25 13:12:58
-2024/09/26 sn: 2023477814765836 连续报警补漏数据: {1 136149 2024-09-25 13:10:59 25.79277026267128 45.599997854531296 {106.64535522461,26.654289245605 true} 2024-08-20 13:39:03}  插入时间点: 2024-09-25 13:10:59
-2024/09/26 sn: 2023477814765836 连续报警补漏数据: {1 136149 2024-09-25 13:12:39 25.725944162029542 45.47242507764767 {106.64535522461,26.654289245605 true} 2024-08-20 13:39:03}  插入时间点: 2024-09-25 13:12:39
-2024/09/26 sn: 2023477814765836 连续报警补漏数据: {1 136149 2024-09-25 13:12:58 25.845183743054562 45.40252760911536 {106.64535522461,26.654289245605 true} 2024-08-20 13:39:03}  插入时间点: 2024-09-25 13:12:58
-2024/09/26 sn: 2023477814765836 连续报警补漏数据: {1 136149 2024-09-25 13:10:59 25.764410558343396 45.43372358918089 {106.64535522461,26.654289245605 true} 2024-08-20 13:39:03}  插入时间点: 2024-09-25 13:10:59
-2024/09/26 sn: 2023477814765836 连续报警补漏数据: {1 136149 2024-09-25 13:12:58 25.883996999005003 45.697934100997664 {106.64535522461,26.654289245605 true} 2024-08-20 13:39:03}  插入时间点: 2024-09-25 13:12:58
-2024/09/26 sn: 2023477814765836 连续报警补漏数据: {1 136149 2024-09-25 13:12:39 25.79258751847078 45.432709017768374 {106.64535522461,26.654289245605 true} 2024-08-20 13:39:03}  插入时间点: 2024-09-25 13:12:39
-2024/09/26 sn: 2023477814765836 连续报警补漏数据: {1 136149 2024-09-25 13:10:59 25.60132905342124 45.48645684178921 {106.64535522461,26.654289245605 true} 2024-08-20 13:39:03}  插入时间点: 2024-09-25 13:10:59
-2024/09/26 sn: 2023477814765836 连续报警补漏数据: {1 136149 2024-09-25 13:12:58 25.72564903293349 45.38510759603772 {106.64535522461,26.654289245605 true} 2024-08-20 13:39:03}  插入时间点: 2024-09-25 13:12:58
-2024/09/26 sn: 2023477814765836 连续报警补漏数据: {1 136149 2024-09-25 13:12:39 25.85832909951638 45.67009774214352 {106.64535522461,26.654289245605 true} 2024-08-20 13:39:03}  插入时间点: 2024-09-25 13:12:39
-2024/09/26 sn: 2023477814765836 连续报警补漏数据: {1 136149 2024-09-25 13:42:39 25.74836589098745 45.65463925456853 {106.64535522461,26.654289245605 true} 2024-08-20 13:39:03}  插入时间点: 2024-09-25 13:42:39
-2024/09/26 sn: 2023477814765836 连续报警补漏数据: {1 136149 2024-09-25 14:12:39 25.815043822545046 45.360689367490394 {106.64535522461,26.654289245605 true} 2024-08-20 13:39:03}  插入时间点: 2024-09-25 14:12:39
-2024/09/26 sn: 2023477814765836 连续报警补漏数据: {1 136149 2024-09-25 14:42:39 25.671999222605283 45.59842291565161 {106.64535522461,26.654289245605 true} 2024-08-20 13:39:03}  插入时间点: 2024-09-25 14:42:39

+ 38 - 33
service/test.go

@@ -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) {