Browse Source

Merge pull request 'fix-3244' (#3278) from fix-3244 into V20221130

Reviewed-on: https://openi.pcl.ac.cn/OpenI/aiforge/pulls/3278
Reviewed-by: zouap <zouap@pcl.ac.cn>
tags/v1.22.11.3^2
zouap 3 years ago
parent
commit
54a32dbd40
3 changed files with 96 additions and 66 deletions
  1. +55
    -0
      models/cloudbrain.go
  2. +40
    -64
      routers/api/v1/repo/cloudbrain_dashboard.go
  3. +1
    -2
      routers/repo/cloudbrain_statistic.go

+ 55
- 0
models/cloudbrain.go View File

@@ -2344,6 +2344,61 @@ func CloudbrainAllStatic(opts *CloudbrainsOptions) ([]*CloudbrainInfo, int64, er
return cloudbrains, count, nil return cloudbrains, count, nil
} }


func CloudbrainAllKanBan(opts *CloudbrainsOptions) ([]*CloudbrainInfo, int64, error) {
sess := x.NewSession()
defer sess.Close()

var cond = builder.NewCond()

if (opts.Type) >= 0 {
cond = cond.And(
builder.Eq{"cloudbrain.type": opts.Type},
)
}
if opts.BeginTimeUnix > 0 && opts.EndTimeUnix > 0 {
cond = cond.And(
builder.And(builder.Gte{"cloudbrain.created_unix": opts.BeginTimeUnix}, builder.Lte{"cloudbrain.created_unix": opts.EndTimeUnix}),
)
}
var count int64
var err error
count, err = sess.Unscoped().Where(cond).Count(new(Cloudbrain))

if err != nil {
return nil, 0, fmt.Errorf("Count: %v", err)
}

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.Cols("id", "type", "work_server_number", "duration", "train_job_duration", "ai_center", "cluster").Table(&Cloudbrain{}).Unscoped().Where(cond).
Find(&cloudbrains); err != nil {
return nil, 0, fmt.Errorf("Find: %v", err)
}
if opts.NeedRepoInfo {
var ids []int64
for _, task := range cloudbrains {
ids = append(ids, task.RepoID)
}
repositoryMap, err := GetRepositoriesMapByIDs(ids)
if err == nil {
for _, task := range cloudbrains {
task.Repo = repositoryMap[task.RepoID]
}
}

}
return cloudbrains, count, nil
}

func GetStartedCloudbrainTaskByUpdatedUnix(startTime, endTime time.Time) ([]Cloudbrain, error) { func GetStartedCloudbrainTaskByUpdatedUnix(startTime, endTime time.Time) ([]Cloudbrain, error) {
r := make([]Cloudbrain, 0) r := make([]Cloudbrain, 0)
err := x.Where("updated_unix >= ? and updated_unix <= ? and start_time > 0", startTime.Unix(), endTime.Unix()).Unscoped().Find(&r) err := x.Where("updated_unix >= ? and updated_unix <= ? and start_time > 0", startTime.Unix(), endTime.Unix()).Unscoped().Find(&r)


+ 40
- 64
routers/api/v1/repo/cloudbrain_dashboard.go View File

@@ -58,42 +58,30 @@ func GetAllCloudbrainsOverview(ctx *context.Context) {
return return
} }
cloudbrainTypeCount, err := models.GetCloudbrainTypeCount() cloudbrainTypeCount, err := models.GetCloudbrainTypeCount()
log.Info("cloudbrainTypeCount:", cloudbrainTypeCount)
if err != nil { if err != nil {
log.Error("Can not query cloudbrainTypeCount.", err) log.Error("Can not query cloudbrainTypeCount.", err)
return return
} }


cloudbrainTpyeDurationSum, err := models.GetCloudbrainTpyeDurationSum()
log.Info("cloudbrainTpyeDurationSum:", cloudbrainTpyeDurationSum)
if err != nil {
log.Error("Can not query cloudbrainTpyeDurationSum.", err)
return
}

todayCloudbrainCount, err := models.GetTodayCloudbrainCount(beginTime, endTime) todayCloudbrainCount, err := models.GetTodayCloudbrainCount(beginTime, endTime)
log.Info("todayCloudbrainCount:", todayCloudbrainCount)
if err != nil { if err != nil {
log.Error("Can not query todayCloudbrainCount.", err) log.Error("Can not query todayCloudbrainCount.", err)
return return
} }


todayRunningCount, err := models.GetTodayRunningCount(beginTime, endTime) todayRunningCount, err := models.GetTodayRunningCount(beginTime, endTime)
log.Info("todayRunningCount:", todayRunningCount)
if err != nil { if err != nil {
log.Error("Can not query todayRunningCount.", err) log.Error("Can not query todayRunningCount.", err)
return return
} }


todayWaitingCount, err := models.GetTodayWaitingCount(beginTime, endTime) todayWaitingCount, err := models.GetTodayWaitingCount(beginTime, endTime)
log.Info("todayWaittingCount:", todayWaitingCount)
if err != nil { if err != nil {
log.Error("Can not query todayWaitingCount.", err) log.Error("Can not query todayWaitingCount.", err)
return return
} }


todayCompletedCount := todayCloudbrainCount - todayRunningCount - todayWaitingCount todayCompletedCount := todayCloudbrainCount - todayRunningCount - todayWaitingCount
log.Info("todayCompletedCount:", todayCompletedCount)


creatorCount, err := models.GetCreatorCount() creatorCount, err := models.GetCreatorCount()
if err != nil { if err != nil {
@@ -139,60 +127,48 @@ func GetOverviewDuration(ctx *context.Context) {
c2NetDuration := int64(0) c2NetDuration := int64(0)
cDCenterDuration := int64(0) cDCenterDuration := int64(0)


page := 1
pagesize := 10000
count := pagesize
// Each time a maximum of 10000 pieces of data are detected to the memory, batch processing
for count == pagesize && count != 0 {
cloudbrains, _, err := models.CloudbrainAllStatic(&models.CloudbrainsOptions{
ListOptions: models.ListOptions{
Page: page,
PageSize: pagesize,
},
Type: models.TypeCloudBrainAll,
BeginTimeUnix: int64(recordBeginTime),
EndTimeUnix: endTime.Unix(),
})
if err != nil {
ctx.ServerError("Get cloudbrains failed:", err)
return
}
models.LoadSpecs4CloudbrainInfo(cloudbrains)

for _, cloudbrain := range cloudbrains {
cloudbrain = cloudbrainService.UpdateCloudbrainAiCenter(cloudbrain)
if cloudbrain.Cloudbrain.Spec != nil {
cardNum = int64(cloudbrain.Cloudbrain.Spec.AccCardsNum)
} else {
cardNum = 1
}
if cloudbrain.Cloudbrain.WorkServerNumber >= 1 {
workServerNumber = int64(cloudbrain.Cloudbrain.WorkServerNumber)
} else {
workServerNumber = 1
}
duration := models.ConvertStrToDuration(cloudbrain.TrainJobDuration)
CardDuration := workServerNumber * int64(cardNum) * duration

if cloudbrain.Cloudbrain.Type == models.TypeCloudBrainOne {
cloudBrainOneDuration += duration
cloudBrainOneCardDuSum += CardDuration
} else if cloudbrain.Cloudbrain.Type == models.TypeCloudBrainTwo {
cloudBrainTwoDuration += duration
cloudBrainTwoCardDuSum += CardDuration
} else if cloudbrain.Cloudbrain.Type == models.TypeC2Net {
c2NetDuration += duration
c2NetCardDuSum += CardDuration
} else if cloudbrain.Cloudbrain.Type == models.TypeCDCenter {
cDCenterDuration += duration
cDNetCardDuSum += CardDuration
}
cloudbrains, _, err := models.CloudbrainAllKanBan(&models.CloudbrainsOptions{
Type: models.TypeCloudBrainAll,
BeginTimeUnix: int64(recordBeginTime),
EndTimeUnix: endTime.Unix(),
})
if err != nil {
ctx.ServerError("Get cloudbrains failed:", err)
return
}
models.LoadSpecs4CloudbrainInfo(cloudbrains)


durationAllSum += duration
cardDuSum += CardDuration
for _, cloudbrain := range cloudbrains {
cloudbrain = cloudbrainService.UpdateCloudbrainAiCenter(cloudbrain)
if cloudbrain.Cloudbrain.Spec != nil {
cardNum = int64(cloudbrain.Cloudbrain.Spec.AccCardsNum)
} else {
cardNum = 1
} }
count = len(cloudbrains)
page += 1
if cloudbrain.Cloudbrain.WorkServerNumber >= 1 {
workServerNumber = int64(cloudbrain.Cloudbrain.WorkServerNumber)
} else {
workServerNumber = 1
}
duration := models.ConvertStrToDuration(cloudbrain.TrainJobDuration)
CardDuration := workServerNumber * int64(cardNum) * duration

if cloudbrain.Cloudbrain.Type == models.TypeCloudBrainOne {
cloudBrainOneDuration += duration
cloudBrainOneCardDuSum += CardDuration
} else if cloudbrain.Cloudbrain.Type == models.TypeCloudBrainTwo {
cloudBrainTwoDuration += duration
cloudBrainTwoCardDuSum += CardDuration
} else if cloudbrain.Cloudbrain.Type == models.TypeC2Net {
c2NetDuration += duration
c2NetCardDuSum += CardDuration
} else if cloudbrain.Cloudbrain.Type == models.TypeCDCenter {
cDCenterDuration += duration
cDNetCardDuSum += CardDuration
}

durationAllSum += duration
cardDuSum += CardDuration
} }
ctx.JSON(http.StatusOK, map[string]interface{}{ ctx.JSON(http.StatusOK, map[string]interface{}{
"cloudBrainOneCardDuSum": cloudBrainOneCardDuSum, "cloudBrainOneCardDuSum": cloudBrainOneCardDuSum,


+ 1
- 2
routers/repo/cloudbrain_statistic.go View File

@@ -26,9 +26,8 @@ func CloudbrainDurationStatisticHour() {
} else { } else {
statisticTime = currentTime statisticTime = currentTime
} }
deleteBeginTime := time.Unix(int64(recordDurationUpdateTime[0].DateTime), 0)


err = models.DeleteCloudbrainDurationStatistic(timeutil.TimeStamp(deleteBeginTime.Unix()), timeutil.TimeStamp(currentTime.Unix()))
err = models.DeleteCloudbrainDurationStatistic(timeutil.TimeStamp(statisticTime.Unix()), timeutil.TimeStamp(currentTime.Unix()))
if err != nil { if err != nil {
log.Error("DeleteCloudbrainDurationStatistic failed", err) log.Error("DeleteCloudbrainDurationStatistic failed", err)
} }


Loading…
Cancel
Save