Browse Source

提交代码。

Signed-off-by: zouap <zouap@pcl.ac.cn>
tags/v1.22.4.1^2
zouap 3 years ago
parent
commit
26d1df4a0d
3 changed files with 64 additions and 12 deletions
  1. +2
    -0
      models/models.go
  2. +53
    -12
      models/user_business_analysis.go
  3. +9
    -0
      models/user_business_struct.go

+ 2
- 0
models/models.go View File

@@ -151,6 +151,8 @@ func init() {
new(UserBusinessAnalysisCurrentWeek), new(UserBusinessAnalysisCurrentWeek),
new(UserBusinessAnalysisYesterday), new(UserBusinessAnalysisYesterday),
new(UserLoginLog), new(UserLoginLog),
new(UserMetrics),
new(UserAnalysisPara),
) )


gonicNames := []string{"SSL", "UID"} gonicNames := []string{"SSL", "UID"}


+ 53
- 12
models/user_business_analysis.go View File

@@ -378,7 +378,7 @@ func QueryUserStaticDataPage(opts *UserBusinessAnalysisQueryOptions) ([]*UserBus
return userBusinessAnalysisReturnList, count return userBusinessAnalysisReturnList, count
} }


func refreshUserStaticTable(wikiCountMap map[string]int, tableName string, pageStartTime time.Time, pageEndTime time.Time) {
func refreshUserStaticTable(wikiCountMap map[string]int, tableName string, pageStartTime time.Time, pageEndTime time.Time, userMetrics map[string]int) {
sess := x.NewSession() sess := x.NewSession()
defer sess.Close() defer sess.Close()


@@ -481,6 +481,11 @@ func refreshUserStaticTable(wikiCountMap map[string]int, tableName string, pageS
} }
dateRecordBatch = make([]UserBusinessAnalysisAll, 0) dateRecordBatch = make([]UserBusinessAnalysisAll, 0)
} }
if tableName == "user_business_analysis_all" {
if dateRecordAll.UserIndex > 0 || dateRecordAll.LoginCount > 0 {
userMetrics["TotalHasActivityUser"] = getMapKeyStringValue("TotalHasActivityUser", userMetrics) + 1
}
}
} }
indexTotal += PAGE_SIZE indexTotal += PAGE_SIZE
if indexTotal >= count { if indexTotal >= count {
@@ -519,36 +524,36 @@ func insertTable(dateRecords []UserBusinessAnalysisAll, tableName string, static
statictisSess.Exec(insertBatchSql) statictisSess.Exec(insertBatchSql)
} }


func RefreshUserStaticAllTabel(wikiCountMap map[string]int) {
func RefreshUserStaticAllTabel(wikiCountMap map[string]int, userMetrics map[string]int) {
currentTimeNow := time.Now() currentTimeNow := time.Now()
pageStartTime := time.Date(2021, 11, 5, 0, 0, 0, 0, currentTimeNow.Location()) pageStartTime := time.Date(2021, 11, 5, 0, 0, 0, 0, currentTimeNow.Location())
pageEndTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 23, 59, 59, 0, currentTimeNow.Location()) pageEndTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 23, 59, 59, 0, currentTimeNow.Location())
refreshUserStaticTable(wikiCountMap, "user_business_analysis_all", pageStartTime, pageEndTime)
refreshUserStaticTable(wikiCountMap, "user_business_analysis_all", pageStartTime, pageEndTime, userMetrics)
log.Info("refresh all data finished.") log.Info("refresh all data finished.")


pageStartTime = time.Date(currentTimeNow.Year(), 1, 1, 0, 0, 0, 0, currentTimeNow.Location()) pageStartTime = time.Date(currentTimeNow.Year(), 1, 1, 0, 0, 0, 0, currentTimeNow.Location())
refreshUserStaticTable(wikiCountMap, "user_business_analysis_current_year", pageStartTime, pageEndTime)
refreshUserStaticTable(wikiCountMap, "user_business_analysis_current_year", pageStartTime, pageEndTime, userMetrics)


thisMonth := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), 1, 0, 0, 0, 0, currentTimeNow.Location()) thisMonth := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), 1, 0, 0, 0, 0, currentTimeNow.Location())
refreshUserStaticTable(wikiCountMap, "user_business_analysis_current_month", thisMonth, pageEndTime)
refreshUserStaticTable(wikiCountMap, "user_business_analysis_current_month", thisMonth, pageEndTime, userMetrics)


offset := int(time.Monday - currentTimeNow.Weekday()) offset := int(time.Monday - currentTimeNow.Weekday())
if offset > 0 { if offset > 0 {
offset = -6 offset = -6
} }
pageStartTime = time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, offset) pageStartTime = time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, offset)
refreshUserStaticTable(wikiCountMap, "user_business_analysis_current_week", pageStartTime, pageEndTime)
refreshUserStaticTable(wikiCountMap, "user_business_analysis_current_week", pageStartTime, pageEndTime, userMetrics)


pageStartTime = time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, -30) pageStartTime = time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, -30)
refreshUserStaticTable(wikiCountMap, "user_business_analysis_last30_day", pageStartTime, pageEndTime)
refreshUserStaticTable(wikiCountMap, "user_business_analysis_last30_day", pageStartTime, pageEndTime, userMetrics)


pageStartTime = time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, -1) pageStartTime = time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, -1)
pageEndTime = time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 23, 59, 59, 0, currentTimeNow.Location()).AddDate(0, 0, -1) pageEndTime = time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 23, 59, 59, 0, currentTimeNow.Location()).AddDate(0, 0, -1)
refreshUserStaticTable(wikiCountMap, "user_business_analysis_yesterday", pageStartTime, pageEndTime)
refreshUserStaticTable(wikiCountMap, "user_business_analysis_yesterday", pageStartTime, pageEndTime, userMetrics)


pageStartTime = thisMonth.AddDate(0, -1, 0) pageStartTime = thisMonth.AddDate(0, -1, 0)
pageEndTime = time.Date(currentTimeNow.Year(), currentTimeNow.Month(), 1, 23, 59, 59, 0, currentTimeNow.Location()).AddDate(0, 0, -1) pageEndTime = time.Date(currentTimeNow.Year(), currentTimeNow.Month(), 1, 23, 59, 59, 0, currentTimeNow.Location()).AddDate(0, 0, -1)
refreshUserStaticTable(wikiCountMap, "user_business_analysis_last_month", pageStartTime, pageEndTime)
refreshUserStaticTable(wikiCountMap, "user_business_analysis_last_month", pageStartTime, pageEndTime, userMetrics)


} }


@@ -604,7 +609,7 @@ func CounDataByDateAndReCount(wikiCountMap map[string]int, startTime time.Time,
} }


ParaWeight := getParaWeight() ParaWeight := getParaWeight()
userMetrics := make(map[string]int)
var indexTotal int64 var indexTotal int64
indexTotal = 0 indexTotal = 0
for { for {
@@ -666,7 +671,7 @@ func CounDataByDateAndReCount(wikiCountMap map[string]int, startTime time.Time,


dateRecord.CommitModelCount = getMapValue(dateRecord.ID, AiModelManageMap) dateRecord.CommitModelCount = getMapValue(dateRecord.ID, AiModelManageMap)
dateRecord.UserIndex = getUserIndex(dateRecord, ParaWeight) dateRecord.UserIndex = getUserIndex(dateRecord, ParaWeight)
setUserMetrics(userMetrics, userRecord, start_unix, end_unix, dateRecord)
_, err = statictisSess.Insert(&dateRecord) _, err = statictisSess.Insert(&dateRecord)
if err != nil { if err != nil {
log.Info("insert daterecord failed." + err.Error()) log.Info("insert daterecord failed." + err.Error())
@@ -680,11 +685,47 @@ func CounDataByDateAndReCount(wikiCountMap map[string]int, startTime time.Time,
} }
} }


RefreshUserStaticAllTabel(wikiCountMap)
RefreshUserStaticAllTabel(wikiCountMap, userMetrics)

//insert userMetrics table
var useMetrics UserMetrics
useMetrics.CountDate = CountDate.Unix()
statictisSess.Delete(&useMetrics)

useMetrics.ActivateRegistUser = getMapKeyStringValue("ActivateRegistUser", userMetrics)
useMetrics.HasActivityUser = getMapKeyStringValue("HasActivityUser", userMetrics)
useMetrics.NotActivateRegistUser = getMapKeyStringValue("NotActivateRegistUser", userMetrics)
useMetrics.TotalActivateRegistUser = getMapKeyStringValue("TotalActivateRegistUser", userMetrics)
useMetrics.TotalHasActivityUser = getMapKeyStringValue("TotalHasActivityUser", userMetrics)
statictisSess.Insert(&useMetrics)


return nil return nil
} }


func setUserMetrics(userMetrics map[string]int, user *User, start_time int64, end_time int64, dateRecord UserBusinessAnalysis) {
//ActivateRegistUser int `xorm:"NOT NULL DEFAULT 0"`
//NotActivateRegistUser int `xorm:"NOT NULL DEFAULT 0"`
//HasActivityUser int `xorm:"NOT NULL DEFAULT 0"`
//TotalActivateRegistUser int `xorm:"NOT NULL DEFAULT 0"`
//TotalHasActivityUser
regist_time := user.CreatedUnix.AsTime().Unix()
if regist_time >= start_time && regist_time <= end_time {
if user.IsActive {
userMetrics["ActivateRegistUser"] = getMapKeyStringValue("ActivateRegistUser", userMetrics) + 1
} else {
userMetrics["NotActivateRegistUser"] = getMapKeyStringValue("NotActivateRegistUser", userMetrics) + 1
}
}
if user.IsActive {
userMetrics["TotalActivateRegistUser"] = getMapKeyStringValue("TotalActivateRegistUser", userMetrics) + 1
}

if dateRecord.UserIndex > 0 || dateRecord.LoginCount > 0 {
userMetrics["HasActivityUser"] = getMapKeyStringValue("HasActivityUser", userMetrics) + 1
}

}

func getParaWeight() map[string]float64 { func getParaWeight() map[string]float64 {
result := make(map[string]float64) result := make(map[string]float64)
statictisSess := xStatistic.NewSession() statictisSess := xStatistic.NewSession()


+ 9
- 0
models/user_business_struct.go View File

@@ -342,3 +342,12 @@ type UserAnalysisPara struct {
Key string `xorm:"NOT NULL"` Key string `xorm:"NOT NULL"`
Value float64 `xorm:"NOT NULL DEFAULT 0"` Value float64 `xorm:"NOT NULL DEFAULT 0"`
} }

type UserMetrics struct {
CountDate int64 `xorm:"pk"`
ActivateRegistUser int `xorm:"NOT NULL DEFAULT 0"`
NotActivateRegistUser int `xorm:"NOT NULL DEFAULT 0"`
HasActivityUser int `xorm:"NOT NULL DEFAULT 0"`
TotalActivateRegistUser int `xorm:"NOT NULL DEFAULT 0"`
TotalHasActivityUser int `xorm:"NOT NULL DEFAULT 0"`
}

Loading…
Cancel
Save