|
@@ -20,20 +20,14 @@ func GetNewActiveUser(st, ed time.Time) []*NewActiveMsg {
|
|
ctx context.Context
|
|
ctx context.Context
|
|
)
|
|
)
|
|
stYear, stMonth, stDay := st.Date()
|
|
stYear, stMonth, stDay := st.Date()
|
|
- edYear, edMonth, edDay := ed.Date()
|
|
|
|
|
|
+ _, edMonth, edDay := ed.Date()
|
|
nst := st.AddDate(0, -1, 0)
|
|
nst := st.AddDate(0, -1, 0)
|
|
_, nstMonth, nstDay := nst.Date()
|
|
_, nstMonth, nstDay := nst.Date()
|
|
- var sql, nSql string
|
|
|
|
- if stYear == edYear && stMonth == edMonth && stDay == edDay {
|
|
|
|
- sql = fmt.Sprintf("month = %d and day = %d", int(stMonth), stDay)
|
|
|
|
- } else if stMonth == edMonth {
|
|
|
|
- sql = fmt.Sprintf("month = %d and day >= %d and day <= %d", int(stMonth), stDay, edDay)
|
|
|
|
- } else {
|
|
|
|
- sql = fmt.Sprintf("(month = %d and day >= %d) or (month = %d and day <= %d)", int(stMonth), stDay, int(edMonth), edDay)
|
|
|
|
- }
|
|
|
|
|
|
|
|
//昨天所有活跃用户
|
|
//昨天所有活跃用户
|
|
- res, err := g.DB().Query(ctx, fmt.Sprintf(`SELECT DISTINCT user_mongoid FROM user_countbyhour WHERE %s `, sql))
|
|
|
|
|
|
+ res, err := g.DB("useranaly").Query(ctx, fmt.Sprintf(`SELECT DISTINCT user_mongoid FROM user_countbyhour
|
|
|
|
+WHERE CONCAT(month, '-', day) >= '%s' AND CONCAT(month, '-', day) <= '%s';`, fmt.Sprintf("%d-%d", int(stMonth), stDay), fmt.Sprintf("%d-%d", int(edMonth), edDay)))
|
|
|
|
+ //res, err := g.DB().Query(ctx, fmt.Sprintf(`SELECT DISTINCT user_mongoid FROM user_countbyhour WHERE %s `, sql))
|
|
if err == nil && !res.IsEmpty() {
|
|
if err == nil && !res.IsEmpty() {
|
|
for _, m := range res.List() {
|
|
for _, m := range res.List() {
|
|
mongoid := gconv.String(m["user_mongoid"])
|
|
mongoid := gconv.String(m["user_mongoid"])
|
|
@@ -44,11 +38,6 @@ func GetNewActiveUser(st, ed time.Time) []*NewActiveMsg {
|
|
lock sync.Mutex
|
|
lock sync.Mutex
|
|
data []*NewActiveMsg
|
|
data []*NewActiveMsg
|
|
)
|
|
)
|
|
- if nstMonth == stMonth {
|
|
|
|
- nSql = fmt.Sprintf("month = %d and day >= %d and day < %d", int(stMonth), nstDay, stDay)
|
|
|
|
- } else {
|
|
|
|
- nSql = fmt.Sprintf("((month = %d and day >= %d) or (month = %d and day < %d))", int(nstMonth), nstDay, int(stMonth), stDay)
|
|
|
|
- }
|
|
|
|
pool := make(chan bool, 5)
|
|
pool := make(chan bool, 5)
|
|
wait := &sync.WaitGroup{}
|
|
wait := &sync.WaitGroup{}
|
|
for _, id := range mgoIds {
|
|
for _, id := range mgoIds {
|
|
@@ -59,7 +48,8 @@ func GetNewActiveUser(st, ed time.Time) []*NewActiveMsg {
|
|
wait.Done()
|
|
wait.Done()
|
|
<-pool
|
|
<-pool
|
|
}()
|
|
}()
|
|
- count, _ := g.DB().GetCount(ctx, fmt.Sprintf("user_mongoid = '%s' and %s", mId, nSql))
|
|
|
|
|
|
+ count, _ := g.DB("useranaly").GetCount(ctx, fmt.Sprintf(`SELECT count(1) FROM user_countbyhour
|
|
|
|
+WHERE user_mongoid = '%s' and CONCAT(month, '-', day) >= '%s' AND CONCAT(month, '-', day) < '%s';`, mId, fmt.Sprintf("%d-%d", int(nstMonth), nstDay), fmt.Sprintf("%d-%d", int(stMonth), stDay)))
|
|
if count == 0 { //统计昨天之前30天不活跃用户
|
|
if count == 0 { //统计昨天之前30天不活跃用户
|
|
lock.Lock()
|
|
lock.Lock()
|
|
data = append(data, &NewActiveMsg{
|
|
data = append(data, &NewActiveMsg{
|