ssa
1package tg2
3import (4"bufio"5"fmt"6"log"7"os"8"strconv"9"strings"10"testing"11
12"github.com/RB-PRO/ssa/pkg/movmean"13"github.com/RB-PRO/ssa/pkg/oss"14"github.com/RB-PRO/ssa/pkg/ssa"15)
16
17func TestPlot(t *testing.T) {18createLineChart([]float64{1, 2, 3, 4, 5}, []float64{2, 3, 4, 5, 6}, "Sample.png")19}
20
21func TestSSA_tgbot(t *testing.T) {22Folder := "..\\..\\TelegramVideoNote/test/"23pw, _ := oss.Make_singnal_xn(Folder + "pw")24SSA_tgbot(Folder, pw)25}
26
27func TestPW(t *testing.T) {28RGBs := LoadRGB("..\\..\\TelegramVideoNote/test/RGBTEST.txt")29pw, _ := CalcPW(RGBs, "..\\..\\TelegramVideoNote/test/")30createLineChart([]float64{}, pw, "..\\..\\TelegramVideoNote/test/"+"pw.png")31}
32func LoadTXT(FileName string) []float64 {33var data []float6434file, err := os.Open(FileName)35if err != nil {36log.Fatal(err)37}38defer file.Close()39
40scanner := bufio.NewScanner(file)41// optionally, resize scanner's capacity for lines over 64K, see next example42for scanner.Scan() {43fl, _ := strconv.ParseFloat(scanner.Text(), 64)44data = append(data, fl)45}46if err := scanner.Err(); err != nil {47panic(err)48}49return data50}
51func LoadRGB(FileName string) []RGB_float64 {52var RGBs []RGB_float6453file, err := os.Open(FileName)54if err != nil {55log.Fatal(err)56}57defer file.Close()58
59scanner := bufio.NewScanner(file)60// optionally, resize scanner's capacity for lines over 64K, see next example61for scanner.Scan() {62str := scanner.Text()63strs := strings.Split(str, ";")64if len(strs) == 3 {65R, _ := strconv.ParseFloat(strs[0], 64)66G, _ := strconv.ParseFloat(strs[1], 64)67B, _ := strconv.ParseFloat(strs[2], 64)68RGBs = append(RGBs, RGB_float64{69R: R,70G: G,71B: B,72})73}74}75if err := scanner.Err(); err != nil {76panic(err)77}78return RGBs79}
80
81func TestSSA(t *testing.T) {82var pw []float6483file, err := os.Open("..\\..\\TelegramVideoNote/test/pw.txt")84if err != nil {85log.Fatal(err)86}87defer file.Close()88
89scanner := bufio.NewScanner(file)90// optionally, resize scanner's capacity for lines over 64K, see next example91for scanner.Scan() {92str := scanner.Text()93strfloat64, _ := strconv.ParseFloat(str, 64)94pw = append(pw, strfloat64)95}96if err := scanner.Err(); err != nil {97t.Error(err)98}99
100SSA_tgbot("..\\..\\TelegramVideoNote/test/", pw)101}
102
103func TestMedianFilter(t *testing.T) {104x := []float64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10} // Пример входных данных105n := 3 // Порядок фильтра106result := medianFilter(x, n) // Применение медианного фильтра107fmt.Println(result) // Вывод результата108}
109
110func TestExtractRGB(t *testing.T) {111RGBs, errRGB := ExtractRGB("..\\..\\TelegramVideoNote/test/", "huawei.mp4")112if errRGB != nil {113t.Error(errRGB)114}115fmt.Println("len(RGBs)", len(RGBs))116}
117
118func TestButter(t *testing.T) {119FileName := "EUT_P1H1_RGB.txt"120FileName = strings.ReplaceAll(FileName, ".avi", "")121FileName = strings.ReplaceAll(FileName, ".txt", "")122FileName = strings.ReplaceAll(FileName, "_RGB", "")123FileName = strings.ReplaceAll(FileName, "_pw", "")124FileName = strings.ReplaceAll(FileName, "_but", "")125Folder := "tests/"126
127// RGB128// RGB, _ := ExtractRGB(Folder, FileName+".avi")129// RGB := LoadRGB(Folder + FileName + ".txt")130// Butter131// RGB_but := Butter(RGB)132// SaveRGB(Folder+FileName+"_but.txt", RGB_but)133// RGB2s := LoadRGB(Folder + FileName + ".txt")134RGB := LoadRGB(Folder + FileName + "_RGB" + ".txt")135// // PW136pw, ErrPW := CalcPW(RGB, Folder)137if ErrPW != nil {138t.Error(ErrPW)139}140pw, _ = movmean.Movmean(pw, 5)141// SaveTXT(Folder+FileName+"_pw.txt", pw)142// pw = LoadTXT(Folder + "tg10" + "_pw.txt")143
144SSS_spw2(pw, []float64{})145
146// Частоты147
148// ssaAnalis, ErrNewSSA := ssa2.NewSSA(pw, ssa2.Setup{149// Cad: 30, Win: 1024, NPart: 20,150// FMi: 40.0 / 60.0, FMa: 240.0 / 60.0,151// })152// if ErrNewSSA != nil {153// t.Error(ErrNewSSA)154// }155// ssaAnalis.Col()156// ssaAnalis.SpwEstimation()157// ssaAnalis.PwEstimation()158// ssa2.CreateLineChart(ssaAnalis.Pto_fMAX, Folder+"pto.png")159}
160
161func SSS_spw2(pw, fmp []float64) {162s := ssa.New("File")163s.Graph = true // Создавать графики164s.Xlsx = true // Сохранять в Xlsx165s.Var(pw, fmp)166s.Spw_Form(pw) // Создать spw167
168// # 1, 2, 3, 4169s.SET_Form() // SSA - анализ сегментов pw170
171// # 5172// Оценка АКФ сингулярных троек для сегментов pw173// Визуализация АКФ сингулярных троек для сегментов pw174s.AKF_Form() // Оценка АКФ сингулярных троек для сегментов pw175
176// # 6, 7177// Огибающие АКФ сингулярных троек sET12 сегментов pw178// Нормированные АКФ сингулярных троек sET12 сегментов pw179s.Envelope()180
181// # 8182// Мгновенная частота нормированной АКФ сингулярных троек sET12 для сегментов pw183s.MomentFrequency()184
185// # 9186// Визуализация СПМ сингулярных троек сегменов pw187s.VisibleSPM()188
189// # 10190// Агрегирование сегментов очищенной пульсовой волны cpw191s.AggregationPW()192
193}
194
195// func LoadTXT()
196
197func SaveTXT(FileName string, data []float64) {198filePW, ErrOpenFile := os.Create(FileName)199if ErrOpenFile != nil {200panic(ErrOpenFile)201}202defer filePW.Close()203for i := range data {204if _, err := filePW.WriteString(fmt.Sprintf("%.8f\n", data[i])); err != nil {205log.Println(err)206}207}208}
209func SaveRGB(FileName string, data []RGB_float64) {210filePW, ErrOpenFile := os.Create(FileName)211if ErrOpenFile != nil {212panic(ErrOpenFile)213}214defer filePW.Close()215for i := range data {216if _, err := filePW.WriteString(fmt.Sprintf("%.8f;%.8f;%.8f\n", data[i].R, data[i].G, data[i].B)); err != nil {217log.Println(err)218}219}220}
221