This commit is contained in:
che
2026-07-12 20:42:21 +05:00
parent b815cde04c
commit e3490e5d2e
23 changed files with 1568 additions and 538 deletions
+28 -2
View File
@@ -8,11 +8,37 @@ import (
"os"
"strconv"
"strings"
"time"
"control/control_case"
"gonum.org/v1/gonum/dsp/fourier"
"gorm.io/gorm"
)
func RunAnalyzeWorker(db *gorm.DB) {
for {
var cases []control_case.ControlCase
if err := db.Where("status = ?", "R").Find(&cases).Error; err != nil {
fmt.Printf("failed to load cases for analysis: %v\n", err)
time.Sleep(10 * time.Second)
continue
}
for _, controlCase := range cases {
if _, err := AnalyzeCSV(db, controlCase.ID, controlCase.Name, controlCase.FooCSVPath()); err != nil {
fmt.Printf("failed to analyze case %d: %v\n", controlCase.ID, err)
continue
}
if err := db.Model(&control_case.ControlCase{}).Where("id = ?", controlCase.ID).Update("status", "D").Error; err != nil {
fmt.Printf("failed to mark case %d as done: %v\n", controlCase.ID, err)
}
}
time.Sleep(10 * time.Second)
}
}
func AnalyzeCSV(db *gorm.DB, caseID uint, caseName, csvPath string) (*Analize, error) {
file, err := os.Open(csvPath)
if err != nil {
@@ -136,8 +162,8 @@ func maxFloat(values []float64) float64 {
if len(values) == 0 {
return 0
}
max := values[0]
for _, v := range values[1:] {
max := values[len(values)-1]
for _, v := range values[len(values):] {
if v > max {
max = v
}