Browse Source

update

tags/v1.22.6.1^2
liuzx 3 years ago
parent
commit
a5ee6c39a9
2 changed files with 78 additions and 0 deletions
  1. +1
    -0
      routers/api/v1/api.go
  2. +77
    -0
      routers/api/v1/repo/cloudbrain_dashboard.go

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

@@ -565,6 +565,7 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Get("/distribution", repo.GetAllCloudbrainsPeriodDistribution)
m.Get("/trend", repo.GetAllCloudbrainsTrend)
m.Get("/status_analysis", repo.GetCloudbrainsStatusAnalysis)
m.Get("/detail_data", repo.GetCloudbrainsDetailData)
})
}, operationReq)



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

@@ -4,11 +4,13 @@ import (
"fmt"
"net/http"
"net/url"
"strings"
"time"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/modelarts"
"github.com/360EntSecGroup-Skylar/excelize/v2"

"code.gitea.io/gitea/modules/setting"
@@ -412,6 +414,81 @@ func GetCloudbrainsStatusAnalysis(ctx *context.Context) {
ctx.JSON(http.StatusOK, cloudbrainsStatusAnalysis)
}

func GetCloudbrainsDetailData(ctx *context.Context) {

listType := ctx.Query("listType")
jobType := ctx.Query("jobType")
jobStatus := ctx.Query("jobStatus")

page := ctx.QueryInt("page")
if page <= 0 {
page = 1
}
debugType := models.TypeCloudBrainAll
if listType == models.GPUResource {
debugType = models.TypeCloudBrainOne
} else if listType == models.NPUResource {
debugType = models.TypeCloudBrainTwo
}

var jobTypes []string
jobTypeNot := false
if jobType == string(models.JobTypeDebug) {
jobTypes = append(jobTypes, string(models.JobTypeSnn4imagenet), string(models.JobTypeBrainScore), string(models.JobTypeDebug))
} else if jobType != "all" && jobType != "" {
jobTypes = append(jobTypes, jobType)
}

var jobStatuses []string
jobStatusNot := false
if jobStatus == "other" {
jobStatusNot = true
jobStatuses = append(jobStatuses, string(models.ModelArtsTrainJobWaiting), string(models.ModelArtsTrainJobFailed), string(models.ModelArtsRunning), string(models.ModelArtsTrainJobCompleted),
string(models.ModelArtsStarting), string(models.ModelArtsRestarting), string(models.ModelArtsStartFailed),
string(models.ModelArtsStopping), string(models.ModelArtsStopped), string(models.JobSucceeded))
} else if jobStatus != "all" && jobStatus != "" {
jobStatuses = append(jobStatuses, jobStatus)
}

keyword := strings.Trim(ctx.Query("q"), " ")

ciTasks, count, err := models.Cloudbrains(&models.CloudbrainsOptions{
ListOptions: models.ListOptions{
Page: page,
PageSize: setting.UI.IssuePagingNum,
},
Keyword: keyword,
Type: debugType,
JobTypeNot: jobTypeNot,
JobStatusNot: jobStatusNot,
JobStatus: jobStatuses,
JobTypes: jobTypes,
NeedRepoInfo: true,
IsLatestVersion: modelarts.IsLatestVersion,
})
if err != nil {
ctx.ServerError("Get job failed:", err)
return
}

for i, task := range ciTasks {
ciTasks[i].CanDebug = true
ciTasks[i].CanDel = true
ciTasks[i].Cloudbrain.ComputeResource = task.ComputeResource
}

pager := context.NewPagination(int(count), setting.UI.IssuePagingNum, page, getTotalPage(count, setting.UI.IssuePagingNum))
pager.SetDefaultParams(ctx)
pager.AddParam(ctx, "listType", "ListType")

ctx.JSON(http.StatusOK, map[string]interface{}{
"Title": ctx.Tr("kanban.cloudBrains"),
"Tasks": ciTasks,
"CanCreate": true,
"Keyword": keyword,
})
}

func getCloudbrainCount(beginTime time.Time, endTime time.Time) (int64, int64, int64, int64, int64, int64, int64, int64, int64, error) {
debugOneCount, err := models.GetDebugOnePeriodCount(beginTime, endTime)
if err != nil {


Loading…
Cancel
Save