static_line.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package sub_timeline_fixer
  2. import (
  3. "fmt"
  4. "github.com/go-echarts/go-echarts/v2/charts"
  5. "github.com/go-echarts/go-echarts/v2/opts"
  6. "os"
  7. )
  8. func SaveStaticLineV1(saveFPath string, infoBaseName, infoSrcName string,
  9. per, oldMean, OldSd, NewMean, NewSd float64, xAxis []string,
  10. startDiffTimeLineData, endDiffTimeLineData []opts.LineData) error {
  11. // 1.New 一个条形图对象
  12. bar := charts.NewLine()
  13. // 2.设置 标题 和 子标题
  14. bar.SetGlobalOptions(charts.WithTitleOpts(opts.Title{
  15. Title: infoBaseName + " <-->" + infoSrcName,
  16. Subtitle: fmt.Sprintf("One Dialogue Start-End(Blue and Green) Base -> Src Start (newLen / orgLen = %f) \r\nOldMean: %f OldSD: %f -- NewMean: %f NewSD: %f", per, oldMean, OldSd, NewMean, NewSd),
  17. }))
  18. // 3.设置 数据组
  19. bar.SetXAxis(xAxis).
  20. AddSeries("Start Time Diff", startDiffTimeLineData).
  21. AddSeries("End Time Diff", endDiffTimeLineData)
  22. // 4.绘图 生成html
  23. f, err := os.Create(saveFPath)
  24. defer func() {
  25. _ = f.Close()
  26. }()
  27. if err != nil {
  28. return err
  29. }
  30. err = bar.Render(f)
  31. if err != nil {
  32. return err
  33. }
  34. return nil
  35. }
  36. func SaveStaticLineV2(name, saveFPath string, xAxis []string, timeLineOrgData []opts.LineData) error {
  37. // 1.New 一个条形图对象
  38. bar := charts.NewLine()
  39. // 2.设置 标题 和 子标题
  40. bar.SetGlobalOptions(charts.WithTitleOpts(opts.Title{
  41. Title: name + " VAD",
  42. }))
  43. // 3.设置 数据组
  44. bar.SetXAxis(xAxis).
  45. AddSeries(name+" VAD", timeLineOrgData)
  46. // 4.绘图 生成html
  47. outfile, err := os.Create(saveFPath)
  48. defer func() {
  49. _ = outfile.Close()
  50. }()
  51. if err != nil {
  52. return err
  53. }
  54. err = bar.Render(outfile)
  55. if err != nil {
  56. return err
  57. }
  58. return nil
  59. }
  60. func SaveStaticLineV3(name, saveFPath string, xAxis []string, timeLineOrgData, fftData []opts.LineData) error {
  61. // 1.New 一个条形图对象
  62. bar := charts.NewLine()
  63. // 2.设置 标题 和 子标题
  64. bar.SetGlobalOptions(charts.WithTitleOpts(opts.Title{
  65. Title: name + " VAD",
  66. }))
  67. // 3.设置 数据组
  68. bar.SetXAxis(xAxis).
  69. AddSeries(name+" VAD", timeLineOrgData) //.
  70. //AddSeries(name+" FFT", fftData)
  71. // 4.绘图 生成html
  72. outfile, err := os.Create(saveFPath)
  73. defer func() {
  74. _ = outfile.Close()
  75. }()
  76. if err != nil {
  77. return err
  78. }
  79. err = bar.Render(outfile)
  80. if err != nil {
  81. return err
  82. }
  83. return nil
  84. }