Browse Source

update

tags/v1.22.6.1^2
liuzx 4 years ago
parent
commit
17718c507f
3 changed files with 139 additions and 0 deletions
  1. +5
    -0
      models/cloudbrain_static.go
  2. +15
    -0
      routers/api/v1/api.go
  3. +119
    -0
      routers/api/v1/repo/cloudbrain_dashboard.go

+ 5
- 0
models/cloudbrain_static.go View File

@@ -0,0 +1,5 @@
package models

func CountBrainStatByRawSql(sql string) (int64, error) {
return xStatistic.SQL(sql).Count()
}

+ 15
- 0
routers/api/v1/api.go View File

@@ -554,6 +554,21 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Get("/query_user_last_month", operationReq, repo_ext.QueryUserStaticLastMonth)
m.Get("/query_user_yesterday", operationReq, repo_ext.QueryUserStaticYesterday)
m.Get("/query_user_all", operationReq, repo_ext.QueryUserStaticAll)
//cloudbrain board
m.Group("/cloudbrainboard", func() {
m.Get("/restoreFork", repo.RestoreForkNumber)
m.Get("/downloadAll", repo.ServeAllProjectsPeriodStatisticsFile)
m.Get("/downloadAllOpenI", repo.ServeAllProjectsOpenIStatisticsFile)
m.Group("/cloudbrain", func() {
m.Get("", repo.GetAllCloudbrainsPeriodStatistics)
m.Group("/:id", func() {
m.Get("", repo.GetProjectLatestStatistics)
m.Get("/period", repo.GetProjectPeriodStatistics)

})
})
}, operationReq)

// Users
m.Group("/users", func() {
m.Get("/search", user.Search)


+ 119
- 0
routers/api/v1/repo/cloudbrain_dashboard.go View File

@@ -0,0 +1,119 @@
package repo

import (
"net/http"
"strconv"
"time"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/log"
)

func GetAllCloudbrainsPeriodStatistics(ctx *context.Context) {

recordBeginTime, err := getRecordBeginTime()
if err != nil {
log.Error("Can not get record begin time", err)
ctx.Error(http.StatusBadRequest, ctx.Tr("repo.record_begintime_get_err"))
return
}
beginTime, endTime, err := getTimePeroid(ctx, recordBeginTime)
if err != nil {
log.Error("Parameter is wrong", err)
ctx.Error(http.StatusBadRequest, ctx.Tr("repo.parameter_is_wrong"))
return
}
q := ctx.QueryTrim("q")
page := ctx.QueryInt("page")
if page <= 0 {
page = 1
}
pageSize := ctx.QueryInt("pagesize")
if pageSize <= 0 {
pageSize = DEFAULT_PAGE_SIZE
}
orderBy := getOrderBy(ctx)

latestUpdatedTime, latestDate, err := models.GetRepoStatLastUpdatedTime()
if err != nil {
log.Error("Can not query the last updated time.", err)
ctx.Error(http.StatusBadRequest, ctx.Tr("repo.last_update_time_error"))
return
}

DebugOneCountSql := generateDebugOneCountSql(beginTime, endTime)
DebugOneTotal, err := models.CountBrainStatByRawSql(beginTime, endTime)
if err != nil {
log.Error("Can not query total count.", err)
ctx.Error(http.StatusBadRequest, ctx.Tr("repo.total_count_get_error"))
return
}
DebugTwoCountSql := generateDebugTwoCountSql(beginTime, endTime)
DebugOneTotal, err := models.CountBrainStatByRawSql(DebugTwoCountSql)
if err != nil {
log.Error("Can not query total count.", err)
ctx.Error(http.StatusBadRequest, ctx.Tr("repo.total_count_get_error"))
return
}

sql := generateSqlByType(ctx, beginTime, endTime, latestDate, q, orderBy, page, pageSize)

projectsPeriodData := ProjectsPeriodData{
RecordBeginTime: recordBeginTime.Format(DATE_FORMAT),
PageSize: pageSize,
TotalPage: getTotalPage(DebugOneTotal, pageSize),
TotalCount: DebugOneTotal,
LastUpdatedTime: latestUpdatedTime,
PageRecords: models.GetRepoStatisticByRawSql(sql),
}

ctx.JSON(http.StatusOK, projectsPeriodData)

}

func generateDebugOneCountSql(beginTime time.Time, endTime time.Time) string {
countSql := "SELECT count(*) FROM " +
"(SELECT job_id FROM cloudbrain where created_unix >=" + strconv.FormatInt(beginTime.Unix(), 10) +
" and created_unix<" + strconv.FormatInt(endTime.Unix(), 10) +
" and job_type=" + "DEBUG" +
" and type=" + "0" +
" group by job_id) "
return countSql
}
func generateBenchmarkOneCountSql(beginTime time.Time, endTime time.Time) string {
countSql := "SELECT count(*) FROM " +
"(SELECT job_id FROM cloudbrain where created_unix >=" + strconv.FormatInt(beginTime.Unix(), 10) +
" and created_unix<" + strconv.FormatInt(endTime.Unix(), 10) +
" and job_type=" + "BENCHMARK" +
" and type=" + "0" +
" group by job_id) "
return countSql
}
func generateDebugTwoCountSql(beginTime time.Time, endTime time.Time) string {
countSql := "SELECT count(*) FROM " +
"(SELECT job_id FROM cloudbrain where created_unix >=" + strconv.FormatInt(beginTime.Unix(), 10) +
" and created_unix<" + strconv.FormatInt(endTime.Unix(), 10) +
" and job_type=" + "DEBUG" +
" and type=" + "2" +
" group by job_id) "
return countSql
}
func generateTrainTwoCountSql(beginTime time.Time, endTime time.Time) string {
countSql := "SELECT count(*) FROM " +
"(SELECT job_id FROM cloudbrain where created_unix >=" + strconv.FormatInt(beginTime.Unix(), 10) +
" and created_unix<" + strconv.FormatInt(endTime.Unix(), 10) +
" and job_type=" + "TRAIN" +
" and type=" + "1" +
" group by job_id) "
return countSql
}
func generateInferenceTwoCountSql(beginTime time.Time, endTime time.Time) string {
countSql := "SELECT count(*) FROM " +
"(SELECT job_id FROM cloudbrain where created_unix >=" + strconv.FormatInt(beginTime.Unix(), 10) +
" and created_unix<" + strconv.FormatInt(endTime.Unix(), 10) +
" and job_type=" + "INFERENCE" +
" and type=" + "1" +
" group by job_id) "
return countSql
}

Loading…
Cancel
Save