Reviewed-on: https://git.openi.org.cn/OpenI/aiforge/pulls/2098 Reviewed-by: lewis <747342561@qq.com>pull/2112/head
@@ -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 | ||||
@@ -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 + | ||||
@@ -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) | ||||
@@ -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() | ||||
} | } | ||||
@@ -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) | ||||
} | } | ||||
@@ -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 | ||||
}) | }) | ||||
}, | }, | ||||