Browse Source

update

tags/v1.22.11.1^2
liuzx 3 years ago
parent
commit
fc5692e781
3 changed files with 9 additions and 51 deletions
  1. +1
    -33
      models/cloudbrain_static.go
  2. +8
    -16
      routers/api/v1/repo/cloudbrain_dashboard.go
  3. +0
    -2
      routers/repo/cloudbrain_statistic.go

+ 1
- 33
models/cloudbrain_static.go View File

@@ -38,17 +38,6 @@ type TaskDetail struct {
WorkServerNum int64 `json:"WorkServerNum"`
Spec *Specification `json:"Spec"`
}
type CardTypeAndNum struct {
CardType string `json:"CardType"`
Num int `json:"Num"`
ComputeResource string `json:"computeResource"`
}
type ResourceOverview struct {
Cluster string `json:"cluster"`
AiCenterName string `json:"aiCenterName"`
AiCenterCode string `json:"aiCenterCode"`
CardTypeAndNum []CardTypeAndNum `json:"cardTypeAndNum"`
}

type CloudbrainDurationStatistic struct {
ID int64 `xorm:"pk autoincr"`
@@ -78,7 +67,7 @@ type DurationStatisticOptions struct {
type DurationRateStatistic struct {
AiCenterTotalDurationStat map[string]int `json:"aiCenterTotalDurationStat"`
AiCenterUsageDurationStat map[string]int `json:"aiCenterUsageDurationStat"`
UsageRate map[string]float32 `json:"UsageRate"`
UsageRate map[string]float64 `json:"UsageRate"`
}
type ResourceDetail struct {
QueueCode string
@@ -89,15 +78,8 @@ type ResourceDetail struct {
AccCardType string
CardsTotalNum int
IsAutomaticSync bool
// CardTypeAndNum []CardTypeAndNum `json:"cardTypeAndNum"`
}

// type DateCloudbrainStatistic struct {
// Date string `json:"date"`
// AiCenterUsageDuration map[string]int `json:"aiCenterUsageDuration"`
// AiCenterTotalDuration map[string]int `json:"aiCenterTotalDuration"`
// AiCenterUsageRate map[string]float64 `json:"aiCenterUsageRate"`
// }
type DateUsageStatistic struct {
Date string `json:"date"`
UsageDuration int `json:"usageDuration"`
@@ -347,26 +329,12 @@ func DeleteCloudbrainDurationStatisticHour(date string, hour int, aiCenterCode s
func GetCanUseCardInfo() ([]*ResourceQueue, error) {
sess := x.NewSession()
defer sess.Close()
// var cond = builder.NewCond()
// cond = cond.And(
// builder.And(builder.Eq{"resource_queue.is_automatic_sync": false}),
// )
sess.OrderBy("resource_queue.id ASC")
ResourceQueues := make([]*ResourceQueue, 0, 10)
if err := sess.Table(&ResourceQueue{}).Find(&ResourceQueues); err != nil {
log.Info("find error.")
}
return ResourceQueues, nil
// Cols("queue_code", "cluster", "ai_center_name", "ai_center_code", "compute_resource", "acc_card_type", "cards_total_num")
// sess := x.NewSession()
// defer sess.Close()
// sess.OrderBy("resource_queue.id ASC limit 1")
// cloudbrains := make([]*CloudbrainInfo, 0)
// if err := sess.Table(&Cloudbrain{}).Unscoped().
// Find(&cloudbrains); err != nil {
// log.Info("find error.")
// }
// return cloudbrains, nil
}

func GetCardDurationStatistics(opts *DurationStatisticOptions) ([]*CloudbrainDurationStatistic, error) {


+ 8
- 16
routers/api/v1/repo/cloudbrain_dashboard.go View File

@@ -1663,10 +1663,10 @@ func getAiCenterUsageDuration(beginTime time.Time, endTime time.Time, cloudbrain
return totalDuration, usageDuration, usageRate
}

func getDurationStatistic(beginTime time.Time, endTime time.Time) (models.DurationRateStatistic, models.DurationRateStatistic, float32) {
func getDurationStatistic(beginTime time.Time, endTime time.Time) (models.DurationRateStatistic, models.DurationRateStatistic, float64) {
OpenITotalDuration := make(map[string]int)
OpenIUsageDuration := make(map[string]int)
OpenIUsageRate := make(map[string]float32)
OpenIUsageRate := make(map[string]float64)
C2NetTotalDuration := make(map[string]int)
C2NetUsageDuration := make(map[string]int)
OpenIDurationRate := models.DurationRateStatistic{}
@@ -1717,7 +1717,6 @@ func getDurationStatistic(beginTime time.Time, endTime time.Time) (models.Durati
return OpenIDurationRate, C2NetDurationRate, 0
}
for _, v := range ResourceAiCenterRes {
// if v.AiCenterCode != models.AICenterOfCloudBrainOne && v.AiCenterCode != models.AICenterOfCloudBrainTwo {
if cutString(v.AiCenterCode, 4) == cutString(models.AICenterOfCloudBrainOne, 4) {
if _, ok := OpenIUsageDuration[v.AiCenterName]; !ok {
OpenIUsageDuration[v.AiCenterName] = 0
@@ -1731,36 +1730,33 @@ func getDurationStatistic(beginTime time.Time, endTime time.Time) (models.Durati
}
}
}
totalCanUse := float32(0)
totalUse := float32(0)
totalUsageRate := float32(0)
totalCanUse := float64(0)
totalUse := float64(0)
totalUsageRate := float64(0)
for k, v := range OpenITotalDuration {
for i, j := range OpenIUsageDuration {
if k == i {
OpenIUsageRate[k] = float32(j) / float32(v)
OpenIUsageRate[k] = float64(j) / float64(v)
}
}
}
for _, v := range OpenITotalDuration {
totalCanUse += float32(v)
totalCanUse += float64(v)
}
for _, v := range OpenIUsageRate {
totalUse += float32(v)
totalUse += float64(v)
}
if totalCanUse == 0 || totalUse == 0 {
totalUsageRate = 0
} else {
totalUsageRate = totalUse / totalCanUse
}
// totalUsageRate = totalUse / totalCanUse
// strconv.FormatFloat(*100, 'f', 4, 64) + "%"

OpenIDurationRate.AiCenterTotalDurationStat = OpenITotalDuration
OpenIDurationRate.AiCenterUsageDurationStat = OpenIUsageDuration
OpenIDurationRate.UsageRate = OpenIUsageRate
C2NetDurationRate.AiCenterTotalDurationStat = C2NetTotalDuration
C2NetDurationRate.AiCenterUsageDurationStat = C2NetUsageDuration
// C2NetDurationRate.TotalUsageRate = totalUsageRate
return OpenIDurationRate, C2NetDurationRate, totalUsageRate
}

@@ -1846,10 +1842,6 @@ func getHourCloudbrainDuration(beginTime time.Time, endTime time.Time, aiCenterC
if _, ok := hourTimeTotalDuration[v]; !ok {
hourTimeTotalDuration[v] = 0
}
// if _, ok := hourTimeUsageRate[v]; !ok {
// hourTimeUsageRate[v] = 0
// }

}

for k, v := range hourTimeTotalDuration {


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

@@ -42,7 +42,6 @@ func CloudbrainDurationStatisticHour() {
log.Info("GetSpecByAiCenterCodeAndType err: %v", err)
return
}
log.Info("cloudbrain: %s", cloudbrain)
if cloudbrain != nil {
totalCanUse := false
if err := models.DeleteCloudbrainDurationStatisticHour(dayTime, hourTime, centerCode, cardType, totalCanUse); err != nil {
@@ -107,7 +106,6 @@ func CloudbrainDurationStatisticHour() {
func getcloudBrainCenterCodeAndCardTypeInfo(ciTasks []*models.CloudbrainInfo, beginTime int64, endTime int64) map[string]map[string]int {
var WorkServerNumber int
var AccCardsNum int
// cloudBrainCardRes := make(map[string]int)
cloudBrainAiCenterCodeList := make(map[string]string)
cloudBrainCardTypeList := make(map[string]string)
cloudBrainCenterCodeAndCardType := make(map[string]map[string]int)


Loading…
Cancel
Save