|
|
|
@@ -2,14 +2,20 @@ package repo |
|
|
|
|
|
|
|
import ( |
|
|
|
"net/http" |
|
|
|
"strconv" |
|
|
|
"time" |
|
|
|
|
|
|
|
"code.gitea.io/gitea/models" |
|
|
|
"code.gitea.io/gitea/modules/context" |
|
|
|
"code.gitea.io/gitea/modules/log" |
|
|
|
) |
|
|
|
|
|
|
|
type CloudbrainsPeriodData struct { |
|
|
|
DebugOneCount int64 `json:"debugOneCount"` |
|
|
|
BenchmarkOneCount int64 `json:"benchmarkOneCount"` |
|
|
|
DebugTwoCount int64 `json:"debugTwoCount"` |
|
|
|
TrainTwoCount int64 `json:"trainTwoCount"` |
|
|
|
InferenceTwoCount int64 `json:"inferenceTwoCount"` |
|
|
|
} |
|
|
|
|
|
|
|
func GetAllCloudbrainsPeriodStatistics(ctx *context.Context) { |
|
|
|
|
|
|
|
recordBeginTime, err := getRecordBeginTime() |
|
|
|
@@ -24,7 +30,6 @@ func GetAllCloudbrainsPeriodStatistics(ctx *context.Context) { |
|
|
|
ctx.Error(http.StatusBadRequest, ctx.Tr("repo.parameter_is_wrong")) |
|
|
|
return |
|
|
|
} |
|
|
|
q := ctx.QueryTrim("q") |
|
|
|
page := ctx.QueryInt("page") |
|
|
|
if page <= 0 { |
|
|
|
page = 1 |
|
|
|
@@ -33,87 +38,46 @@ func GetAllCloudbrainsPeriodStatistics(ctx *context.Context) { |
|
|
|
if pageSize <= 0 { |
|
|
|
pageSize = DEFAULT_PAGE_SIZE |
|
|
|
} |
|
|
|
orderBy := getOrderBy(ctx) |
|
|
|
|
|
|
|
latestUpdatedTime, latestDate, err := models.GetRepoStatLastUpdatedTime() |
|
|
|
debugOneCount, err := models.GenerateDebugOneCount(beginTime, endTime) |
|
|
|
if err != nil { |
|
|
|
log.Error("Can not query the last updated time.", err) |
|
|
|
ctx.Error(http.StatusBadRequest, ctx.Tr("repo.last_update_time_error")) |
|
|
|
log.Error("Can not query debugOneCount.", err) |
|
|
|
ctx.Error(http.StatusBadRequest, ctx.Tr("debugOneCount_get_error")) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
DebugOneCountSql := generateDebugOneCountSql(beginTime, endTime) |
|
|
|
DebugOneTotal, err := models.CountBrainStatByRawSql(beginTime, endTime) |
|
|
|
benchmarkOneCount, err := models.GenerateBenchmarkOneCount(beginTime, endTime) |
|
|
|
if err != nil { |
|
|
|
log.Error("Can not query total count.", err) |
|
|
|
ctx.Error(http.StatusBadRequest, ctx.Tr("repo.total_count_get_error")) |
|
|
|
log.Error("Can not query benchmarkCount.", err) |
|
|
|
ctx.Error(http.StatusBadRequest, ctx.Tr("benchmarkOneCount_get_error")) |
|
|
|
return |
|
|
|
} |
|
|
|
DebugTwoCountSql := generateDebugTwoCountSql(beginTime, endTime) |
|
|
|
DebugOneTotal, err := models.CountBrainStatByRawSql(DebugTwoCountSql) |
|
|
|
debugTwoCount, err := models.GenerateDebugTwoCount(beginTime, endTime) |
|
|
|
if err != nil { |
|
|
|
log.Error("Can not query total count.", err) |
|
|
|
ctx.Error(http.StatusBadRequest, ctx.Tr("repo.total_count_get_error")) |
|
|
|
log.Error("Can not query debugTwoCount.", err) |
|
|
|
ctx.Error(http.StatusBadRequest, ctx.Tr("debugTwoCount_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), |
|
|
|
trainTwoCount, err := models.GenerateTrainTwoCount(beginTime, endTime) |
|
|
|
if err != nil { |
|
|
|
log.Error("Can not query DebugOneTotal count.", err) |
|
|
|
ctx.Error(http.StatusBadRequest, ctx.Tr("total_count_get_error")) |
|
|
|
return |
|
|
|
} |
|
|
|
inferenceTwoCount, err := models.GenerateInferenceTwoCount(beginTime, endTime) |
|
|
|
if err != nil { |
|
|
|
log.Error("Can not query inferenceTwoCount.", err) |
|
|
|
ctx.Error(http.StatusBadRequest, ctx.Tr("inferenceTwoCount_get_error")) |
|
|
|
return |
|
|
|
} |
|
|
|
|
|
|
|
ctx.JSON(http.StatusOK, projectsPeriodData) |
|
|
|
cloudbrainsPeriodData := CloudbrainsPeriodData{ |
|
|
|
DebugOneCount: debugOneCount, |
|
|
|
BenchmarkOneCount: benchmarkOneCount, |
|
|
|
DebugTwoCount: debugTwoCount, |
|
|
|
TrainTwoCount: trainTwoCount, |
|
|
|
InferenceTwoCount: inferenceTwoCount, |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
ctx.JSON(http.StatusOK, cloudbrainsPeriodData) |
|
|
|
|
|
|
|
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 |
|
|
|
} |