Browse Source

Merge pull request '解决用户分析相关Bug及新增用户分析手工触发接口。' (#2098) from zouap into V20220519

Reviewed-on: https://git.openi.org.cn/OpenI/aiforge/pulls/2098
Reviewed-by: lewis <747342561@qq.com>
pull/2112/head
lewis 3 years ago
parent
commit
2761af7e4d
6 changed files with 47 additions and 19 deletions
  1. +25
    -13
      models/user_business_analysis.go
  2. +2
    -2
      modules/cloudbrain/cloudbrain.go
  3. +3
    -2
      routers/private/internal.go
  4. +5
    -0
      routers/private/tool.go
  5. +10
    -0
      routers/repo/user_data_analysis.go
  6. +2
    -2
      web_src/js/components/UserTrend.vue

+ 25
- 13
models/user_business_analysis.go View File

@@ -233,19 +233,15 @@ func QueryMetricsPage(start int64, end int64, page int, pageSize int) ([]*UserMe
statictisSess := xStatistic.NewSession() statictisSess := xStatistic.NewSession()
defer statictisSess.Close() defer statictisSess.Close()
cond := "count_date >" + fmt.Sprint(start) + " and count_date<" + fmt.Sprint(end) cond := "count_date >" + fmt.Sprint(start) + " and count_date<" + fmt.Sprint(end)
allCount, err := statictisSess.Where(cond).Count(new(UserMetrics))
if err != nil {
log.Info("query error." + err.Error())
return nil, 0
}

userMetricsList := make([]*UserMetrics, 0) userMetricsList := make([]*UserMetrics, 0)
//.Limit(pageSize, page*pageSize) //.Limit(pageSize, page*pageSize)
if err := statictisSess.Table(new(UserMetrics)).Where(cond).OrderBy("count_date desc"). if err := statictisSess.Table(new(UserMetrics)).Where(cond).OrderBy("count_date desc").
Find(&userMetricsList); err != nil { Find(&userMetricsList); err != nil {
return nil, 0 return nil, 0
} }
postDeal(userMetricsList)
return userMetricsList, allCount
postUserMetricsList := postDeal(userMetricsList)
return postUserMetricsList, int64(len(postUserMetricsList))
} }


func QueryMetrics(start int64, end int64) ([]*UserMetrics, int) { func QueryMetrics(start int64, end int64) ([]*UserMetrics, int) {
@@ -256,16 +252,31 @@ func QueryMetrics(start int64, end int64) ([]*UserMetrics, int) {
Find(&userMetricsList); err != nil { Find(&userMetricsList); err != nil {
return nil, 0 return nil, 0
} }
postDeal(userMetricsList)
return userMetricsList, len(userMetricsList)
postUserMetricsList := postDeal(userMetricsList)
return postUserMetricsList, int(len(postUserMetricsList))
}

func duplicateRemoval(userMetricsList []*UserMetrics) []*UserMetrics {
userMetricsResult := make([]*UserMetrics, 0)
for i := 0; i < len(userMetricsList); i++ {
if i > 0 {
if userMetricsList[i].DataDate == userMetricsList[i-1].DataDate {
continue
}
}
userMetricsResult = append(userMetricsResult, userMetricsList[i])
}
return userMetricsResult
} }


func postDeal(userMetricsList []*UserMetrics) {
for _, userMetrics := range userMetricsList {
func postDeal(userMetricsList []*UserMetrics) []*UserMetrics {
duplicateRemovalUserMetricsList := duplicateRemoval(userMetricsList)
for _, userMetrics := range duplicateRemovalUserMetricsList {
userMetrics.DisplayDate = userMetrics.DataDate userMetrics.DisplayDate = userMetrics.DataDate
userMetrics.TotalRegistUser = userMetrics.ActivateRegistUser + userMetrics.NotActivateRegistUser userMetrics.TotalRegistUser = userMetrics.ActivateRegistUser + userMetrics.NotActivateRegistUser
userMetrics.TotalNotActivateRegistUser = userMetrics.TotalUser - userMetrics.TotalActivateRegistUser userMetrics.TotalNotActivateRegistUser = userMetrics.TotalUser - userMetrics.TotalActivateRegistUser
} }
return duplicateRemovalUserMetricsList
} }


func QueryMetricsForAll() []*UserMetrics { func QueryMetricsForAll() []*UserMetrics {
@@ -276,7 +287,8 @@ func QueryMetricsForAll() []*UserMetrics {
Find(&userMetricsList); err != nil { Find(&userMetricsList); err != nil {
return nil return nil
} }
return makeResultForMonth(userMetricsList, len(userMetricsList))
duplicateRemovalUserMetricsList := duplicateRemoval(userMetricsList)
return makeResultForMonth(duplicateRemovalUserMetricsList, len(duplicateRemovalUserMetricsList))
} }


func QueryMetricsForYear() []*UserMetrics { func QueryMetricsForYear() []*UserMetrics {
@@ -879,9 +891,9 @@ func CounDataByDateAndReCount(wikiCountMap map[string]int, startTime time.Time,
//insert userMetrics table //insert userMetrics table
var useMetrics UserMetrics var useMetrics UserMetrics
useMetrics.CountDate = CountDate.Unix() useMetrics.CountDate = CountDate.Unix()
useMetrics.DataDate = DataDate
statictisSess.Delete(&useMetrics) statictisSess.Delete(&useMetrics)


useMetrics.DataDate = DataDate
useMetrics.ActivateRegistUser = getMapKeyStringValue("ActivateRegistUser", userMetrics) useMetrics.ActivateRegistUser = getMapKeyStringValue("ActivateRegistUser", userMetrics)
useMetrics.HasActivityUser = getMapKeyStringValue("HasActivityUser", userMetrics) useMetrics.HasActivityUser = getMapKeyStringValue("HasActivityUser", userMetrics)
useMetrics.RegistActivityUser = 0 useMetrics.RegistActivityUser = 0


+ 2
- 2
modules/cloudbrain/cloudbrain.go View File

@@ -1,11 +1,12 @@
package cloudbrain package cloudbrain


import ( import (
"code.gitea.io/gitea/modules/timeutil"
"encoding/json" "encoding/json"
"errors" "errors"
"strconv" "strconv"


"code.gitea.io/gitea/modules/timeutil"

"code.gitea.io/gitea/modules/storage" "code.gitea.io/gitea/modules/storage"


"code.gitea.io/gitea/models" "code.gitea.io/gitea/models"
@@ -186,7 +187,6 @@ func AdminOrImageCreaterRight(ctx *context.Context) {


} }



func GenerateTask(ctx *context.Context, displayJobName, jobName, image, command, uuid, codePath, modelPath, benchmarkPath, snn4imagenetPath, brainScorePath, jobType, gpuQueue, description, branchName, bootFile, params string, benchmarkTypeID, benchmarkChildTypeID, resourceSpecId int) error { func GenerateTask(ctx *context.Context, displayJobName, jobName, image, command, uuid, codePath, modelPath, benchmarkPath, snn4imagenetPath, brainScorePath, jobType, gpuQueue, description, branchName, bootFile, params string, benchmarkTypeID, benchmarkChildTypeID, resourceSpecId int) error {


dataActualPath := setting.Attachment.Minio.RealPath + dataActualPath := setting.Attachment.Minio.RealPath +


+ 3
- 2
routers/private/internal.go View File

@@ -6,9 +6,10 @@
package private package private


import ( import (
"code.gitea.io/gitea/routers/repo"
"strings" "strings"


"code.gitea.io/gitea/routers/repo"

"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/private" "code.gitea.io/gitea/modules/private"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
@@ -46,7 +47,7 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Post("/manager/flush-queues", bind(private.FlushOptions{}), FlushQueues) m.Post("/manager/flush-queues", bind(private.FlushOptions{}), FlushQueues)
m.Post("/tool/update_all_repo_commit_cnt", UpdateAllRepoCommitCnt) m.Post("/tool/update_all_repo_commit_cnt", UpdateAllRepoCommitCnt)
m.Post("/tool/repo_stat/:date", RepoStatisticManually) m.Post("/tool/repo_stat/:date", RepoStatisticManually)
m.Post("/tool/user_stat/:date", UserStatisticManually)
m.Get("/tool/org_stat", OrgStatisticManually) m.Get("/tool/org_stat", OrgStatisticManually)
m.Post("/tool/update_repo_visit/:date", UpdateRepoVisit) m.Post("/tool/update_repo_visit/:date", UpdateRepoVisit)
m.Post("/task/history_handle/duration", repo.HandleTaskWithNoDuration) m.Post("/task/history_handle/duration", repo.HandleTaskWithNoDuration)


+ 5
- 0
routers/private/tool.go View File

@@ -45,6 +45,11 @@ func RepoStatisticManually(ctx *macaron.Context) {
repo.TimingCountDataByDate(date) repo.TimingCountDataByDate(date)
} }


func UserStatisticManually(ctx *macaron.Context) {
date := ctx.Params("date")
repo.TimingCountDataByDate(date)
}

func OrgStatisticManually() { func OrgStatisticManually() {
models.UpdateOrgStatistics() models.UpdateOrgStatistics()
} }


+ 10
- 0
routers/repo/user_data_analysis.go View File

@@ -247,6 +247,7 @@ func queryUserDataPage(ctx *context.Context, tableName string, queryObj interfac
mapInterface := make(map[string]interface{}) mapInterface := make(map[string]interface{})
mapInterface["data"] = re mapInterface["data"] = re
mapInterface["count"] = count mapInterface["count"] = count

ctx.JSON(http.StatusOK, mapInterface) ctx.JSON(http.StatusOK, mapInterface)
} }
} }
@@ -303,6 +304,15 @@ func queryMetrics(ctx *context.Context, tableName string, startTime time.Time, e
mapInterface := make(map[string]interface{}) mapInterface := make(map[string]interface{})
mapInterface["data"] = result mapInterface["data"] = result
mapInterface["count"] = count mapInterface["count"] = count
if tableName == "public.user_business_analysis_yesterday" {
mapInterface["datarecordbegintime"] = setting.RadarMap.GrowthBeginTime
if len(result) > 0 {
dateTime := time.Unix(result[0].CountDate, 0)
mapInterface["lastUpdatedTime"] = dateTime.Format("2006-01-02 15:04:05")
} else {
mapInterface["lastUpdatedTime"] = ""
}
}
ctx.JSON(http.StatusOK, mapInterface) ctx.JSON(http.StatusOK, mapInterface)
} }




+ 2
- 2
web_src/js/components/UserTrend.vue View File

@@ -257,10 +257,10 @@
return days; return days;
}, },
getUpdateTime(){ getUpdateTime(){
this.$axios.get('../../api/v1/projectboard/project',{
this.$axios.get('../../api/v1/query_metrics_yesterday',{
params:this.params_pro params:this.params_pro
}).then((res)=>{ }).then((res)=>{
this.recordBeginTime=res.data.recordBeginTime
this.recordBeginTime=res.data.datarecordbegintime
this.lastUpdatedTime=res.data.lastUpdatedTime this.lastUpdatedTime=res.data.lastUpdatedTime
}) })
}, },


Loading…
Cancel
Save