debug_view.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package debug_view
  2. import (
  3. "fmt"
  4. "github.com/allanpk716/ChineseSubFinder/internal/pkg/global_value"
  5. "github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_helper"
  6. "github.com/allanpk716/ChineseSubFinder/internal/pkg/vad"
  7. "github.com/go-echarts/go-echarts/v2/charts"
  8. "github.com/go-echarts/go-echarts/v2/opts"
  9. "os"
  10. "path/filepath"
  11. )
  12. func SaveDebugChart(subUnit sub_helper.SubUnit, title, subTitle string) error {
  13. return SaveDebugChartBase(subUnit.VADList, title, subTitle)
  14. }
  15. func SaveDebugChartBase(vadList []vad.VADInfo, title, subTitle string) error {
  16. line := charts.NewBar()
  17. line.SetGlobalOptions(charts.WithTitleOpts(opts.Title{
  18. Title: title,
  19. Subtitle: subTitle,
  20. }))
  21. // 构建 X 轴
  22. xAxis := make([]string, len(vadList))
  23. for i := 0; i < len(vadList); i++ {
  24. xAxis[i] = fmt.Sprintf("%d", i)
  25. }
  26. lineData := make([]opts.BarData, len(vadList))
  27. for i := 0; i < len(vadList); i++ {
  28. value := -1
  29. if vadList[i].Active == true {
  30. value = 1
  31. }
  32. lineData[i] = opts.BarData{Value: value}
  33. }
  34. // Put data into instance
  35. line.SetXAxis(xAxis).
  36. AddSeries("VAD", lineData)
  37. // Where the magic happens
  38. f, err := os.Create(filepath.Join(global_value.DefDebugFolder, title+".html"))
  39. if err != nil {
  40. return err
  41. }
  42. defer f.Close()
  43. return line.Render(f)
  44. }