|
@@ -33,7 +33,10 @@ func (ua *UserAnalysis) GetAnalysisLogRes(ctx context.Context, runTime time.Time
|
|
|
}
|
|
|
|
|
|
//标讯详情页访问
|
|
|
- if res, err := ua.ArticleVisit(ctx, runTime.AddDate(0, 0, -7)); err == nil && len(res) > 0 {
|
|
|
+ if res, err := ua.ArticleVisit(ctx, runTime, 7, []int{5}, []int{7, 10, 15, 20}); err == nil && len(res) > 0 {
|
|
|
+ returnData = append(returnData, res...)
|
|
|
+ }
|
|
|
+ if res, err := ua.ArticleVisit(ctx, runTime, 3, []int{}, []int{5}); err == nil && len(res) > 0 {
|
|
|
returnData = append(returnData, res...)
|
|
|
}
|
|
|
if res, err := ua.SearchVisit(ctx, runTime.AddDate(0, 0, -7)); err == nil && len(res) > 0 {
|
|
@@ -109,47 +112,61 @@ func (ua *UserAnalysis) ActiveDayNum(ctx context.Context, runTime time.Time, day
|
|
|
}
|
|
|
|
|
|
// ArticleVisit 指定时间内访问详情页数量大于num次的用户
|
|
|
-func (ua *UserAnalysis) ArticleVisit(ctx context.Context, start time.Time) ([]*AnalysisRes, error) {
|
|
|
+func (ua *UserAnalysis) ArticleVisit(ctx context.Context, runTime time.Time, dayNum int, gt, gte []int) ([]*AnalysisRes, error) {
|
|
|
var (
|
|
|
- d1, d2, d3 = map[BaseUserId]bool{}, map[BaseUserId]bool{}, map[BaseUserId]bool{}
|
|
|
- d4, d5 = map[BaseUserId]bool{}, map[BaseUserId]bool{}
|
|
|
+ staticGtMap = map[int]map[BaseUserId]bool{}
|
|
|
+ staticGteMap = map[int]map[BaseUserId]bool{}
|
|
|
+
|
|
|
+ result = []*AnalysisRes{}
|
|
|
)
|
|
|
+ for _, num := range gt {
|
|
|
+ staticGtMap[num] = map[BaseUserId]bool{}
|
|
|
+ }
|
|
|
+ for _, num := range gte {
|
|
|
+ staticGteMap[num] = map[BaseUserId]bool{}
|
|
|
+ }
|
|
|
|
|
|
- rPc, err := g.DB().Query(ctx, `SELECT sum(article) as articleCount,baseUserId FROM pub_tags.user_log_byHour WHERE create_time > ? GROUP BY baseUserId HAVING articleCount >5 `, start.Format(time.DateTime))
|
|
|
+ rPc, err := g.DB().Query(ctx, `SELECT sum(article) as articleCount,baseUserId FROM pub_tags.user_log_byHour WHERE create_time > ? GROUP BY baseUserId HAVING articleCount >5 `, runTime.AddDate(0, 0, -dayNum).Format(time.DateTime))
|
|
|
if err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
for _, m := range rPc.List() {
|
|
|
var (
|
|
|
baseUserId = BaseUserId(gconv.Int64(m["baseUserId"]))
|
|
|
- count = gconv.Int64(m["articleCount"])
|
|
|
+ count = gconv.Int(m["articleCount"])
|
|
|
)
|
|
|
if baseUserId <= 0 {
|
|
|
continue
|
|
|
}
|
|
|
- if count > 5 {
|
|
|
- d1[baseUserId] = true
|
|
|
- }
|
|
|
- if count >= 7 {
|
|
|
- d2[baseUserId] = true
|
|
|
- }
|
|
|
- if count >= 10 {
|
|
|
- d3[baseUserId] = true
|
|
|
- }
|
|
|
- if count >= 15 {
|
|
|
- d4[baseUserId] = true
|
|
|
+ for num, v := range staticGtMap {
|
|
|
+ if count > num {
|
|
|
+ v[baseUserId] = true
|
|
|
+ }
|
|
|
}
|
|
|
- if count >= 20 {
|
|
|
- d5[baseUserId] = true
|
|
|
+
|
|
|
+ for num, v := range staticGteMap {
|
|
|
+ if count >= num {
|
|
|
+ v[baseUserId] = true
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- return []*AnalysisRes{
|
|
|
- {"7天内访问详情页次数>5", "7day_article_gt_5", d1, false},
|
|
|
- {"7天内访问详情页次数>=7", "7day_article_gte_7", d2, false},
|
|
|
- {"7天内访问详情页次数>=10", "7day_article_gte_10", d3, false},
|
|
|
- {"7天内访问详情页次数>=15", "7day_article_gte_15", d4, false},
|
|
|
- {"7天内访问详情页次数>=20", "7day_article_gte_20", d5, false},
|
|
|
- }, nil
|
|
|
+ for i, i2 := range staticGtMap {
|
|
|
+ result = append(result, &AnalysisRes{
|
|
|
+ Name: fmt.Sprintf("%d天内访问详情页次数>%d", dayNum, i),
|
|
|
+ Code: fmt.Sprintf("%dday_article_gt_%d", dayNum, i),
|
|
|
+ Data: i2,
|
|
|
+ SaveOldData: false,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ for i, i2 := range staticGteMap {
|
|
|
+ result = append(result, &AnalysisRes{
|
|
|
+ Name: fmt.Sprintf("%d天内访问详情页次数>=%d", dayNum, i),
|
|
|
+ Code: fmt.Sprintf("%dday_article_gte_%d", dayNum, i),
|
|
|
+ Data: i2,
|
|
|
+ SaveOldData: false,
|
|
|
+ })
|
|
|
+ }
|
|
|
+ return result, nil
|
|
|
}
|
|
|
|
|
|
func (ua *UserAnalysis) SearchVisit(ctx context.Context, start time.Time) ([]*AnalysisRes, error) {
|