Browse Source

update

tags/v1.22.6.1^2
liuzx 3 years ago
parent
commit
22861000fb
3 changed files with 45 additions and 63 deletions
  1. +33
    -0
      models/cloudbrain_static.go
  2. +1
    -1
      routers/api/v1/api.go
  3. +11
    -62
      routers/api/v1/repo/cloudbrain_dashboard.go

+ 33
- 0
models/cloudbrain_static.go View File

@@ -216,6 +216,39 @@ func GetAllCloudBrain() ([]*CloudbrainInfo, error) {
return cloudbrains, nil
}

// func GetCloudBrains(opts *CloudbrainsOptions) ([]*CloudbrainInfo, error) {
// sess := x.NewSession()
// defer sess.Close()
// var cond = builder.NewCond()
// if len(opts.JobStatus) > 0 {
// if opts.JobStatusNot {
// cond = cond.And(
// builder.NotIn("cloudbrain.status", opts.JobStatus),
// )
// } else {
// cond = cond.And(
// builder.In("cloudbrain.status", opts.JobStatus),
// )
// }
// }
// if opts.Page >= 0 && opts.PageSize > 0 {
// var start int
// if opts.Page == 0 {
// start = 0
// } else {
// start = (opts.Page - 1) * opts.PageSize
// }
// sess.Limit(opts.PageSize, start)
// }
// sess.OrderBy("cloudbrain.created_unix DESC")
// cloudbrains := make([]*CloudbrainInfo, 0, setting.UI.IssuePagingNum)
// if err := sess.Table(&Cloudbrain{}).Where(cond).Unscoped().
// Find(&cloudbrains); err != nil {
// log.Info("find error.")
// }
// return cloudbrains, nil
// }

func getCreatePeriodCount(dateBeginTime string, dateEndTime string, hourBeginTime string, hourEndTime string) (int64, error) {
countSql := "SELECT count(*) FROM " +
"public.cloudbrain where to_char(to_timestamp(created_unix), 'YYYY-MM-DD') >= '" + dateBeginTime +


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

@@ -568,7 +568,7 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Get("/status_analysis", repo.GetCloudbrainsStatusAnalysis)
m.Get("/detail_data", repo.GetCloudbrainsDetailData)
m.Get("/hours_data", repo.GetCloudbrainsCreateHoursData)
// m.Get("/run_hours_data", repo.GetCloudbrainsRunHoursData)
m.Get("/wait_time_top", repo.GetWaitTimeTop)
})
}, operationReq)



+ 11
- 62
routers/api/v1/repo/cloudbrain_dashboard.go View File

@@ -649,75 +649,24 @@ func GetCloudbrainsCreateHoursData(ctx *context.Context) {
})

}
func GetCloudbrainsRunHoursData(ctx *context.Context) {
runHourPeriodCount := make(map[string]interface{})
brainRecordBeginTime, err := getBrainRecordBeginTime()

func GetWaitTimeTop(ctx *context.Context) {

cloudbrains, err := models.GetAllCloudBrain()
if err != nil {
log.Error("Can not get brain record begin time", err)
ctx.Error(http.StatusBadRequest, ctx.Tr("repo.brain_record_begintime_get_err"))
log.Error("Getcloudbrains failed:%v", err)
return
}
queryType := ctx.QueryTrim("type")
beginTimeStr := ctx.QueryTrim("beginTime")
endTimeStr := ctx.QueryTrim("endTime")
now := time.Now()
var beginTime time.Time
var endTime time.Time
if queryType != "" {
if queryType == "all" {
beginTime = brainRecordBeginTime
endTime = now
} 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())
} else if queryType == "current_week" {
beginTime = now.AddDate(0, 0, -int(time.Now().Weekday())+1) //begin from monday
endTime = now
} else if queryType == "current_month" {
endTime = now
beginTime = time.Date(endTime.Year(), endTime.Month(), 1, 0, 0, 0, 0, now.Location())
} else if queryType == "monthly" {
endTime = now
beginTime = now.AddDate(0, -1, 0)
beginTime = time.Date(beginTime.Year(), beginTime.Month(), beginTime.Day(), 0, 0, 0, 0, now.Location())
} else if queryType == "current_year" {
endTime = now
beginTime = time.Date(endTime.Year(), 1, 1, 0, 0, 0, 0, now.Location())
} else if queryType == "last_month" {
lastMonthTime := now.AddDate(0, -1, 0)
beginTime = time.Date(lastMonthTime.Year(), lastMonthTime.Month(), 1, 0, 0, 0, 0, now.Location())
endTime = time.Date(now.Year(), now.Month(), 2, 0, 0, 0, 0, now.Location())
}
} else {
if beginTimeStr == "" || endTimeStr == "" {
//如果查询类型和开始时间结束时间都未设置,按queryType=all处理
beginTime = brainRecordBeginTime
endTime = now
cloudBrainStatusResult := make(map[string]int)
for _, cloudbrain := range cloudbrains {
if _, ok := cloudBrainStatusResult[cloudbrain.Status]; !ok {
cloudBrainStatusResult[cloudbrain.Status] = 1
} else {
beginTime, err = time.ParseInLocation("2006-01-02", beginTimeStr, time.Local)
if err != nil {
log.Error("Can not ParseInLocation.", err)
ctx.Error(http.StatusBadRequest, ctx.Tr("ParseInLocation_get_error"))
return
}
endTime, err = time.ParseInLocation("2006-01-02", endTimeStr, time.Local)
if err != nil {
log.Error("Can not ParseInLocation.", err)
ctx.Error(http.StatusBadRequest, ctx.Tr("ParseInLocation_get_error"))
return
}
cloudBrainStatusResult[cloudbrain.Status] += 1
}
}
dateBeginTime := beginTime.Format("2006-01-02")
dateEndTime := endTime.Format("2006-01-02")
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{}{
"runHourPeriodCount": runHourPeriodCount,
"cloudBrainStatusResult": cloudBrainStatusResult,
})

}


Loading…
Cancel
Save