浏览代码

wip:新增五天访问三级页 和 曾访问过剑鱼标签

wkyuer 6 月之前
父节点
当前提交
13a082794f
共有 3 个文件被更改,包括 49 次插入6 次删除
  1. 12 0
      userSign/main.go
  2. 9 6
      userSign/userAnalysis/analysisManager.go
  3. 28 0
      userSign/userAnalysis/jobLogsAnalysis.go

+ 12 - 0
userSign/main.go

@@ -73,6 +73,18 @@ func runOnce(ctx context.Context) {
 			allRes = append(allRes, &userAnalysis.AnalysisRes{Name: fmt.Sprintf("%d天活跃用户", day), Code: fmt.Sprintf("active_%d", day), Data: res})
 		}
 	}
+	// 近7天访问详情页次数大于5
+	var (
+		dayLimit     = 7
+		articleLimit = 5
+	)
+	if res, err := manager.ArticleVisit(ctx, nowTime.AddDate(0, 0, -dayLimit), articleLimit); err == nil && len(res) > 0 {
+		allRes = append(allRes, &userAnalysis.AnalysisRes{Name: fmt.Sprintf("%d天内访问详情页次数大于%d次", dayLimit, articleLimit), Code: fmt.Sprintf("%dday_article_gt_%d", dayLimit, articleLimit), Data: res})
+	}
+	// 已访问过
+	if res, err := manager.Visited(ctx, nowTime.AddDate(0, 0, -7)); err == nil && len(res) > 0 {
+		allRes = append(allRes, &userAnalysis.AnalysisRes{Name: "访问过剑鱼产品", Code: "visited", Data: res, SaveOldData: true})
+	}
 
 	for _, re := range allRes {
 		re.UpdateTag(ctx)

+ 9 - 6
userSign/userAnalysis/analysisManager.go

@@ -26,8 +26,9 @@ type (
 	BaseUserId int64
 
 	AnalysisRes struct {
-		Name, Code string              //标签名字
-		Data       map[BaseUserId]bool //数据
+		Name, Code  string              //标签名字
+		Data        map[BaseUserId]bool //数据
+		SaveOldData bool                //累计统计时需要设置为true 是否保留旧数据
 	}
 )
 
@@ -57,13 +58,15 @@ func (ar *AnalysisRes) UpdateTag(ctx context.Context) {
 	}
 
 	if len(updateBatch) == 0 {
-		execSql := fmt.Sprintf(`ALTER TABLE dwd_d_tag UPDATE bitobj = bitmapBuild([toUInt64(0)]) WHERE code = '%v';`, ar.Code)
-		if _, err := g.DB().Exec(ctx, execSql); err != nil {
-			g.Log().Errorf(ctx, "更新标签%s 滞空异常 %v", ar.Code, err)
+		if !ar.SaveOldData {
+			execSql := fmt.Sprintf(`ALTER TABLE dwd_d_tag UPDATE bitobj = bitmapBuild([toUInt64(0)]) WHERE code = '%v';`, ar.Code)
+			if _, err := g.DB().Exec(ctx, execSql); err != nil {
+				g.Log().Errorf(ctx, "更新标签%s 滞空异常 %v", ar.Code, err)
+			}
 		}
 	} else {
 		for i, batch := range updateBatch {
-			if i == 0 {
+			if i == 0 && !ar.SaveOldData {
 				execSql := fmt.Sprintf(`ALTER TABLE dwd_d_tag UPDATE bitobj = bitmapBuild([%v]) WHERE code = '%v';`, strings.Join(batch, ","), ar.Code)
 				if _, err := g.DB().Exec(ctx, execSql); err != nil {
 					g.Log().Errorf(ctx, "更新标签%s [%d]异常 %v", ar.Code, i, err)

+ 28 - 0
userSign/userAnalysis/jobLogsAnalysis.go

@@ -55,3 +55,31 @@ func (ua *UserAnalysis) UnActiveUserLoad(ctx context.Context, start time.Time) (
 	}
 	return unActiveUser, nil
 }
+
+// ArticleVisit 指定时间内访问详情页数量大于num次的用户
+func (ua *UserAnalysis) ArticleVisit(ctx context.Context, start time.Time, num int) (map[BaseUserId]bool, error) {
+	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>?`, start.Format(time.DateTime), num)
+	if err != nil {
+		return nil, err
+	}
+	articleUser := map[BaseUserId]bool{}
+	for _, m := range rPc.List() {
+		// 插入pc30天活跃用户
+		articleUser[BaseUserId(gconv.Int64(m["baseUserId"]))] = true
+	}
+	return articleUser, nil
+}
+
+// Visited 指定日期内访问过剑鱼
+func (ua *UserAnalysis) Visited(ctx context.Context, start time.Time) (map[BaseUserId]bool, error) {
+	rPc, err := g.DB().Query(ctx, `SELECT sum(article)+sum(search)+sum(portrait)+sum(other) as allCount,baseUserId FROM pub_tags.user_log_byHour WHERE create_time >? GROUP BY  baseUserId`, start.Format(time.DateTime))
+	if err != nil {
+		return nil, err
+	}
+	visitedUser := map[BaseUserId]bool{}
+	for _, m := range rPc.List() {
+		// 插入pc30天活跃用户
+		visitedUser[BaseUserId(gconv.Int64(m["baseUserId"]))] = true
+	}
+	return visitedUser, nil
+}