feat: survey 分析记录支持通过 GetTime 函数获取记录时间
This commit is contained in:
parent
19df61b97f
commit
3c3dc83830
|
@ -1,6 +1,10 @@
|
||||||
package survey
|
package survey
|
||||||
|
|
||||||
import "github.com/tidwall/gjson"
|
import (
|
||||||
|
"github.com/kercylan98/minotaur/utils/times"
|
||||||
|
"github.com/tidwall/gjson"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
Result = gjson.Result
|
Result = gjson.Result
|
||||||
|
@ -9,6 +13,11 @@ type (
|
||||||
// R 记录器所记录的一条数据
|
// R 记录器所记录的一条数据
|
||||||
type R string
|
type R string
|
||||||
|
|
||||||
|
// GetTime 获取该记录的时间
|
||||||
|
func (slf R) GetTime(layout string) time.Time {
|
||||||
|
return times.GetTimeFromString(string(slf)[:len(layout)], layout)
|
||||||
|
}
|
||||||
|
|
||||||
// Get 获取指定 key 的值
|
// Get 获取指定 key 的值
|
||||||
// - 当 key 为嵌套 key 时,使用 . 进行分割,例如:a.b.c
|
// - 当 key 为嵌套 key 时,使用 . 进行分割,例如:a.b.c
|
||||||
// - 更多用法参考:https://github.com/tidwall/gjson
|
// - 更多用法参考:https://github.com/tidwall/gjson
|
||||||
|
|
|
@ -127,3 +127,18 @@ func Analyze(filePath string, handle func(analyzer *Analyzer, record R)) *Report
|
||||||
|
|
||||||
return newReport(analyzer)
|
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)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue