feat: survey 分析记录支持通过 GetTime 函数获取记录时间

This commit is contained in:
kercylan98 2023-09-08 20:14:43 +08:00
parent 19df61b97f
commit 3c3dc83830
2 changed files with 25 additions and 1 deletions

View File

@ -1,6 +1,10 @@
package survey
import "github.com/tidwall/gjson"
import (
"github.com/kercylan98/minotaur/utils/times"
"github.com/tidwall/gjson"
"time"
)
type (
Result = gjson.Result
@ -9,6 +13,11 @@ type (
// R 记录器所记录的一条数据
type R string
// GetTime 获取该记录的时间
func (slf R) GetTime(layout string) time.Time {
return times.GetTimeFromString(string(slf)[:len(layout)], layout)
}
// Get 获取指定 key 的值
// - 当 key 为嵌套 key 时,使用 . 进行分割例如a.b.c
// - 更多用法参考https://github.com/tidwall/gjson

View File

@ -127,3 +127,18 @@ func Analyze(filePath string, handle func(analyzer *Analyzer, record R)) *Report
return newReport(analyzer)
}
// AnalyzeMulti 与 Analyze 类似,但是可以分析多个文件
func AnalyzeMulti(filePaths []string, handle func(analyzer *Analyzer, record R)) *Report {
analyzer := new(Analyzer)
for _, filePath := range filePaths {
err := file.ReadLineWithParallel(filePath, 1*1024*1024*1024, func(s string) {
handle(analyzer, R(s))
})
if err != nil {
panic(err)
}
}
return newReport(analyzer)
}