mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-10 23:12:41 +08:00
feat: check target achieving for each feed type
This commit is contained in:
@@ -38,6 +38,7 @@
|
|||||||
1,
|
1,
|
||||||
1
|
1
|
||||||
],
|
],
|
||||||
|
"target": 2,
|
||||||
"text": "^广告$"
|
"text": "^广告$"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ func TestAndroidVideoCrawlerTest(t *testing.T) {
|
|||||||
"feed": map[string]interface{}{
|
"feed": map[string]interface{}{
|
||||||
"target_count": 5,
|
"target_count": 5,
|
||||||
"target_labels": []map[string]interface{}{
|
"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},
|
{"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},
|
||||||
|
|||||||
@@ -22,23 +22,59 @@ type VideoStat struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *VideoStat) isFeedTargetAchieved() bool {
|
func (s *VideoStat) isFeedTargetAchieved() bool {
|
||||||
log.Info().
|
targetStat := make(map[string]int)
|
||||||
Int("count", s.FeedCount).
|
for _, targetLabel := range s.configs.Feed.TargetLabels {
|
||||||
Interface("stat", s.FeedStat).
|
targetStat[targetLabel.Text] = targetLabel.Target
|
||||||
Int("target", s.configs.Feed.TargetCount).
|
}
|
||||||
Msg("current feed count")
|
|
||||||
|
|
||||||
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 {
|
func (s *VideoStat) isLiveTargetAchieved() bool {
|
||||||
log.Info().
|
targetStat := make(map[string]int)
|
||||||
Int("count", s.LiveCount).
|
for _, targetLabel := range s.configs.Live.TargetLabels {
|
||||||
Interface("stat", s.FeedStat).
|
targetStat[targetLabel.Text] = targetLabel.Target
|
||||||
Int("target", s.configs.Live.TargetCount).
|
}
|
||||||
Msg("current live count")
|
|
||||||
|
|
||||||
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 {
|
func (s *VideoStat) isTargetAchieved() bool {
|
||||||
@@ -79,9 +115,10 @@ func (s *VideoStat) incrFeed(texts OCRTexts, driverExt *DriverExt) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type TargetLabel struct {
|
type TargetLabel struct {
|
||||||
Text string `json:"text"`
|
Text string `json:"text"`
|
||||||
Scope Scope `json:"scope"`
|
Scope Scope `json:"scope"`
|
||||||
Regex bool `json:"regex"`
|
Regex bool `json:"regex"`
|
||||||
|
Target int `json:"target"` // target count for current label
|
||||||
}
|
}
|
||||||
|
|
||||||
type FeedConfig struct {
|
type FeedConfig struct {
|
||||||
|
|||||||
Reference in New Issue
Block a user