|
|
|
@@ -1577,10 +1577,12 @@ func GetCloudbrainResourceUsageDetail(ctx *context.Context) { |
|
|
|
|
|
|
|
func GetDurationRateStatistic(ctx *context.Context) { |
|
|
|
beginTime, endTime := getBeginAndEndTime(ctx) |
|
|
|
durationRateStatistic := getDurationStatistic(beginTime, endTime) |
|
|
|
OpenIDurationRate, C2NetDurationRate, totalUsageRate := getDurationStatistic(beginTime, endTime) |
|
|
|
|
|
|
|
ctx.JSON(http.StatusOK, map[string]interface{}{ |
|
|
|
"durationRateStatistic": durationRateStatistic, |
|
|
|
"openIDurationRate": OpenIDurationRate, |
|
|
|
"c2NetDurationRate": C2NetDurationRate, |
|
|
|
"totalUsageRate": totalUsageRate, |
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
@@ -1719,59 +1721,91 @@ func getAiCenterUsageDuration(beginTime time.Time, endTime time.Time, cloudbrain |
|
|
|
return totalDuration, usageDuration, usageRate |
|
|
|
} |
|
|
|
|
|
|
|
func getDurationStatistic(beginTime time.Time, endTime time.Time) models.DurationRateStatistic { |
|
|
|
aiCenterTotalDurationStat := make(map[string]int) |
|
|
|
aiCenterUsageDurationStat := make(map[string]int) |
|
|
|
durationRateStatistic := models.DurationRateStatistic{} |
|
|
|
func getDurationStatistic(beginTime time.Time, endTime time.Time) (models.DurationRateStatistic, models.DurationRateStatistic, float32) { |
|
|
|
OpenITotalDuration := make(map[string]int) |
|
|
|
OpenIUsageDuration := make(map[string]int) |
|
|
|
OpenIUsageRate := make(map[string]float32) |
|
|
|
C2NetTotalDuration := make(map[string]int) |
|
|
|
C2NetUsageDuration := make(map[string]int) |
|
|
|
OpenIDurationRate := models.DurationRateStatistic{} |
|
|
|
C2NetDurationRate := models.DurationRateStatistic{} |
|
|
|
cardDurationStatistics, err := models.GetCardDurationStatistics(&models.DurationStatisticOptions{ |
|
|
|
BeginTime: beginTime, |
|
|
|
EndTime: endTime, |
|
|
|
}) |
|
|
|
if err != nil { |
|
|
|
log.Error("GetCardDurationStatistics error:", err) |
|
|
|
return durationRateStatistic |
|
|
|
return OpenIDurationRate, C2NetDurationRate, 0 |
|
|
|
} |
|
|
|
for _, cloudbrainStatistic := range cardDurationStatistics { |
|
|
|
if cloudbrainStatistic.TotalCanUse { |
|
|
|
if _, ok := aiCenterTotalDurationStat[cloudbrainStatistic.AiCenterCode]; !ok { |
|
|
|
aiCenterTotalDurationStat[cloudbrainStatistic.AiCenterCode] = cloudbrainStatistic.CardsTotalDuration |
|
|
|
if cloudbrainStatistic.Cluster == models.OpenICluster { |
|
|
|
if cloudbrainStatistic.TotalCanUse { |
|
|
|
if _, ok := OpenITotalDuration[cloudbrainStatistic.AiCenterName]; !ok { |
|
|
|
OpenITotalDuration[cloudbrainStatistic.AiCenterName] = cloudbrainStatistic.CardsTotalDuration |
|
|
|
} else { |
|
|
|
OpenITotalDuration[cloudbrainStatistic.AiCenterName] += cloudbrainStatistic.CardsTotalDuration |
|
|
|
} |
|
|
|
} else { |
|
|
|
aiCenterTotalDurationStat[cloudbrainStatistic.AiCenterCode] += cloudbrainStatistic.CardsTotalDuration |
|
|
|
if _, ok := OpenIUsageDuration[cloudbrainStatistic.AiCenterName]; !ok { |
|
|
|
OpenIUsageDuration[cloudbrainStatistic.AiCenterName] = cloudbrainStatistic.CardsTotalDuration |
|
|
|
} else { |
|
|
|
OpenIUsageDuration[cloudbrainStatistic.AiCenterName] += cloudbrainStatistic.CardsTotalDuration |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
if _, ok := aiCenterUsageDurationStat[cloudbrainStatistic.AiCenterCode]; !ok { |
|
|
|
aiCenterUsageDurationStat[cloudbrainStatistic.AiCenterCode] = cloudbrainStatistic.CardsTotalDuration |
|
|
|
} |
|
|
|
if cloudbrainStatistic.Cluster == models.C2NetCluster { |
|
|
|
if cloudbrainStatistic.TotalCanUse { |
|
|
|
if _, ok := C2NetTotalDuration[cloudbrainStatistic.AiCenterName]; !ok { |
|
|
|
C2NetTotalDuration[cloudbrainStatistic.AiCenterName] = cloudbrainStatistic.CardsTotalDuration |
|
|
|
} else { |
|
|
|
C2NetTotalDuration[cloudbrainStatistic.AiCenterName] += cloudbrainStatistic.CardsTotalDuration |
|
|
|
} |
|
|
|
} else { |
|
|
|
aiCenterUsageDurationStat[cloudbrainStatistic.AiCenterCode] += cloudbrainStatistic.CardsTotalDuration |
|
|
|
if _, ok := C2NetUsageDuration[cloudbrainStatistic.AiCenterName]; !ok { |
|
|
|
C2NetUsageDuration[cloudbrainStatistic.AiCenterName] = cloudbrainStatistic.CardsTotalDuration |
|
|
|
} else { |
|
|
|
C2NetUsageDuration[cloudbrainStatistic.AiCenterName] += cloudbrainStatistic.CardsTotalDuration |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
ResourceAiCenterRes, err := models.GetResourceAiCenters() |
|
|
|
if err != nil { |
|
|
|
log.Error("Can not get ResourceAiCenterRes.", err) |
|
|
|
return durationRateStatistic |
|
|
|
return OpenIDurationRate, C2NetDurationRate, 0 |
|
|
|
} |
|
|
|
for _, v := range ResourceAiCenterRes { |
|
|
|
if _, ok := aiCenterUsageDurationStat[v.AiCenterCode]; !ok { |
|
|
|
aiCenterUsageDurationStat[v.AiCenterCode] = 0 |
|
|
|
if v.AiCenterCode != models.AICenterOfCloudBrainOne && v.AiCenterCode != models.AICenterOfCloudBrainTwo { |
|
|
|
// if v.AiCenterCode != models.AICenterOfCloudBrainTwo { |
|
|
|
if _, ok := C2NetUsageDuration[v.AiCenterName]; !ok { |
|
|
|
C2NetUsageDuration[v.AiCenterName] = 0 |
|
|
|
} |
|
|
|
// } |
|
|
|
} else { |
|
|
|
if _, ok := OpenIUsageDuration[v.AiCenterName]; !ok { |
|
|
|
OpenIUsageDuration[v.AiCenterName] = 0 |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
totalCanUse := float64(0) |
|
|
|
totalUse := float64(0) |
|
|
|
for k, v := range aiCenterTotalDurationStat { |
|
|
|
for i, j := range aiCenterUsageDurationStat { |
|
|
|
// totalCanUse := float64(0) |
|
|
|
// totalUse := float64(0) |
|
|
|
totalUsageRate := float32(0) |
|
|
|
for k, v := range OpenITotalDuration { |
|
|
|
for i, j := range OpenIUsageDuration { |
|
|
|
if k == i { |
|
|
|
totalUse += float64(j) |
|
|
|
totalCanUse += float64(v) |
|
|
|
OpenIUsageRate[k] = float32(j) / float32(v) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
totalUsageRate := totalUse / totalCanUse |
|
|
|
// totalUsageRate := totalUse / totalCanUse |
|
|
|
|
|
|
|
durationRateStatistic.AiCenterTotalDurationStat = aiCenterTotalDurationStat |
|
|
|
durationRateStatistic.AiCenterUsageDurationStat = aiCenterUsageDurationStat |
|
|
|
durationRateStatistic.TotalUsageRate = totalUsageRate |
|
|
|
return durationRateStatistic |
|
|
|
OpenIDurationRate.AiCenterTotalDurationStat = OpenITotalDuration |
|
|
|
OpenIDurationRate.AiCenterUsageDurationStat = OpenIUsageDuration |
|
|
|
OpenIDurationRate.UsageRate = OpenIUsageRate |
|
|
|
C2NetDurationRate.AiCenterTotalDurationStat = C2NetTotalDuration |
|
|
|
C2NetDurationRate.AiCenterUsageDurationStat = C2NetUsageDuration |
|
|
|
// C2NetDurationRate.TotalUsageRate = totalUsageRate |
|
|
|
return OpenIDurationRate, C2NetDurationRate, totalUsageRate |
|
|
|
} |
|
|
|
|
|
|
|
func getDayCloudbrainDuration(beginTime time.Time, endTime time.Time, aiCenterCode string) ([]models.DateUsageStatistic, int, error) { |
|
|
|
|