feat: check target achieving for each feed type

This commit is contained in:
lilong.129
2023-05-03 23:51:03 +08:00
parent 94462c48bb
commit 87cba44164
3 changed files with 54 additions and 16 deletions

View File

@@ -38,6 +38,7 @@
1,
1
],
"target": 2,
"text": "^广告$"
},
{

View File

@@ -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},

View File

@@ -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 {