diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index a4df6143e..2ace1c1bf 100755 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -566,8 +566,8 @@ func RegisterRoutes(m *macaron.Macaron) { m.Get("/trend", repo.GetAllCloudbrainsTrend) m.Get("/status_analysis", repo.GetCloudbrainsStatusAnalysis) m.Get("/detail_data", repo.GetCloudbrainsDetailData) - m.Get("/create_hours_data", repo.GetCloudbrainsCreateHoursData) - m.Get("/run_hours_data", repo.GetCloudbrainsRunHoursData) + m.Get("/hours_data", repo.GetCloudbrainsCreateHoursData) + // m.Get("/run_hours_data", repo.GetCloudbrainsRunHoursData) }) }, operationReq) diff --git a/routers/api/v1/repo/cloudbrain_dashboard.go b/routers/api/v1/repo/cloudbrain_dashboard.go index 83fdb612e..b4db09bb9 100644 --- a/routers/api/v1/repo/cloudbrain_dashboard.go +++ b/routers/api/v1/repo/cloudbrain_dashboard.go @@ -149,8 +149,19 @@ func GetAllCloudbrainsTrend(ctx *context.Context) { return } - } else if queryType == "current_week" { - beginTime = now.AddDate(0, 0, -int(time.Now().Weekday())+1) //begin from monday + } else if queryType == "last_7day" { + beginTime = now.AddDate(0, 0, -7) //begin from monday + beginTime = time.Date(beginTime.Year(), beginTime.Month(), beginTime.Day(), 0, 0, 0, 0, now.Location()) + endTime = now + endTimeTemp = beginTime.AddDate(0, 0, 1) + dateCloudbrainNum, err = getDayCloudbrainNum(beginTime, endTimeTemp, endTime) + if err != nil { + log.Error("Can not query getDayCloudbrainNum.", err) + ctx.Error(http.StatusBadRequest, ctx.Tr("getDayCloudbrainNum_get_error")) + return + } + } else if queryType == "last_30day" { + beginTime = now.AddDate(0, 0, -30) //begin from monday beginTime = time.Date(beginTime.Year(), beginTime.Month(), beginTime.Day(), 0, 0, 0, 0, now.Location()) endTime = now endTimeTemp = beginTime.AddDate(0, 0, 1) @@ -376,6 +387,13 @@ func GetAllCloudbrainsPeriodDistribution(ctx *context.Context) { intelligentNetJobTypeRes[v] = 0 } } + cloudBrainTypeList := []int{0, 1, 2} + for _, v := range cloudBrainTypeList { + if _, ok := cloudBrainPeriodNum[v]; !ok { + cloudBrainPeriodNum[v] = 0 + } + } + // totalTasksCount := cloudBrainPeriodNum[0] + cloudBrainPeriodNum[1] + cloudBrainPeriodNum[2] cloudOneJobTypeRes["EVALUATION"] = cloudOneJobTypeRes["BENCHMARK"] + cloudOneJobTypeRes["SNN4IMAGENET"] + cloudOneJobTypeRes["BRAINSCORE"] cloudTwoJobTypeRes["EVALUATION"] = cloudTwoJobTypeRes["BENCHMARK"] + cloudTwoJobTypeRes["SNN4IMAGENET"] + cloudTwoJobTypeRes["BRAINSCORE"] @@ -385,6 +403,7 @@ func GetAllCloudbrainsPeriodDistribution(ctx *context.Context) { "cloudTwoJobTypeRes": cloudTwoJobTypeRes, "intelligentNetJobTypeRes": intelligentNetJobTypeRes, "cloudBrainPeriodNum": cloudBrainPeriodNum, + // "totalTasksCount": totalTasksCount, }) } @@ -463,13 +482,16 @@ func GetCloudbrainsDetailData(ctx *context.Context) { ctx.ServerError("Get job failed:", err) return } - // var taskList := []*models.TaskDetail - + res := &models.AllTask{} + res.List = []models.TaskDetail{} for i, task := range ciTasks { ciTasks[i].CanDebug = true ciTasks[i].CanDel = true ciTasks[i].Cloudbrain.ComputeResource = task.ComputeResource + var dataOne models.TaskDetail + dataOne.DisplayJobName = ciTasks[i].DisplayJobName + res.List = append(res.List, dataOne) } pager := context.NewPagination(int(count), setting.UI.IssuePagingNum, page, getTotalPage(count, setting.UI.IssuePagingNum)) @@ -502,6 +524,9 @@ func GetCloudbrainsCreateHoursData(ctx *context.Context) { if queryType == "all" { beginTime = brainRecordBeginTime endTime = now + } else if queryType == "today" { + beginTime = now.AddDate(0, 0, 0) + endTime = time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location()) } else if queryType == "yesterday" { beginTime = now.AddDate(0, 0, -1) endTime = time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location()) @@ -551,8 +576,16 @@ func GetCloudbrainsCreateHoursData(ctx *context.Context) { ctx.Error(http.StatusBadRequest, ctx.Tr("hourPeriodCount_get_error")) return } + + runHourPeriodCount, err := models.GetRunHourPeriodCount(dateBeginTime, dateEndTime) + if err != nil { + log.Error("Can not query runHourPeriodCount.", err) + ctx.Error(http.StatusBadRequest, ctx.Tr("runHourPeriodCount_get_error")) + return + } ctx.JSON(http.StatusOK, map[string]interface{}{ "createHourPeriodCount": createHourPeriodCount, + "runHourPeriodCount": runHourPeriodCount, }) } @@ -732,6 +765,7 @@ func getCloudbrainCount(beginTime time.Time, endTime time.Time) (map[string]int, cloudBrainPeriodNum[v] = 0 } } + cloudBrainPeriodNum[-1] = cloudBrainPeriodNum[0] + cloudBrainPeriodNum[1] + cloudBrainPeriodNum[2] return cloudOneJobTypeRes, cloudTwoJobTypeRes, intelligentNetJobTypeRes, cloudBrainPeriodNum, cloudBrainComputeResource, err } diff --git a/routers/api/v1/repo/repo_dashbord.go b/routers/api/v1/repo/repo_dashbord.go index 2c42f8a16..7d9ab3ffc 100644 --- a/routers/api/v1/repo/repo_dashbord.go +++ b/routers/api/v1/repo/repo_dashbord.go @@ -566,12 +566,19 @@ func getTimePeroid(ctx *context.Context, recordBeginTime time.Time) (time.Time, if queryType == "all" { beginTime = recordBeginTimeTemp endTime = now + } else if queryType == "today" { + endTime = now + beginTime = time.Date(endTime.Year(), endTime.Month(), endTime.Day(), 0, 0, 0, 0, now.Location()) } else if queryType == "yesterday" { endTime = now beginTime = time.Date(endTime.Year(), endTime.Month(), endTime.Day(), 0, 0, 0, 0, now.Location()) - } else if queryType == "current_week" { - beginTime = now.AddDate(0, 0, -int(time.Now().Weekday())+2) //begin from monday + } else if queryType == "last_7day" { + beginTime = now.AddDate(0, 0, -7) + beginTime = time.Date(beginTime.Year(), beginTime.Month(), beginTime.Day(), 0, 0, 0, 0, now.Location()) + endTime = now + } else if queryType == "last_30day" { + beginTime = now.AddDate(0, 0, -30) beginTime = time.Date(beginTime.Year(), beginTime.Month(), beginTime.Day(), 0, 0, 0, 0, now.Location()) endTime = now } else if queryType == "current_month" {