Browse Source

update

tags/v1.22.6.1^2
liuzx 3 years ago
parent
commit
4b487086d1
3 changed files with 72 additions and 10 deletions
  1. +34
    -6
      models/cloudbrain_static.go
  2. +2
    -1
      routers/api/v1/api.go
  3. +36
    -3
      routers/api/v1/repo/cloudbrain_dashboard.go

+ 34
- 6
models/cloudbrain_static.go View File

@@ -315,7 +315,7 @@ func GetJobRunningCount() (int64, error) {
return x.SQL(countSql).Count()
}

func getDateAndHourPeriodCount(dateBeginTime string, dateEndTime string, hourBeginTime string, hourEndTime string) (int64, error) {
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 +
"' and to_char(to_timestamp(created_unix), 'YYYY-MM-DD') < '" + dateEndTime +
@@ -324,19 +324,47 @@ func getDateAndHourPeriodCount(dateBeginTime string, dateEndTime string, hourBeg
return x.SQL(countSql).Count()
}

func GetHourPeriodCount(dateBeginTime string, dateEndTime string) (map[int]int64, error) {
//SELECT * FROM xxx WHERE NOT ((endTime < hourBeginTime) OR (startTime > hourEndTime))
func getRunPeriodCount(dateBeginTime string, dateEndTime string, hourBeginTime string, hourEndTime string) (int64, error) {
countSql := "SELECT count(*) FROM " +
"public.cloudbrain where not ((to_char(to_timestamp(start_time), ' HH24:MI:SS') > '" + hourEndTime +
"') or (to_char(to_timestamp(end_time), 'HH24:MI:SS') < '" + hourBeginTime + "'))" +
" and (to_char(to_timestamp(start_time), 'YYYY-MM-DD') >= '" + dateBeginTime +
"' and to_char(to_timestamp(start_time), 'YYYY-MM-DD') < '" + dateEndTime + "')"
return x.SQL(countSql).Count()

}

func GetCreateHourPeriodCount(dateBeginTime string, dateEndTime string) (map[string]interface{}, error) {
//0 to 23 for each hour,
dateHourMap := make(map[string]interface{})
var slice = []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23}
for key, value := range slice {
hourBeginHour := strconv.Itoa(value) + ":00:00"
hourEndHour := strconv.Itoa(value+1) + ":00:00"
cout, err := getCreatePeriodCount(dateBeginTime, dateEndTime, hourBeginHour, hourEndHour)
if err != nil {
log.Error("Can not query getCreatePeriodCount.", err)
return nil, nil
}
dateHourMap[strconv.Itoa(key)] = cout
}
return dateHourMap, nil
}

func GetRunHourPeriodCount(dateBeginTime string, dateEndTime string) (map[string]interface{}, error) {
//0 to 23 for each hour,
dateHourMap := make(map[int]int64)
dateHourMap := make(map[string]interface{})
var slice = []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23}
for key, value := range slice {
hourBeginHour := strconv.Itoa(value) + ":00:00"
hourEndHour := strconv.Itoa(value+1) + ":00:00"
cout, err := getDateAndHourPeriodCount(dateBeginTime, dateEndTime, hourBeginHour, hourEndHour)
cout, err := getRunPeriodCount(dateBeginTime, dateEndTime, hourBeginHour, hourEndHour)
if err != nil {
log.Error("Can not query getDateAndHourPeriodCount.", err)
log.Error("Can not query getRunPeriodCount.", err)
return nil, nil
}
dateHourMap[key] = cout
dateHourMap[strconv.Itoa(key)] = cout
}
return dateHourMap, nil
}

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

@@ -566,7 +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("/hours_data", repo.GetCloudbrainsHoursData)
m.Get("/create_hours_data", repo.GetCloudbrainsCreateHoursData)
m.Get("/run_hours_data", repo.GetCloudbrainsRunHoursData)
})
}, operationReq)



+ 36
- 3
routers/api/v1/repo/cloudbrain_dashboard.go View File

@@ -490,8 +490,8 @@ func GetCloudbrainsDetailData(ctx *context.Context) {
})
}

func GetCloudbrainsHoursData(ctx *context.Context) {
hourPeriodCount := make(map[int]int64)
func GetCloudbrainsCreateHoursData(ctx *context.Context) {
hourPeriodCount := make(map[string]interface{})
brainRecordBeginTime, err := getBrainRecordBeginTime()
if err != nil {
log.Error("Can not get brain record begin time", err)
@@ -506,7 +506,7 @@ func GetCloudbrainsHoursData(ctx *context.Context) {
endTime := now
dateBeginTime := beginTime.Format("2006-01-02")
dateEndTime := endTime.Format("2006-01-02")
hourPeriodCount, err = models.GetHourPeriodCount(dateBeginTime, dateEndTime)
hourPeriodCount, err = models.GetCreateHourPeriodCount(dateBeginTime, dateEndTime)
if err != nil {
log.Error("Can not query hourPeriodCount.", err)
ctx.Error(http.StatusBadRequest, ctx.Tr("hourPeriodCount_get_error"))
@@ -522,6 +522,39 @@ func GetCloudbrainsHoursData(ctx *context.Context) {
"hourPeriodCount": hourPeriodCount,
})

}
func GetCloudbrainsRunHoursData(ctx *context.Context) {
runHourPeriodCount := make(map[string]interface{})
brainRecordBeginTime, err := getBrainRecordBeginTime()
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"))
return
}
queryType := ctx.QueryTrim("type")
now := time.Now()
if queryType != "" {
if queryType == "all" {
beginTime := brainRecordBeginTime
endTime := now
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
}
} else {
return
}
} else {
return
}
ctx.JSON(http.StatusOK, map[string]interface{}{
"runHourPeriodCount": runHourPeriodCount,
})

}

func getCloudbrainCount(beginTime time.Time, endTime time.Time) (int64, int64, int64, int64, int64, int64, int64, int64, int64, error) {


Loading…
Cancel
Save