From 87cba441649ab2f354e1ab189fcddddb528cea8c Mon Sep 17 00:00:00 2001 From: "lilong.129" Date: Wed, 3 May 2023 23:51:03 +0800 Subject: [PATCH] feat: check target achieving for each feed type --- .../uitest/demo_android_video_crawler.json | 1 + .../uitest/demo_android_video_crawler_test.go | 2 +- hrp/pkg/uixt/video_crawler.go | 67 ++++++++++++++----- 3 files changed, 54 insertions(+), 16 deletions(-) diff --git a/examples/uitest/demo_android_video_crawler.json b/examples/uitest/demo_android_video_crawler.json index 41b00b01..356d62e6 100644 --- a/examples/uitest/demo_android_video_crawler.json +++ b/examples/uitest/demo_android_video_crawler.json @@ -38,6 +38,7 @@ 1, 1 ], + "target": 2, "text": "^广告$" }, { diff --git a/examples/uitest/demo_android_video_crawler_test.go b/examples/uitest/demo_android_video_crawler_test.go index 897f901e..4cda04b3 100644 --- a/examples/uitest/demo_android_video_crawler_test.go +++ b/examples/uitest/demo_android_video_crawler_test.go @@ -25,7 +25,7 @@ func TestAndroidVideoCrawlerTest(t *testing.T) { "feed": map[string]interface{}{ "target_count": 5, "target_labels": []map[string]interface{}{ - {"text": "^广告$", "scope": []float64{0, 0.5, 1, 1}, "regex": true}, + {"text": "^广告$", "scope": []float64{0, 0.5, 1, 1}, "regex": true, "target": 2}, {"text": "^图文$", "scope": []float64{0, 0.5, 1, 1}, "regex": true}, {"text": `^特效\|`, "scope": []float64{0, 0.5, 1, 1}, "regex": true}, {"text": `^模板\|`, "scope": []float64{0, 0.5, 1, 1}, "regex": true}, diff --git a/hrp/pkg/uixt/video_crawler.go b/hrp/pkg/uixt/video_crawler.go index 169f208a..11237ad6 100644 --- a/hrp/pkg/uixt/video_crawler.go +++ b/hrp/pkg/uixt/video_crawler.go @@ -22,23 +22,59 @@ type VideoStat struct { } func (s *VideoStat) isFeedTargetAchieved() bool { - log.Info(). - Int("count", s.FeedCount). - Interface("stat", s.FeedStat). - Int("target", s.configs.Feed.TargetCount). - Msg("current feed count") + targetStat := make(map[string]int) + for _, targetLabel := range s.configs.Feed.TargetLabels { + targetStat[targetLabel.Text] = targetLabel.Target + } - return s.FeedCount >= s.configs.Feed.TargetCount + log.Info(). + Int("current_total", s.FeedCount). + Interface("current_stat", s.FeedStat). + Int("target_total", s.configs.Feed.TargetCount). + Interface("target_stat", targetStat). + Msg("display feed crawler progress") + + // check total feed count + if s.FeedCount < s.configs.Feed.TargetCount { + return false + } + + // check each feed type's count + for _, targetLabel := range s.configs.Feed.TargetLabels { + if s.FeedStat[targetLabel.Text] < targetLabel.Target { + return false + } + } + + return true } func (s *VideoStat) isLiveTargetAchieved() bool { - log.Info(). - Int("count", s.LiveCount). - Interface("stat", s.FeedStat). - Int("target", s.configs.Live.TargetCount). - Msg("current live count") + targetStat := make(map[string]int) + for _, targetLabel := range s.configs.Live.TargetLabels { + targetStat[targetLabel.Text] = targetLabel.Target + } - return s.LiveCount >= s.configs.Live.TargetCount + log.Info(). + Int("current_total", s.LiveCount). + Interface("current_stat", s.LiveStat). + Int("target_total", s.configs.Live.TargetCount). + Interface("target_stat", targetStat). + Msg("display live crawler progress") + + // check total live count + if s.LiveCount < s.configs.Live.TargetCount { + return false + } + + // check each live type's count + for _, targetLabel := range s.configs.Live.TargetLabels { + if s.LiveStat[targetLabel.Text] < targetLabel.Target { + return false + } + } + + return true } func (s *VideoStat) isTargetAchieved() bool { @@ -79,9 +115,10 @@ func (s *VideoStat) incrFeed(texts OCRTexts, driverExt *DriverExt) error { } type TargetLabel struct { - Text string `json:"text"` - Scope Scope `json:"scope"` - Regex bool `json:"regex"` + Text string `json:"text"` + Scope Scope `json:"scope"` + Regex bool `json:"regex"` + Target int `json:"target"` // target count for current label } type FeedConfig struct {