package models import ( "strconv" "time" "code.gitea.io/gitea/modules/timeutil" ) // Cloudbrain statistic info of all CloudbrainTasks type CloudbrainStatistic struct { ID int64 `xorm:"pk autoincr" json:"-"` Date string `xorm:"unique(s) NOT NULL" json:"date"` 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"` CreatedUnix timeutil.TimeStamp `xorm:"INDEX created" json:"-"` UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated" json:"-"` } func GenerateDebugOneCount(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(JobTypeDebug) + "'" + " and type='" + strconv.Itoa(TypeCloudBrainOne) + "'" return x.SQL(countSql).Count() } func GenerateBenchmarkOneCount(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(JobTypeBenchmark) + "'" + " and type='" + strconv.Itoa(TypeCloudBrainOne) + "'" return x.SQL(countSql).Count() } func GenerateDebugTwoCount(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(JobTypeDebug) + "'" + " and type='" + strconv.Itoa(TypeCloudBrainTwo) + "'" return x.SQL(countSql).Count() } func GenerateTrainTwoCount(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(TypeCloudBrainTwo) + "'" return x.SQL(countSql).Count() } func GenerateInferenceTwoCount(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(JobTypeInference) + "'" + " and type='" + strconv.Itoa(TypeCloudBrainTwo) + "'" return x.SQL(countSql).Count() }