|
|
|
@@ -1,9 +1,11 @@ |
|
|
|
package models |
|
|
|
|
|
|
|
import ( |
|
|
|
"fmt" |
|
|
|
"strconv" |
|
|
|
"time" |
|
|
|
|
|
|
|
"code.gitea.io/gitea/modules/log" |
|
|
|
"code.gitea.io/gitea/modules/timeutil" |
|
|
|
) |
|
|
|
|
|
|
|
@@ -11,12 +13,24 @@ import ( |
|
|
|
type CloudbrainStatistic struct { |
|
|
|
ID int64 `xorm:"pk autoincr" json:"-"` |
|
|
|
Date string `xorm:"unique(s) NOT NULL" json:"date"` |
|
|
|
WhichHour int64 `xorm:"NOT NULL DEFAULT -1" json:"whichHour"` |
|
|
|
NumDubugOne int64 `xorm:"NOT NULL DEFAULT 0" json:"numDubugOne"` |
|
|
|
NumBenchmarkOne int64 `xorm:"NOT NULL DEFAULT 0" json:"numBenchmarkOne"` |
|
|
|
NumTrainOne int64 `xorm:"NOT NULL DEFAULT 0" json:"numTrainOne"` |
|
|
|
NumDubugTwo int64 `xorm:"NOT NULL DEFAULT 0" json:"numDubugTwo"` |
|
|
|
NumTrainTwo int64 `xorm:"NOT NULL DEFAULT 0" json:"numTrainTwo"` |
|
|
|
NumInferenceTwo int64 `xorm:"NOT NULL DEFAULT 0" json:"numInferenceTwo"` |
|
|
|
NumCloudOneAll int64 `xorm:"NOT NULL DEFAULT 0" json:"numCloudOneAll"` |
|
|
|
NumCloudTwoAll int64 `xorm:"NOT NULL DEFAULT 0" json:"numCloudTwoAll"` |
|
|
|
|
|
|
|
DurationDubugOne int64 `xorm:"NOT NULL DEFAULT 0" json:"durationDubugOne"` |
|
|
|
DurationBenchmarkOne int64 `xorm:"NOT NULL DEFAULT 0" json:"durationBenchmarkOne"` |
|
|
|
DurationTrainOne int64 `xorm:"NOT NULL DEFAULT 0" json:"durationTrainOne"` |
|
|
|
DurationDebugTwo int64 `xorm:"NOT NULL DEFAULT 0" json:"durationDebugTwo"` |
|
|
|
DurationTrainTwo int64 `xorm:"NOT NULL DEFAULT 0" json:"durationTrainTwo"` |
|
|
|
DurationInferenceTwo int64 `xorm:"NOT NULL DEFAULT 0" json:"durationInferenceTwo"` |
|
|
|
DurationCloudOneAll int64 `xorm:"NOT NULL DEFAULT 0" json:"durationCloudOneAll"` |
|
|
|
DurationCloudTwoAll int64 `xorm:"NOT NULL DEFAULT 0" json:"durationCloudTwoAll"` |
|
|
|
|
|
|
|
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created" json:"-"` |
|
|
|
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated" json:"-"` |
|
|
|
@@ -31,6 +45,32 @@ func GenerateDebugOneCount(beginTime time.Time, endTime time.Time) (int64, error |
|
|
|
|
|
|
|
return x.SQL(countSql).Count() |
|
|
|
} |
|
|
|
func GetDebugOneDuration(beginTime time.Time, endTime time.Time) (int64, error) { |
|
|
|
total, err := x.Where("created_unix >= ? And created_unix < ? And job_type = ? And type = ? ", strconv.FormatInt(beginTime.Unix(), 10), strconv.FormatInt(endTime.Unix(), 10), JobTypeDebug, TypeCloudBrainOne).SumInt(&Cloudbrain{}, "duration") |
|
|
|
if err != nil { |
|
|
|
return 0, err |
|
|
|
} |
|
|
|
|
|
|
|
return total, nil |
|
|
|
} |
|
|
|
|
|
|
|
func GenerateTrainOneCount(beginTime time.Time, endTime time.Time) (int64, error) { |
|
|
|
countSql := "SELECT count(*) FROM " + |
|
|
|
"public.cloudbrain where created_unix >=" + strconv.FormatInt(beginTime.Unix(), 10) + |
|
|
|
" and created_unix<" + strconv.FormatInt(endTime.Unix(), 10) + |
|
|
|
" and job_type ='" + string(JobTypeTrain) + "'" + |
|
|
|
" and type='" + strconv.Itoa(TypeCloudBrainOne) + "'" |
|
|
|
|
|
|
|
return x.SQL(countSql).Count() |
|
|
|
} |
|
|
|
func GetTrainOneDuration(beginTime time.Time, endTime time.Time) (int64, error) { |
|
|
|
total, err := x.Where("created_unix >= ? And created_unix < ? And job_type = ? And type = ? ", strconv.FormatInt(beginTime.Unix(), 10), strconv.FormatInt(endTime.Unix(), 10), JobTypeTrain, TypeCloudBrainOne).SumInt(&Cloudbrain{}, "duration") |
|
|
|
if err != nil { |
|
|
|
return 0, err |
|
|
|
} |
|
|
|
|
|
|
|
return total, nil |
|
|
|
} |
|
|
|
|
|
|
|
func GenerateBenchmarkOneCount(beginTime time.Time, endTime time.Time) (int64, error) { |
|
|
|
countSql := "SELECT count(*) FROM " + |
|
|
|
@@ -40,6 +80,14 @@ func GenerateBenchmarkOneCount(beginTime time.Time, endTime time.Time) (int64, e |
|
|
|
" and type='" + strconv.Itoa(TypeCloudBrainOne) + "'" |
|
|
|
return x.SQL(countSql).Count() |
|
|
|
} |
|
|
|
func GetBenchmarkOneDuration(beginTime time.Time, endTime time.Time) (int64, error) { |
|
|
|
total, err := x.Where("created_unix >= ? And created_unix < ? And job_type = ? And type = ? ", strconv.FormatInt(beginTime.Unix(), 10), strconv.FormatInt(endTime.Unix(), 10), JobTypeBenchmark, TypeCloudBrainOne).SumInt(&Cloudbrain{}, "duration") |
|
|
|
if err != nil { |
|
|
|
return 0, err |
|
|
|
} |
|
|
|
|
|
|
|
return total, nil |
|
|
|
} |
|
|
|
func GenerateDebugTwoCount(beginTime time.Time, endTime time.Time) (int64, error) { |
|
|
|
countSql := "SELECT count(*) FROM " + |
|
|
|
"public.cloudbrain where created_unix >=" + strconv.FormatInt(beginTime.Unix(), 10) + |
|
|
|
@@ -48,6 +96,13 @@ func GenerateDebugTwoCount(beginTime time.Time, endTime time.Time) (int64, error |
|
|
|
" and type='" + strconv.Itoa(TypeCloudBrainTwo) + "'" |
|
|
|
return x.SQL(countSql).Count() |
|
|
|
} |
|
|
|
func GetDebugTwoDuration(beginTime time.Time, endTime time.Time) (int64, error) { |
|
|
|
total, err := x.Where("created_unix >= ? And created_unix < ? And job_type = ? And type = ? ", strconv.FormatInt(beginTime.Unix(), 10), strconv.FormatInt(endTime.Unix(), 10), JobTypeDebug, TypeCloudBrainTwo).SumInt(&Cloudbrain{}, "duration") |
|
|
|
if err != nil { |
|
|
|
return 0, err |
|
|
|
} |
|
|
|
return total, nil |
|
|
|
} |
|
|
|
func GenerateTrainTwoCount(beginTime time.Time, endTime time.Time) (int64, error) { |
|
|
|
countSql := "SELECT count(*) FROM " + |
|
|
|
"public.cloudbrain where created_unix >=" + strconv.FormatInt(beginTime.Unix(), 10) + |
|
|
|
@@ -56,6 +111,13 @@ func GenerateTrainTwoCount(beginTime time.Time, endTime time.Time) (int64, error |
|
|
|
" and type='" + strconv.Itoa(TypeCloudBrainTwo) + "'" |
|
|
|
return x.SQL(countSql).Count() |
|
|
|
} |
|
|
|
func GetTrainTwoDuration(beginTime time.Time, endTime time.Time) (int64, error) { |
|
|
|
total, err := x.Where("created_unix >= ? And created_unix < ? And job_type = ? And type = ? ", strconv.FormatInt(beginTime.Unix(), 10), strconv.FormatInt(endTime.Unix(), 10), JobTypeTrain, TypeCloudBrainTwo).SumInt(&Cloudbrain{}, "duration") |
|
|
|
if err != nil { |
|
|
|
return 0, err |
|
|
|
} |
|
|
|
return total, nil |
|
|
|
} |
|
|
|
func GenerateInferenceTwoCount(beginTime time.Time, endTime time.Time) (int64, error) { |
|
|
|
countSql := "SELECT count(*) FROM " + |
|
|
|
"public.cloudbrain where created_unix >=" + strconv.FormatInt(beginTime.Unix(), 10) + |
|
|
|
@@ -64,3 +126,60 @@ func GenerateInferenceTwoCount(beginTime time.Time, endTime time.Time) (int64, e |
|
|
|
" and type='" + strconv.Itoa(TypeCloudBrainTwo) + "'" |
|
|
|
return x.SQL(countSql).Count() |
|
|
|
} |
|
|
|
func GetInferenceTwoDuration(beginTime time.Time, endTime time.Time) (int64, error) { |
|
|
|
total, err := x.Where("created_unix >= ? And created_unix < ? And job_type = ? And type = ? ", strconv.FormatInt(beginTime.Unix(), 10), strconv.FormatInt(endTime.Unix(), 10), JobTypeInference, TypeCloudBrainTwo).SumInt(&Cloudbrain{}, "duration") |
|
|
|
if err != nil { |
|
|
|
return 0, err |
|
|
|
} |
|
|
|
return total, nil |
|
|
|
} |
|
|
|
|
|
|
|
func DeleteCloudbrainStatisticDaily(date string) error { |
|
|
|
sess := xStatistic.NewSession() |
|
|
|
defer sess.Close() |
|
|
|
if err := sess.Begin(); err != nil { |
|
|
|
return fmt.Errorf("Begin: %v", err) |
|
|
|
} |
|
|
|
|
|
|
|
if _, err := sess.Where("date = ?", date).Delete(&CloudbrainStatistic{}); err != nil { |
|
|
|
return fmt.Errorf("Delete: %v", err) |
|
|
|
} |
|
|
|
|
|
|
|
if err := sess.Commit(); err != nil { |
|
|
|
sess.Close() |
|
|
|
return fmt.Errorf("Commit: %v", err) |
|
|
|
} |
|
|
|
|
|
|
|
sess.Close() |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
func GetHourStatTime(timeStr string, whichHour int64) (time.Time, time.Time) { |
|
|
|
t, _ := time.Parse("2006-01-02", timeStr) |
|
|
|
timeNumber := t.Unix() |
|
|
|
beginTimeNumber := timeNumber - 8*60*60 + whichHour*60*60 |
|
|
|
endTimeNumber := beginTimeNumber + 1*60*60 |
|
|
|
beginTime := time.Unix(beginTimeNumber, 0) |
|
|
|
endTime := time.Unix(endTimeNumber, 0) |
|
|
|
log.Info("%s, %s", beginTime, endTime) |
|
|
|
|
|
|
|
return beginTime, endTime |
|
|
|
} |
|
|
|
func GetDayStatTime(timeStr string) (time.Time, time.Time) { |
|
|
|
t, _ := time.Parse("2006-01-02", timeStr) |
|
|
|
timeNumber := t.Unix() |
|
|
|
beginTimeNumber := timeNumber - 8*60*60 |
|
|
|
endTimeNumber := beginTimeNumber + 16*60*60 |
|
|
|
beginTime := time.Unix(beginTimeNumber, 0) |
|
|
|
endTime := time.Unix(endTimeNumber, 0) |
|
|
|
log.Info("%s, %s", beginTime, endTime) |
|
|
|
|
|
|
|
return beginTime, endTime |
|
|
|
} |
|
|
|
|
|
|
|
func CreateCloudbrainStatistic(cloudbrainStat *CloudbrainStatistic) (err error) { |
|
|
|
if _, err = xStatistic.Insert(cloudbrainStat); err != nil { |
|
|
|
return err |
|
|
|
} |
|
|
|
return nil |
|
|
|
} |