| @@ -1725,6 +1725,37 @@ func GetCloudbrainsNeededStopByUserID(userID int64) ([]*Cloudbrain, error) { | |||||
| return cloudBrains, err | return cloudBrains, err | ||||
| } | } | ||||
| func GetWaittingTop() ([]*CloudbrainInfo, error) { | |||||
| sess := x.NewSession() | |||||
| defer sess.Close() | |||||
| var cond = builder.NewCond() | |||||
| cond = cond.And( | |||||
| builder.Eq{"cloudbrain.status": string(JobWaiting)}, | |||||
| ) | |||||
| sess.OrderBy("cloudbrain.created_unix ASC limit 1") | |||||
| cloudbrains := make([]*CloudbrainInfo, 0, 1) | |||||
| if err := sess.Table(&Cloudbrain{}).Where(cond). | |||||
| Find(&cloudbrains); err != nil { | |||||
| log.Info("find error.") | |||||
| } | |||||
| return cloudbrains, nil | |||||
| } | |||||
| func GetModelartsReDebugTaskByJobId(jobID string) ([]*Cloudbrain, error) { | |||||
| sess := x.NewSession() | |||||
| defer sess.Close() | |||||
| var cond = builder.NewCond() | |||||
| cond = cond.And( | |||||
| builder.Eq{"cloudbrain.job_id": jobID}, | |||||
| ) | |||||
| sess.OrderBy("cloudbrain.created_unix ASC limit 1") | |||||
| cloudbrains := make([]*Cloudbrain, 0, 10) | |||||
| if err := sess.Table(&Cloudbrain{}).Unscoped().Where(cond). | |||||
| Find(&cloudbrains); err != nil { | |||||
| log.Info("find error.") | |||||
| } | |||||
| return cloudbrains, nil | |||||
| } | |||||
| func GetCloudbrainsNeededStopByRepoID(repoID int64) ([]*Cloudbrain, error) { | func GetCloudbrainsNeededStopByRepoID(repoID int64) ([]*Cloudbrain, error) { | ||||
| cloudBrains := make([]*Cloudbrain, 0) | cloudBrains := make([]*Cloudbrain, 0) | ||||
| err := x.Cols("job_id", "status", "type", "job_type", "version_id", "start_time").Where("repo_id=? AND status !=?", repoID, string(JobStopped)).Find(&cloudBrains) | err := x.Cols("job_id", "status", "type", "job_type", "version_id", "start_time").Where("repo_id=? AND status !=?", repoID, string(JobStopped)).Find(&cloudBrains) | ||||
| @@ -2154,11 +2185,13 @@ var ( | |||||
| CloudbrainTrainResourceSpecsMap map[int]*ResourceSpec | CloudbrainTrainResourceSpecsMap map[int]*ResourceSpec | ||||
| CloudbrainInferenceResourceSpecsMap map[int]*ResourceSpec | CloudbrainInferenceResourceSpecsMap map[int]*ResourceSpec | ||||
| CloudbrainBenchmarkResourceSpecsMap map[int]*ResourceSpec | CloudbrainBenchmarkResourceSpecsMap map[int]*ResourceSpec | ||||
| CloudbrainSpecialResourceSpecsMap map[int]*ResourceSpec | |||||
| GpuInfosMapInitFlag = false | GpuInfosMapInitFlag = false | ||||
| CloudbrainDebugGpuInfosMap map[string]*GpuInfo | CloudbrainDebugGpuInfosMap map[string]*GpuInfo | ||||
| CloudbrainTrainGpuInfosMap map[string]*GpuInfo | CloudbrainTrainGpuInfosMap map[string]*GpuInfo | ||||
| CloudbrainInferenceGpuInfosMap map[string]*GpuInfo | CloudbrainInferenceGpuInfosMap map[string]*GpuInfo | ||||
| CloudbrainBenchmarkGpuInfosMap map[string]*GpuInfo | CloudbrainBenchmarkGpuInfosMap map[string]*GpuInfo | ||||
| CloudbrainSpecialGpuInfosMap map[string]*GpuInfo | |||||
| ) | ) | ||||
| func InitCloudbrainOneResourceSpecMap() { | func InitCloudbrainOneResourceSpecMap() { | ||||
| @@ -2194,6 +2227,16 @@ func InitCloudbrainOneResourceSpecMap() { | |||||
| CloudbrainBenchmarkResourceSpecsMap[spec.Id] = spec | CloudbrainBenchmarkResourceSpecsMap[spec.Id] = spec | ||||
| } | } | ||||
| } | } | ||||
| if CloudbrainSpecialResourceSpecsMap == nil || len(CloudbrainSpecialResourceSpecsMap) == 0 { | |||||
| t := SpecialPools{} | |||||
| json.Unmarshal([]byte(setting.SpecialPools), &t) | |||||
| for _, pool := range t.Pools { | |||||
| CloudbrainSpecialResourceSpecsMap = make(map[int]*ResourceSpec, len(pool.ResourceSpec)) | |||||
| for _, spec := range pool.ResourceSpec { | |||||
| CloudbrainSpecialResourceSpecsMap[spec.Id] = spec | |||||
| } | |||||
| } | |||||
| } | |||||
| SpecsMapInitFlag = true | SpecsMapInitFlag = true | ||||
| } | } | ||||
| @@ -2230,6 +2273,16 @@ func InitCloudbrainOneGpuInfoMap() { | |||||
| CloudbrainBenchmarkGpuInfosMap[GpuInfo.Queue] = GpuInfo | CloudbrainBenchmarkGpuInfosMap[GpuInfo.Queue] = GpuInfo | ||||
| } | } | ||||
| } | } | ||||
| if CloudbrainSpecialGpuInfosMap == nil || len(CloudbrainSpecialGpuInfosMap) == 0 { | |||||
| t := SpecialPools{} | |||||
| json.Unmarshal([]byte(setting.SpecialPools), &t) | |||||
| for _, pool := range t.Pools { | |||||
| CloudbrainSpecialGpuInfosMap = make(map[string]*GpuInfo, len(pool.Pool)) | |||||
| for _, GpuInfo := range pool.Pool { | |||||
| CloudbrainSpecialGpuInfosMap[GpuInfo.Queue] = GpuInfo | |||||
| } | |||||
| } | |||||
| } | |||||
| GpuInfosMapInitFlag = true | GpuInfosMapInitFlag = true | ||||
| } | } | ||||
| func GetNewestJobsByAiCenter() ([]int64, error) { | func GetNewestJobsByAiCenter() ([]int64, error) { | ||||
| @@ -211,21 +211,6 @@ func GetAllStatusCloudBrain() map[string]int { | |||||
| return cloudBrainStatusResult | return cloudBrainStatusResult | ||||
| } | } | ||||
| func GetWaittingTop() ([]*CloudbrainInfo, error) { | |||||
| sess := x.NewSession() | |||||
| defer sess.Close() | |||||
| var cond = builder.NewCond() | |||||
| cond = cond.And( | |||||
| builder.Eq{"cloudbrain.status": string(JobWaiting)}, | |||||
| ) | |||||
| sess.OrderBy("cloudbrain.created_unix ASC limit 10") | |||||
| cloudbrains := make([]*CloudbrainInfo, 0, 10) | |||||
| if err := sess.Table(&Cloudbrain{}).Where(cond). | |||||
| Find(&cloudbrains); err != nil { | |||||
| log.Info("find error.") | |||||
| } | |||||
| return cloudbrains, nil | |||||
| } | |||||
| func GetRunningTop() ([]*CloudbrainInfo, error) { | func GetRunningTop() ([]*CloudbrainInfo, error) { | ||||
| sess := x.NewSession() | sess := x.NewSession() | ||||
| defer sess.Close() | defer sess.Close() | ||||
| @@ -1603,13 +1603,6 @@ func updateRepository(e Engine, repo *Repository, visibilityChanged bool) (err e | |||||
| if err != nil { | if err != nil { | ||||
| return err | return err | ||||
| } | } | ||||
| //If repo has become private, we need set dataset and dataset_file to private | |||||
| _, err = e.Where("repo_id = ? and status <> 2", repo.ID).Cols("status").Update(&Dataset{ | |||||
| Status: 0, | |||||
| }) | |||||
| if err != nil { | |||||
| return err | |||||
| } | |||||
| dataset, err := GetDatasetByRepo(repo) | dataset, err := GetDatasetByRepo(repo) | ||||
| if err != nil && !IsErrNotExist(err) { | if err != nil && !IsErrNotExist(err) { | ||||
| @@ -1624,6 +1617,14 @@ func updateRepository(e Engine, repo *Repository, visibilityChanged bool) (err e | |||||
| } | } | ||||
| } | } | ||||
| //If repo has become private, we need set dataset and dataset_file to private | |||||
| _, err = e.Where("repo_id = ? and status <> 2", repo.ID).Cols("status").Update(&Dataset{ | |||||
| Status: 0, | |||||
| }) | |||||
| if err != nil { | |||||
| return err | |||||
| } | |||||
| } else { | } else { | ||||
| //If repo has become public, we need set dataset to public | //If repo has become public, we need set dataset to public | ||||
| _, err = e.Where("repo_id = ? and status <> 2", repo.ID).Cols("status").Update(&Dataset{ | _, err = e.Where("repo_id = ? and status <> 2", repo.ID).Cols("status").Update(&Dataset{ | ||||
| @@ -6,6 +6,7 @@ import ( | |||||
| "code.gitea.io/gitea/modules/log" | "code.gitea.io/gitea/modules/log" | ||||
| "code.gitea.io/gitea/modules/timeutil" | "code.gitea.io/gitea/modules/timeutil" | ||||
| "xorm.io/builder" | |||||
| ) | ) | ||||
| type UserBusinessAnalysisForActivity struct { | type UserBusinessAnalysisForActivity struct { | ||||
| @@ -435,3 +436,16 @@ func queryUserModelPublic(start_unix int64, end_unix int64, publicAllRepo map[in | |||||
| } | } | ||||
| return resultMap | return resultMap | ||||
| } | } | ||||
| func QueryUserLoginInfo(userIds []int64) []*UserLoginLog { | |||||
| statictisSess := xStatistic.NewSession() | |||||
| defer statictisSess.Close() | |||||
| var cond = builder.NewCond() | |||||
| cond = cond.And(builder.In("u_id", userIds)) | |||||
| statictisSess.Select("*").Table(new(UserLoginLog)).Where(cond) | |||||
| loginList := make([]*UserLoginLog, 0) | |||||
| statictisSess.Find(&loginList) | |||||
| return loginList | |||||
| } | |||||
| @@ -110,9 +110,9 @@ type UserBusinessAnalysisAll struct { | |||||
| } | } | ||||
| type UserBusinessAnalysis struct { | type UserBusinessAnalysis struct { | ||||
| ID int64 `xorm:"pk"` | |||||
| CountDate int64 `xorm:"pk"` | |||||
| ID int64 `xorm:"pk"` | |||||
| DataDate string `xorm:"pk"` | |||||
| CountDate int64 `xorm:"NULL"` | |||||
| //action :ActionMergePullRequest // 11 | //action :ActionMergePullRequest // 11 | ||||
| CodeMergeCount int `xorm:"NOT NULL DEFAULT 0"` | CodeMergeCount int `xorm:"NOT NULL DEFAULT 0"` | ||||
| @@ -171,8 +171,6 @@ type UserBusinessAnalysis struct { | |||||
| //user | //user | ||||
| Name string `xorm:"NOT NULL"` | Name string `xorm:"NOT NULL"` | ||||
| DataDate string `xorm:"NULL"` | |||||
| CloudBrainTaskNum int `xorm:"NOT NULL DEFAULT 0"` | CloudBrainTaskNum int `xorm:"NOT NULL DEFAULT 0"` | ||||
| GpuDebugJob int `xorm:"NOT NULL DEFAULT 0"` | GpuDebugJob int `xorm:"NOT NULL DEFAULT 0"` | ||||
| NpuDebugJob int `xorm:"NOT NULL DEFAULT 0"` | NpuDebugJob int `xorm:"NOT NULL DEFAULT 0"` | ||||
| @@ -411,6 +409,42 @@ func QueryUserStaticDataAll(opts *UserBusinessAnalysisQueryOptions) ([]*UserBusi | |||||
| return userBusinessAnalysisReturnList, allCount | return userBusinessAnalysisReturnList, allCount | ||||
| } | } | ||||
| func QueryDataForUserDefineFromDb(opts *UserBusinessAnalysisQueryOptions, key string) ([]*UserBusinessAnalysis, int64) { | |||||
| statictisSess := xStatistic.NewSession() | |||||
| defer statictisSess.Close() | |||||
| cond := "data_date='" + key + "'" | |||||
| allCount, err := statictisSess.Where(cond).Count(new(UserBusinessAnalysis)) | |||||
| if err == nil { | |||||
| if allCount > 0 { | |||||
| userBusinessAnalysisList := make([]*UserBusinessAnalysis, 0) | |||||
| if err := statictisSess.Table("user_business_analysis").Where(cond).OrderBy("id desc").Limit(opts.PageSize, (opts.Page-1)*opts.PageSize). | |||||
| Find(&userBusinessAnalysisList); err != nil { | |||||
| return nil, 0 | |||||
| } | |||||
| return userBusinessAnalysisList, allCount | |||||
| } | |||||
| } | |||||
| return nil, 0 | |||||
| } | |||||
| func WriteDataToDb(dataList []*UserBusinessAnalysis, key string) { | |||||
| statictisSess := xStatistic.NewSession() | |||||
| defer statictisSess.Close() | |||||
| log.Info("write to db, size=" + fmt.Sprint(len(dataList))) | |||||
| userBusinessAnalysisList := make([]*UserBusinessAnalysis, 0) | |||||
| for _, data := range dataList { | |||||
| data.DataDate = key | |||||
| userBusinessAnalysisList = append(userBusinessAnalysisList, data) | |||||
| if len(userBusinessAnalysisList) > BATCH_INSERT_SIZE { | |||||
| statictisSess.Insert(userBusinessAnalysisList) | |||||
| userBusinessAnalysisList = make([]*UserBusinessAnalysis, 0) | |||||
| } | |||||
| } | |||||
| if len(userBusinessAnalysisList) > 0 { | |||||
| statictisSess.Insert(userBusinessAnalysisList) | |||||
| } | |||||
| } | |||||
| func QueryUserStaticDataForUserDefine(opts *UserBusinessAnalysisQueryOptions, wikiCountMap map[string]int) ([]*UserBusinessAnalysis, int64) { | func QueryUserStaticDataForUserDefine(opts *UserBusinessAnalysisQueryOptions, wikiCountMap map[string]int) ([]*UserBusinessAnalysis, int64) { | ||||
| log.Info("start to count other user info data") | log.Info("start to count other user info data") | ||||
| sess := x.NewSession() | sess := x.NewSession() | ||||
| @@ -954,6 +988,9 @@ func CounDataByDateAndReCount(wikiCountMap map[string]int, startTime time.Time, | |||||
| statictisSess := xStatistic.NewSession() | statictisSess := xStatistic.NewSession() | ||||
| defer statictisSess.Close() | defer statictisSess.Close() | ||||
| log.Info("truncate all data from table:user_business_analysis ") | |||||
| statictisSess.Exec("TRUNCATE TABLE user_business_analysis") | |||||
| cond := "type != 1" | cond := "type != 1" | ||||
| count, err := sess.Where(cond).Count(new(User)) | count, err := sess.Where(cond).Count(new(User)) | ||||
| if err != nil { | if err != nil { | ||||
| @@ -1103,6 +1140,7 @@ func updateNewUserAcitivity(currentUserActivity map[int64]map[int64]int64, userA | |||||
| ",activate_regist_user=" + fmt.Sprint(useMetrics.ActivateRegistUser) + | ",activate_regist_user=" + fmt.Sprint(useMetrics.ActivateRegistUser) + | ||||
| ",not_activate_regist_user=" + fmt.Sprint(useMetrics.CurrentDayRegistUser-useMetrics.ActivateRegistUser) + | ",not_activate_regist_user=" + fmt.Sprint(useMetrics.CurrentDayRegistUser-useMetrics.ActivateRegistUser) + | ||||
| ",current_day_regist_user=" + fmt.Sprint(useMetrics.CurrentDayRegistUser) + | ",current_day_regist_user=" + fmt.Sprint(useMetrics.CurrentDayRegistUser) + | ||||
| ",activate_index=" + fmt.Sprint(float64(useMetrics.ActivateRegistUser)/float64(useMetrics.CurrentDayRegistUser)) + | |||||
| ",data_date='" + time.Unix(key, 0).Format("2006-01-02") + "'" + | ",data_date='" + time.Unix(key, 0).Format("2006-01-02") + "'" + | ||||
| " where count_date=" + fmt.Sprint(key) | " where count_date=" + fmt.Sprint(key) | ||||
| @@ -466,11 +466,14 @@ func RestartTask(ctx *context.Context, task *models.Cloudbrain, newID *string) e | |||||
| log.Error("no such resourceSpecId(%d)", task.ResourceSpecId, ctx.Data["MsgID"]) | log.Error("no such resourceSpecId(%d)", task.ResourceSpecId, ctx.Data["MsgID"]) | ||||
| return errors.New("no such resourceSpec") | return errors.New("no such resourceSpec") | ||||
| } | } | ||||
| datasetInfos, _, err := models.GetDatasetInfo(task.Uuid) | |||||
| if err != nil { | |||||
| log.Error("GetDatasetInfo failed:%v", err, ctx.Data["MsgID"]) | |||||
| return err | |||||
| var datasetInfos map[string]models.DatasetInfo | |||||
| if task.Uuid != "" { | |||||
| var err error | |||||
| datasetInfos, _, err = models.GetDatasetInfo(task.Uuid) | |||||
| if err != nil { | |||||
| log.Error("GetDatasetInfo failed:%v", err, ctx.Data["MsgID"]) | |||||
| return err | |||||
| } | |||||
| } | } | ||||
| volumes := []models.Volume{ | volumes := []models.Volume{ | ||||
| @@ -510,24 +513,25 @@ func RestartTask(ctx *context.Context, task *models.Cloudbrain, newID *string) e | |||||
| }, | }, | ||||
| }, | }, | ||||
| } | } | ||||
| if len(datasetInfos) == 1 { | |||||
| volumes = append(volumes, models.Volume{ | |||||
| HostPath: models.StHostPath{ | |||||
| Path: datasetInfos[task.Uuid].DataLocalPath, | |||||
| MountPath: DataSetMountPath, | |||||
| ReadOnly: true, | |||||
| }, | |||||
| }) | |||||
| } else { | |||||
| for _, dataset := range datasetInfos { | |||||
| if datasetInfos != nil { | |||||
| if len(datasetInfos) == 1 { | |||||
| volumes = append(volumes, models.Volume{ | volumes = append(volumes, models.Volume{ | ||||
| HostPath: models.StHostPath{ | HostPath: models.StHostPath{ | ||||
| Path: dataset.DataLocalPath, | |||||
| MountPath: DataSetMountPath + "/" + dataset.Name, | |||||
| Path: datasetInfos[task.Uuid].DataLocalPath, | |||||
| MountPath: DataSetMountPath, | |||||
| ReadOnly: true, | ReadOnly: true, | ||||
| }, | }, | ||||
| }) | }) | ||||
| } else { | |||||
| for _, dataset := range datasetInfos { | |||||
| volumes = append(volumes, models.Volume{ | |||||
| HostPath: models.StHostPath{ | |||||
| Path: dataset.DataLocalPath, | |||||
| MountPath: DataSetMountPath + "/" + dataset.Name, | |||||
| ReadOnly: true, | |||||
| }, | |||||
| }) | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @@ -829,6 +829,9 @@ func HandleNotebookInfo(task *models.Cloudbrain) error { | |||||
| if oldStatus != task.Status { | if oldStatus != task.Status { | ||||
| notification.NotifyChangeCloudbrainStatus(task, oldStatus) | notification.NotifyChangeCloudbrainStatus(task, oldStatus) | ||||
| } | } | ||||
| if task.FlavorCode == "" { | |||||
| task.FlavorCode = result.Flavor | |||||
| } | |||||
| err = models.UpdateJob(task) | err = models.UpdateJob(task) | ||||
| if err != nil { | if err != nil { | ||||
| log.Error("UpdateJob(%s) failed:%v", task.DisplayJobName, err) | log.Error("UpdateJob(%s) failed:%v", task.DisplayJobName, err) | ||||
| @@ -571,6 +571,7 @@ func RegisterRoutes(m *macaron.Macaron) { | |||||
| m.Get("/query_user_yesterday", operationReq, repo_ext.QueryUserStaticYesterday) | m.Get("/query_user_yesterday", operationReq, repo_ext.QueryUserStaticYesterday) | ||||
| m.Get("/query_user_all", operationReq, repo_ext.QueryUserStaticAll) | m.Get("/query_user_all", operationReq, repo_ext.QueryUserStaticAll) | ||||
| m.Get("/query_user_activity", operationReq, repo_ext.QueryUserActivity) | m.Get("/query_user_activity", operationReq, repo_ext.QueryUserActivity) | ||||
| m.Get("/query_user_login", operationReq, repo_ext.QueryUserLoginInfo) | |||||
| //cloudbrain board | //cloudbrain board | ||||
| m.Group("/cloudbrainboard", func() { | m.Group("/cloudbrainboard", func() { | ||||
| m.Get("/downloadAll", repo.DownloadCloudBrainBoard) | m.Get("/downloadAll", repo.DownloadCloudBrainBoard) | ||||
| @@ -736,6 +736,7 @@ func GetCloudbrainsDetailData(ctx *context.Context) { | |||||
| var taskDetail models.TaskDetail | var taskDetail models.TaskDetail | ||||
| taskDetail.ID = ciTasks[i].Cloudbrain.ID | taskDetail.ID = ciTasks[i].Cloudbrain.ID | ||||
| taskDetail.JobID = ciTasks[i].Cloudbrain.JobID | |||||
| taskDetail.JobName = ciTasks[i].JobName | taskDetail.JobName = ciTasks[i].JobName | ||||
| taskDetail.DisplayJobName = ciTasks[i].DisplayJobName | taskDetail.DisplayJobName = ciTasks[i].DisplayJobName | ||||
| taskDetail.Status = ciTasks[i].Status | taskDetail.Status = ciTasks[i].Status | ||||
| @@ -758,9 +759,6 @@ func GetCloudbrainsDetailData(ctx *context.Context) { | |||||
| taskDetail.FlavorName, _ = repo.GetCloudbrainFlavorName(ciTasks[i].Cloudbrain) | taskDetail.FlavorName, _ = repo.GetCloudbrainFlavorName(ciTasks[i].Cloudbrain) | ||||
| taskDetail.WaitTime = repo.GetCloudbrainWaitTime(ciTasks[i].Cloudbrain) | taskDetail.WaitTime = repo.GetCloudbrainWaitTime(ciTasks[i].Cloudbrain) | ||||
| if ciTasks[i].Cloudbrain.Type == models.TypeCloudBrainTwo || (ciTasks[i].Cloudbrain.Type == models.TypeCloudBrainOne && ciTasks[i].Cloudbrain.JobType == "TRAIN") { | |||||
| taskDetail.JobID = ciTasks[i].Cloudbrain.JobID | |||||
| } | |||||
| if ciTasks[i].Cloudbrain.DeletedAt != nilTime { | if ciTasks[i].Cloudbrain.DeletedAt != nilTime { | ||||
| taskDetail.IsDelete = true | taskDetail.IsDelete = true | ||||
| @@ -2934,10 +2934,18 @@ func GetCloudbrainAiCenter(task models.Cloudbrain, ctx *context.Context) string | |||||
| } else if task.Type == models.TypeCloudBrainTwo { | } else if task.Type == models.TypeCloudBrainTwo { | ||||
| return ctx.Tr("repo.cloudbrain2") | return ctx.Tr("repo.cloudbrain2") | ||||
| } else if task.Type == models.TypeC2Net { | } else if task.Type == models.TypeC2Net { | ||||
| return task.AiCenter | |||||
| return getCutStringAiCenterByAiCenter(task.AiCenter) | |||||
| } | } | ||||
| return "" | return "" | ||||
| } | } | ||||
| func getCutStringAiCenterByAiCenter(aiCenter string) string { | |||||
| if aiCenter == "" { | |||||
| return "" | |||||
| } | |||||
| index := strings.LastIndex(aiCenter, "+") | |||||
| return aiCenter[index+1:] | |||||
| } | |||||
| func GetCloudbrainCluster(task models.Cloudbrain, ctx *context.Context) string { | func GetCloudbrainCluster(task models.Cloudbrain, ctx *context.Context) string { | ||||
| if task.Type == models.TypeCloudBrainOne || task.Type == models.TypeCloudBrainTwo { | if task.Type == models.TypeCloudBrainOne || task.Type == models.TypeCloudBrainTwo { | ||||
| return ctx.Tr("cloudbrain.resource_cluster_openi") | return ctx.Tr("cloudbrain.resource_cluster_openi") | ||||
| @@ -2947,33 +2955,33 @@ func GetCloudbrainCluster(task models.Cloudbrain, ctx *context.Context) string { | |||||
| return "" | return "" | ||||
| } | } | ||||
| func GetCloudbrainCardDuration(task models.Cloudbrain) string { | func GetCloudbrainCardDuration(task models.Cloudbrain) string { | ||||
| CardNum, _, _ := GetCloudbrainCardNumAndType(task) | |||||
| CardDuration := models.ConvertDurationToStr(int64(CardNum) * task.Duration) | |||||
| return CardDuration | |||||
| cardNum, _, _ := GetCloudbrainCardNumAndType(task) | |||||
| cardDuration := models.ConvertDurationToStr(int64(cardNum) * task.Duration) | |||||
| return cardDuration | |||||
| } | } | ||||
| func GetCloudbrainWaitTime(task models.Cloudbrain) string { | func GetCloudbrainWaitTime(task models.Cloudbrain) string { | ||||
| var WaitTime string | |||||
| var waitTime string | |||||
| if task.Status == string(models.JobWaiting) { | if task.Status == string(models.JobWaiting) { | ||||
| WaitTimeInt := time.Now().Unix() - task.CreatedUnix.AsTime().Unix() | |||||
| WaitTime = models.ConvertDurationToStr(WaitTimeInt) | |||||
| if WaitTimeInt < 0 { | |||||
| WaitTime = "00:00:00" | |||||
| waitTimeInt := time.Now().Unix() - task.CreatedUnix.AsTime().Unix() | |||||
| waitTime = models.ConvertDurationToStr(waitTimeInt) | |||||
| if waitTimeInt < 0 { | |||||
| waitTime = "00:00:00" | |||||
| } | } | ||||
| } else if task.Status == string(models.JobStopped) && task.StartTime.AsTime().Unix() == 0 { | } else if task.Status == string(models.JobStopped) && task.StartTime.AsTime().Unix() == 0 { | ||||
| WaitTimeInt := task.EndTime.AsTime().Unix() - task.CreatedUnix.AsTime().Unix() | |||||
| WaitTime = models.ConvertDurationToStr(WaitTimeInt) | |||||
| if WaitTimeInt < 0 { | |||||
| WaitTime = "00:00:00" | |||||
| waitTimeInt := task.EndTime.AsTime().Unix() - task.CreatedUnix.AsTime().Unix() | |||||
| waitTime = models.ConvertDurationToStr(waitTimeInt) | |||||
| if waitTimeInt < 0 { | |||||
| waitTime = "00:00:00" | |||||
| } | } | ||||
| } else { | } else { | ||||
| WaitTimeInt := task.StartTime.AsTime().Unix() - task.CreatedUnix.AsTime().Unix() | |||||
| WaitTime = models.ConvertDurationToStr(WaitTimeInt) | |||||
| if WaitTimeInt < 0 { | |||||
| WaitTime = "00:00:00" | |||||
| waitTimeInt := task.StartTime.AsTime().Unix() - task.CreatedUnix.AsTime().Unix() | |||||
| waitTime = models.ConvertDurationToStr(waitTimeInt) | |||||
| if waitTimeInt < 0 { | |||||
| waitTime = "00:00:00" | |||||
| } | } | ||||
| } | } | ||||
| return WaitTime | |||||
| return waitTime | |||||
| } | } | ||||
| func GetCloudbrainCardNumAndType(task models.Cloudbrain) (int, string, error) { | func GetCloudbrainCardNumAndType(task models.Cloudbrain) (int, string, error) { | ||||
| @@ -2983,11 +2991,11 @@ func GetCloudbrainCardNumAndType(task models.Cloudbrain) (int, string, error) { | |||||
| if !models.GpuInfosMapInitFlag { | if !models.GpuInfosMapInitFlag { | ||||
| models.InitCloudbrainOneGpuInfoMap() | models.InitCloudbrainOneGpuInfoMap() | ||||
| } | } | ||||
| FlavorName, err := GetCloudbrainFlavorName(task) | |||||
| flavorName, err := GetCloudbrainFlavorName(task) | |||||
| if err != nil { | if err != nil { | ||||
| return 0, "", nil | return 0, "", nil | ||||
| } | } | ||||
| return getCardNumAndTypeByFlavorname(FlavorName) | |||||
| return getCardNumAndTypeByFlavorname(flavorName) | |||||
| } | } | ||||
| func getCardNumAndTypeByFlavorname(FlavorName string) (int, string, error) { | func getCardNumAndTypeByFlavorname(FlavorName string) (int, string, error) { | ||||
| @@ -3012,53 +3020,61 @@ func getCardNumAndTypeByFlavorname(FlavorName string) (int, string, error) { | |||||
| func GetCloudbrainFlavorName(task models.Cloudbrain) (string, error) { | func GetCloudbrainFlavorName(task models.Cloudbrain) (string, error) { | ||||
| if task.Type == models.TypeCloudBrainOne { | if task.Type == models.TypeCloudBrainOne { | ||||
| ResourceSpec, GpuInfo, err := getCloudBrainOneResourceSpec(task) | |||||
| resourceSpec, gpuInfo, err := getCloudBrainOneResourceSpec(task) | |||||
| if err != nil { | if err != nil { | ||||
| log.Info("getCloudBrainOneResourceSpec err:", err) | log.Info("getCloudBrainOneResourceSpec err:", err) | ||||
| return "", err | return "", err | ||||
| } else { | } else { | ||||
| if ResourceSpec == nil || GpuInfo == nil { | |||||
| err := errors.New("ResourceSpec or GpuInfo is nil") | |||||
| if resourceSpec == nil || gpuInfo == nil { | |||||
| err := errors.New("resourceSpec or gpuInfo is nil") | |||||
| return "", err | return "", err | ||||
| } else { | } else { | ||||
| CloudbrainOneFlavorName := "GPU:" + strconv.Itoa(ResourceSpec.GpuNum) + "*Nvidia-" + GpuInfo.Value + | |||||
| " | CPU:" + strconv.Itoa(ResourceSpec.CpuNum) + "核" + strconv.Itoa(ResourceSpec.MemMiB) + "MB" | |||||
| CloudbrainOneFlavorName := "GPU:" + strconv.Itoa(resourceSpec.GpuNum) + "*Nvidia-" + gpuInfo.Value + | |||||
| " | CPU:" + strconv.Itoa(resourceSpec.CpuNum) + "核" + strconv.Itoa(resourceSpec.MemMiB) + "MB" | |||||
| return CloudbrainOneFlavorName, nil | return CloudbrainOneFlavorName, nil | ||||
| } | } | ||||
| } | } | ||||
| } else if (task.Type == models.TypeCloudBrainTwo || task.Type == models.TypeC2Net) && task.FlavorName != "" { | } else if (task.Type == models.TypeCloudBrainTwo || task.Type == models.TypeC2Net) && task.FlavorName != "" { | ||||
| ReplaceFlavorName := strings.ReplaceAll(task.FlavorName, ":", ":") | |||||
| return ReplaceFlavorName, nil | |||||
| replaceFlavorName := strings.ReplaceAll(task.FlavorName, ":", ":") | |||||
| return replaceFlavorName, nil | |||||
| } else if task.Type == models.TypeCloudBrainTwo && task.FlavorName == "" && task.FlavorCode != "" { | } else if task.Type == models.TypeCloudBrainTwo && task.FlavorName == "" && task.FlavorCode != "" { | ||||
| index := strings.LastIndex(task.FlavorCode, ".") | |||||
| cardNum, err := strconv.Atoi(strings.TrimSpace(task.FlavorCode[index+1 : len(task.FlavorCode)])) | |||||
| cloudbrainTwoFlavorName := getFlavorNameByFlavorCode(task.FlavorCode) | |||||
| return cloudbrainTwoFlavorName, nil | |||||
| } else if task.Type == models.TypeCloudBrainTwo && task.JobType == string(models.JobTypeDebug) && task.FlavorName == "" && task.FlavorCode == "" { | |||||
| tasks, err := models.GetModelartsReDebugTaskByJobId(task.JobID) | |||||
| if err != nil { | if err != nil { | ||||
| log.Error("strconv.Atoi failed: %v", err) | |||||
| return "", err | return "", err | ||||
| } | } | ||||
| CloudbrainTwoFlavorName := "Ascend:" + strings.TrimSpace(task.FlavorCode[index+1:len(task.FlavorCode)]) + | |||||
| "*Ascend-910(" + strconv.Itoa(cardNum*32) + "GB)|ARM:" + strconv.Itoa(cardNum*24) + | |||||
| "核" + strconv.Itoa(cardNum*256) + "GB" | |||||
| return CloudbrainTwoFlavorName, nil | |||||
| if len(tasks) >= 1 { | |||||
| return getFlavorNameByFlavorCode(tasks[0].FlavorCode), nil | |||||
| } | |||||
| return "", nil | |||||
| } | } | ||||
| return "", nil | return "", nil | ||||
| } | } | ||||
| func getCloudBrainOneResourceSpec(task models.Cloudbrain) (*models.ResourceSpec, *models.GpuInfo, error) { | func getCloudBrainOneResourceSpec(task models.Cloudbrain) (*models.ResourceSpec, *models.GpuInfo, error) { | ||||
| GpuQueueDefault := "openidebug" | |||||
| gpuQueueDefault := "openidebug" | |||||
| if task.GpuQueue != "" { | if task.GpuQueue != "" { | ||||
| GpuQueueDefault = task.GpuQueue | |||||
| gpuQueueDefault = task.GpuQueue | |||||
| } | } | ||||
| if task.ResourceSpecId >= 0 { | if task.ResourceSpecId >= 0 { | ||||
| if task.JobType == string(models.JobTypeTrain) { | if task.JobType == string(models.JobTypeTrain) { | ||||
| return models.CloudbrainTrainResourceSpecsMap[task.ResourceSpecId], models.CloudbrainTrainGpuInfosMap[GpuQueueDefault], nil | |||||
| if models.CloudbrainTrainResourceSpecsMap[task.ResourceSpecId] != nil { | |||||
| return models.CloudbrainTrainResourceSpecsMap[task.ResourceSpecId], models.CloudbrainTrainGpuInfosMap[gpuQueueDefault], nil | |||||
| } else { | |||||
| return models.CloudbrainSpecialResourceSpecsMap[task.ResourceSpecId], models.CloudbrainSpecialGpuInfosMap[gpuQueueDefault], nil | |||||
| } | |||||
| } else if task.JobType == string(models.JobTypeDebug) { | } else if task.JobType == string(models.JobTypeDebug) { | ||||
| return models.CloudbrainDebugResourceSpecsMap[task.ResourceSpecId], models.CloudbrainDebugGpuInfosMap[GpuQueueDefault], nil | |||||
| if models.CloudbrainDebugResourceSpecsMap[task.ResourceSpecId] != nil { | |||||
| return models.CloudbrainDebugResourceSpecsMap[task.ResourceSpecId], models.CloudbrainDebugGpuInfosMap[gpuQueueDefault], nil | |||||
| } else { | |||||
| return models.CloudbrainSpecialResourceSpecsMap[task.ResourceSpecId], models.CloudbrainSpecialGpuInfosMap[gpuQueueDefault], nil | |||||
| } | |||||
| } else if task.JobType == string(models.JobTypeInference) { | } else if task.JobType == string(models.JobTypeInference) { | ||||
| return models.CloudbrainInferenceResourceSpecsMap[task.ResourceSpecId], models.CloudbrainInferenceGpuInfosMap[GpuQueueDefault], nil | |||||
| return models.CloudbrainInferenceResourceSpecsMap[task.ResourceSpecId], models.CloudbrainInferenceGpuInfosMap[gpuQueueDefault], nil | |||||
| } else if task.JobType == string(models.JobTypeBenchmark) || task.JobType == string(models.JobTypeSnn4imagenet) || task.JobType == string(models.JobTypeBrainScore) { | } else if task.JobType == string(models.JobTypeBenchmark) || task.JobType == string(models.JobTypeSnn4imagenet) || task.JobType == string(models.JobTypeBrainScore) { | ||||
| return models.CloudbrainBenchmarkResourceSpecsMap[task.ResourceSpecId], models.CloudbrainBenchmarkGpuInfosMap[GpuQueueDefault], nil | |||||
| return models.CloudbrainBenchmarkResourceSpecsMap[task.ResourceSpecId], models.CloudbrainBenchmarkGpuInfosMap[gpuQueueDefault], nil | |||||
| } | } | ||||
| } else { | } else { | ||||
| err := errors.New("ResourceSpecId is null") | err := errors.New("ResourceSpecId is null") | ||||
| @@ -3066,3 +3082,15 @@ func getCloudBrainOneResourceSpec(task models.Cloudbrain) (*models.ResourceSpec, | |||||
| } | } | ||||
| return nil, nil, nil | return nil, nil, nil | ||||
| } | } | ||||
| func getFlavorNameByFlavorCode(flavorCode string) string { | |||||
| index := strings.LastIndex(flavorCode, ".") | |||||
| cardNum, err := strconv.Atoi(strings.TrimSpace(flavorCode[index+1 : len(flavorCode)])) | |||||
| if err != nil { | |||||
| log.Error("strconv.Atoi failed: %v", err) | |||||
| return "" | |||||
| } | |||||
| cloudbrainTwoFlavorName := "Ascend:" + strings.TrimSpace(flavorCode[index+1:len(flavorCode)]) + | |||||
| "*Ascend-910(" + strconv.Itoa(cardNum*32) + "GB)|ARM:" + strconv.Itoa(cardNum*24) + | |||||
| "核" + strconv.Itoa(cardNum*256) + "GB" | |||||
| return cloudbrainTwoFlavorName | |||||
| } | |||||
| @@ -481,6 +481,8 @@ func NotebookRestart(ctx *context.Context) { | |||||
| Description: task.Description, | Description: task.Description, | ||||
| CreatedUnix: createTime, | CreatedUnix: createTime, | ||||
| UpdatedUnix: createTime, | UpdatedUnix: createTime, | ||||
| FlavorCode: task.FlavorCode, | |||||
| FlavorName: task.FlavorName, | |||||
| } | } | ||||
| err = models.RestartCloudbrain(task, newTask) | err = models.RestartCloudbrain(task, newTask) | ||||
| @@ -537,11 +539,15 @@ func NotebookStop(ctx *context.Context) { | |||||
| } | } | ||||
| status = res.Status | status = res.Status | ||||
| oldStatus := task.Status | |||||
| task.Status = res.Status | task.Status = res.Status | ||||
| if task.EndTime == 0 && models.IsModelArtsDebugJobTerminal(task.Status) { | if task.EndTime == 0 && models.IsModelArtsDebugJobTerminal(task.Status) { | ||||
| task.EndTime = timeutil.TimeStampNow() | task.EndTime = timeutil.TimeStampNow() | ||||
| } | } | ||||
| task.ComputeAndSetDuration() | task.ComputeAndSetDuration() | ||||
| if oldStatus != task.Status { | |||||
| notification.NotifyChangeCloudbrainStatus(task, oldStatus) | |||||
| } | |||||
| err = models.UpdateJob(task) | err = models.UpdateJob(task) | ||||
| if err != nil { | if err != nil { | ||||
| log.Error("UpdateJob(%s) failed:%v", task.JobName, err.Error(), ctx.Data["MsgID"]) | log.Error("UpdateJob(%s) failed:%v", task.JobName, err.Error(), ctx.Data["MsgID"]) | ||||
| @@ -5,6 +5,8 @@ import ( | |||||
| "net/http" | "net/http" | ||||
| "net/url" | "net/url" | ||||
| "os" | "os" | ||||
| "strconv" | |||||
| "strings" | |||||
| "time" | "time" | ||||
| "code.gitea.io/gitea/models" | "code.gitea.io/gitea/models" | ||||
| @@ -404,7 +406,7 @@ func queryMetrics(ctx *context.Context, tableName string, startTime time.Time, e | |||||
| if tableName == "public.user_business_analysis_yesterday" { | if tableName == "public.user_business_analysis_yesterday" { | ||||
| mapInterface["datarecordbegintime"] = setting.RadarMap.GrowthBeginTime | mapInterface["datarecordbegintime"] = setting.RadarMap.GrowthBeginTime | ||||
| if len(result) > 0 { | if len(result) > 0 { | ||||
| dateTime := time.Unix(result[0].CountDate, 0) | |||||
| dateTime := time.Unix(result[0].CountDate, 0).AddDate(0, 0, 1) | |||||
| mapInterface["lastUpdatedTime"] = dateTime.Format("2006-01-02 15:04:05") | mapInterface["lastUpdatedTime"] = dateTime.Format("2006-01-02 15:04:05") | ||||
| } else { | } else { | ||||
| mapInterface["lastUpdatedTime"] = "" | mapInterface["lastUpdatedTime"] = "" | ||||
| @@ -450,7 +452,7 @@ func DownloadUserDefineFile(ctx *context.Context) { | |||||
| func QueryUserMetricsCurrentMonth(ctx *context.Context) { | func QueryUserMetricsCurrentMonth(ctx *context.Context) { | ||||
| currentTimeNow := time.Now() | currentTimeNow := time.Now() | ||||
| pageEndTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 23, 59, 59, 0, currentTimeNow.Location()) | |||||
| pageEndTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, currentTimeNow.Location()) | |||||
| pageStartTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), 1, 0, 0, 0, 0, currentTimeNow.Location()) | pageStartTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), 1, 0, 0, 0, 0, currentTimeNow.Location()) | ||||
| pageStartTime = getStartTime(pageStartTime) | pageStartTime = getStartTime(pageStartTime) | ||||
| queryMetrics(ctx, "public.user_business_analysis_current_month", pageStartTime, pageEndTime) | queryMetrics(ctx, "public.user_business_analysis_current_month", pageStartTime, pageEndTime) | ||||
| @@ -476,7 +478,7 @@ func QueryUserMetricsCurrentWeek(ctx *context.Context) { | |||||
| } | } | ||||
| pageStartTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, offset) | pageStartTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, offset) | ||||
| pageStartTime = getStartTime(pageStartTime) | pageStartTime = getStartTime(pageStartTime) | ||||
| pageEndTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 23, 59, 59, 0, currentTimeNow.Location()) | |||||
| pageEndTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, currentTimeNow.Location()) | |||||
| queryMetrics(ctx, "public.user_business_analysis_current_week", pageStartTime, pageEndTime) | queryMetrics(ctx, "public.user_business_analysis_current_week", pageStartTime, pageEndTime) | ||||
| } | } | ||||
| func QueryUserStaticCurrentWeek(ctx *context.Context) { | func QueryUserStaticCurrentWeek(ctx *context.Context) { | ||||
| @@ -490,7 +492,7 @@ func QueryUserMetricsCurrentYear(ctx *context.Context) { | |||||
| currentTimeNow := time.Now() | currentTimeNow := time.Now() | ||||
| pageStartTime := time.Date(currentTimeNow.Year(), 1, 1, 0, 0, 0, 0, currentTimeNow.Location()) | pageStartTime := time.Date(currentTimeNow.Year(), 1, 1, 0, 0, 0, 0, currentTimeNow.Location()) | ||||
| pageStartTime = getStartTime(pageStartTime) | pageStartTime = getStartTime(pageStartTime) | ||||
| pageEndTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 23, 59, 59, 0, currentTimeNow.Location()) | |||||
| pageEndTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, currentTimeNow.Location()) | |||||
| queryMetrics(ctx, "public.user_business_analysis_current_year", pageStartTime, pageEndTime) | queryMetrics(ctx, "public.user_business_analysis_current_year", pageStartTime, pageEndTime) | ||||
| } | } | ||||
| func QueryUserStaticCurrentYear(ctx *context.Context) { | func QueryUserStaticCurrentYear(ctx *context.Context) { | ||||
| @@ -500,7 +502,7 @@ func QueryUserMetricsLast30Day(ctx *context.Context) { | |||||
| currentTimeNow := time.Now() | currentTimeNow := time.Now() | ||||
| pageStartTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, -30) | pageStartTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, -30) | ||||
| pageStartTime = getStartTime(pageStartTime) | pageStartTime = getStartTime(pageStartTime) | ||||
| pageEndTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 23, 59, 59, 0, currentTimeNow.Location()) | |||||
| pageEndTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, currentTimeNow.Location()) | |||||
| queryMetrics(ctx, "public.user_business_analysis_last30_day", pageStartTime, pageEndTime) | queryMetrics(ctx, "public.user_business_analysis_last30_day", pageStartTime, pageEndTime) | ||||
| } | } | ||||
| func QueryUserStaticLast30Day(ctx *context.Context) { | func QueryUserStaticLast30Day(ctx *context.Context) { | ||||
| @@ -518,7 +520,7 @@ func QueryUserStaticLastMonth(ctx *context.Context) { | |||||
| queryUserDataPage(ctx, "public.user_business_analysis_last_month", new(models.UserBusinessAnalysisLastMonth)) | queryUserDataPage(ctx, "public.user_business_analysis_last_month", new(models.UserBusinessAnalysisLastMonth)) | ||||
| } | } | ||||
| func QueryUserMetricsYesterday(ctx *context.Context) { | func QueryUserMetricsYesterday(ctx *context.Context) { | ||||
| currentTimeNow := time.Now() | |||||
| currentTimeNow := time.Now().AddDate(0, 0, -1) | |||||
| pageStartTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, time.Local) | pageStartTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, time.Local) | ||||
| pageStartTime = getStartTime(pageStartTime) | pageStartTime = getStartTime(pageStartTime) | ||||
| pageEndTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 23, 59, 59, 0, currentTimeNow.Location()) | pageEndTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 23, 59, 59, 0, currentTimeNow.Location()) | ||||
| @@ -531,7 +533,7 @@ func QueryUserMetricsAll(ctx *context.Context) { | |||||
| currentTimeNow := time.Now() | currentTimeNow := time.Now() | ||||
| pageStartTime := time.Date(2022, 4, 5, 0, 0, 0, 0, currentTimeNow.Location()) | pageStartTime := time.Date(2022, 4, 5, 0, 0, 0, 0, currentTimeNow.Location()) | ||||
| pageStartTime = getStartTime(pageStartTime) | pageStartTime = getStartTime(pageStartTime) | ||||
| pageEndTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 23, 59, 59, 0, currentTimeNow.Location()) | |||||
| pageEndTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, currentTimeNow.Location()) | |||||
| queryMetrics(ctx, "public.user_business_analysis_all", pageStartTime, pageEndTime) | queryMetrics(ctx, "public.user_business_analysis_all", pageStartTime, pageEndTime) | ||||
| } | } | ||||
| func QueryUserStaticAll(ctx *context.Context) { | func QueryUserStaticAll(ctx *context.Context) { | ||||
| @@ -611,7 +613,15 @@ func QueryUserStaticDataPage(ctx *context.Context) { | |||||
| ctx.JSON(http.StatusOK, ctx.Tr("user.static.downloadinfo")+"/api/v1/download_user_define_file?filename="+filename) | ctx.JSON(http.StatusOK, ctx.Tr("user.static.downloadinfo")+"/api/v1/download_user_define_file?filename="+filename) | ||||
| } else { | } else { | ||||
| mapInterface := make(map[string]interface{}) | mapInterface := make(map[string]interface{}) | ||||
| re, count := models.QueryUserStaticDataPage(pageOpts) | |||||
| key := startTime.Format("2006-01-02") + endTime.Format("2006-01-02") | |||||
| log.Info("db key =" + key) | |||||
| re, count := models.QueryDataForUserDefineFromDb(pageOpts, key) | |||||
| if count == 0 { | |||||
| wikiMap, _ := queryWikiCountMap(startTime, endTime) | |||||
| re, count = models.QueryUserStaticDataForUserDefine(pageOpts, wikiMap) | |||||
| models.WriteDataToDb(re, key) | |||||
| } | |||||
| re, count = models.QueryDataForUserDefineFromDb(pageOpts, key) | |||||
| mapInterface["data"] = re | mapInterface["data"] = re | ||||
| mapInterface["count"] = count | mapInterface["count"] = count | ||||
| ctx.JSON(http.StatusOK, mapInterface) | ctx.JSON(http.StatusOK, mapInterface) | ||||
| @@ -839,3 +849,61 @@ func writeUserActivityToExcel(startTime time.Time, endTime time.Time, filePath s | |||||
| log.Info("write to file succeed, filepath=" + filePath) | log.Info("write to file succeed, filepath=" + filePath) | ||||
| } | } | ||||
| } | } | ||||
| // URL: /api/v1/query_user_login?userId=1,2,3,4 | |||||
| func QueryUserLoginInfo(ctx *context.Context) { | |||||
| userId := ctx.Query("userId") | |||||
| userIds := strings.Split(userId, ",") | |||||
| userIdInt := make([]int64, 0) | |||||
| for _, id := range userIds { | |||||
| idInt, err := strconv.ParseInt(id, 10, 64) | |||||
| if err == nil { | |||||
| userIdInt = append(userIdInt, idInt) | |||||
| } | |||||
| } | |||||
| result := models.QueryUserLoginInfo(userIdInt) | |||||
| xlsx := excelize.NewFile() | |||||
| sheetName := ctx.Tr("用户登录信息") | |||||
| index := xlsx.NewSheet(sheetName) | |||||
| xlsx.DeleteSheet("Sheet1") | |||||
| excelHeader := make([]string, 0) | |||||
| excelHeader = append(excelHeader, "用户ID") | |||||
| excelHeader = append(excelHeader, "登录IP") | |||||
| excelHeader = append(excelHeader, "登录时间") | |||||
| excelHeaderMap := make(map[string]string, 0) | |||||
| var j byte | |||||
| j = 0 | |||||
| for _, value := range excelHeader { | |||||
| excelColumn := getColumn(j) + fmt.Sprint(1) | |||||
| log.Info("excelColumn=" + excelColumn) | |||||
| excelHeaderMap[excelColumn] = value | |||||
| j++ | |||||
| } | |||||
| for k, v := range excelHeaderMap { | |||||
| //设置单元格的值 | |||||
| xlsx.SetCellValue(sheetName, k, v) | |||||
| } | |||||
| for i, userLogin := range result { | |||||
| row := i + 2 | |||||
| rows := fmt.Sprint(row) | |||||
| var tmp byte | |||||
| tmp = 0 | |||||
| xlsx.SetCellValue(sheetName, getColumn(tmp)+rows, userLogin.UId) | |||||
| tmp = tmp + 1 | |||||
| xlsx.SetCellValue(sheetName, getColumn(tmp)+rows, userLogin.IpAddr) | |||||
| tmp = tmp + 1 | |||||
| formatTime := userLogin.CreatedUnix.Format("2006-01-02 15:04:05") | |||||
| xlsx.SetCellValue(sheetName, getColumn(tmp)+rows, formatTime) | |||||
| } | |||||
| //设置默认打开的表单 | |||||
| xlsx.SetActiveSheet(index) | |||||
| filename := sheetName + "_" + time.Now().Format("2006-01-02 15:04:05") + ".xlsx" | |||||
| ctx.Resp.Header().Set("Content-Disposition", "attachment; filename="+url.QueryEscape(filename)) | |||||
| ctx.Resp.Header().Set("Content-Type", "application/octet-stream") | |||||
| if _, err := xlsx.WriteTo(ctx.Resp); err != nil { | |||||
| log.Info("writer exel error." + err.Error()) | |||||
| } | |||||
| } | |||||
| @@ -1136,7 +1136,7 @@ func RegisterRoutes(m *macaron.Macaron) { | |||||
| }) | }) | ||||
| }, context.RepoRef()) | }, context.RepoRef()) | ||||
| m.Group("/modelmanage", func() { | m.Group("/modelmanage", func() { | ||||
| m.Post("/create_model", reqRepoModelManageWriter, repo.SaveModel) | |||||
| m.Post("/create_model", repo.SaveModel) | |||||
| m.Post("/create_model_convert", reqRepoModelManageWriter, repo.SaveModelConvert) | m.Post("/create_model_convert", reqRepoModelManageWriter, repo.SaveModelConvert) | ||||
| m.Post("/create_new_model", repo.SaveNewNameModel) | m.Post("/create_new_model", repo.SaveNewNameModel) | ||||
| m.Delete("/delete_model", repo.DeleteModel) | m.Delete("/delete_model", repo.DeleteModel) | ||||
| @@ -497,6 +497,7 @@ | |||||
| } | } | ||||
| validate(); | validate(); | ||||
| $('.ui.create_train_job.green.button').click(function(e) { | $('.ui.create_train_job.green.button').click(function(e) { | ||||
| send_run_para() | |||||
| send_run_para(); | |||||
| validate(); | |||||
| }) | }) | ||||
| </script> | </script> | ||||
| @@ -499,6 +499,7 @@ | |||||
| } | } | ||||
| validate(); | validate(); | ||||
| $('.ui.create_train_job.green.button').click(function (e) { | $('.ui.create_train_job.green.button').click(function (e) { | ||||
| send_run_para() | |||||
| send_run_para(); | |||||
| validate(); | |||||
| }) | }) | ||||
| </script> | </script> | ||||
| @@ -446,6 +446,7 @@ | |||||
| } | } | ||||
| validate(); | validate(); | ||||
| $('.ui.create_train_job.green.button').click(function(e) { | $('.ui.create_train_job.green.button').click(function(e) { | ||||
| send_run_para() | |||||
| send_run_para(); | |||||
| validate(); | |||||
| }) | }) | ||||
| </script> | </script> | ||||
| @@ -478,6 +478,7 @@ | |||||
| validate(); | validate(); | ||||
| $('.ui.create_train_job.green.button').click(function(e) { | $('.ui.create_train_job.green.button').click(function(e) { | ||||
| get_name() | get_name() | ||||
| send_run_para() | |||||
| send_run_para(); | |||||
| validate(); | |||||
| }) | }) | ||||
| </script> | </script> | ||||
| @@ -522,6 +522,7 @@ | |||||
| validate(); | validate(); | ||||
| $('.ui.create_train_job.green.button').click(function(e) { | $('.ui.create_train_job.green.button').click(function(e) { | ||||
| send_run_para() | send_run_para() | ||||
| get_name() | |||||
| get_name(); | |||||
| validate(); | |||||
| }) | }) | ||||
| </script> | </script> | ||||
| @@ -531,6 +531,7 @@ | |||||
| validate(); | validate(); | ||||
| $('.ui.create_train_job.green.button').click(function (e) { | $('.ui.create_train_job.green.button').click(function (e) { | ||||
| get_name() | get_name() | ||||
| send_run_para() | |||||
| send_run_para(); | |||||
| validate(); | |||||
| }) | }) | ||||
| </script> | </script> | ||||
| @@ -75,8 +75,8 @@ | |||||
| <input | <input | ||||
| type="text" | type="text" | ||||
| placeholder="搜数据集名称/描述..." | placeholder="搜数据集名称/描述..." | ||||
| v-model="search" | |||||
| @keyup.enter="searchName" | |||||
| v-model="search" | |||||
| @keydown.enter.stop.prevent="searchName" | |||||
| /> | /> | ||||
| </div> | </div> | ||||
| <el-row> | <el-row> | ||||
| @@ -727,7 +727,7 @@ export default { | |||||
| "currentTree", | "currentTree", | ||||
| this.paramsCurrent.page | this.paramsCurrent.page | ||||
| ); | ); | ||||
| this.initCurrentTreeNode = [this.currentDatasetList[0].id]; | |||||
| this.initCurrentTreeNode = this.currentDatasetList[0]?.id ? [this.currentDatasetList[0].id] : []; | |||||
| this.totalNumCurrent = parseInt(res.data.count); | this.totalNumCurrent = parseInt(res.data.count); | ||||
| let setCheckedKeysList = this.currentDatasetList.reduce( | let setCheckedKeysList = this.currentDatasetList.reduce( | ||||
| (pre, cur) => { | (pre, cur) => { | ||||
| @@ -742,7 +742,7 @@ export default { | |||||
| ); | ); | ||||
| this.$refs.currentTree.setCheckedKeys(setCheckedKeysList); | this.$refs.currentTree.setCheckedKeys(setCheckedKeysList); | ||||
| }) | }) | ||||
| .catch(function (error) { | |||||
| .catch((error) => { | |||||
| this.loadingCurrent = false; | this.loadingCurrent = false; | ||||
| console.log(error); | console.log(error); | ||||
| }); | }); | ||||
| @@ -763,7 +763,7 @@ export default { | |||||
| "myTree", | "myTree", | ||||
| this.paramsMy.page | this.paramsMy.page | ||||
| ); | ); | ||||
| this.initMyTreeNode = [this.myDatasetList[0].id]; | |||||
| this.initMyTreeNode = this.myDatasetList[0]?.id ? [this.myDatasetList[0].id] : []; | |||||
| this.totalNumMy = parseInt(res.data.count); | this.totalNumMy = parseInt(res.data.count); | ||||
| let setCheckedKeysList = this.myDatasetList.reduce((pre, cur) => { | let setCheckedKeysList = this.myDatasetList.reduce((pre, cur) => { | ||||
| cur.Attachments.forEach((item) => { | cur.Attachments.forEach((item) => { | ||||
| @@ -775,7 +775,7 @@ export default { | |||||
| }, []); | }, []); | ||||
| this.$refs.myTree.setCheckedKeys(setCheckedKeysList); | this.$refs.myTree.setCheckedKeys(setCheckedKeysList); | ||||
| }) | }) | ||||
| .catch(function (error) { | |||||
| .catch((error) => { | |||||
| console.log(error); | console.log(error); | ||||
| }); | }); | ||||
| }, | }, | ||||
| @@ -796,7 +796,7 @@ export default { | |||||
| "publicTree", | "publicTree", | ||||
| this.paramsPublics.page | this.paramsPublics.page | ||||
| ); | ); | ||||
| this.initPublicTreeNode = [this.publicDatasetList[0].id]; | |||||
| this.initPublicTreeNode = this.publicDatasetList[0]?.id ? [this.publicDatasetList[0].id] : []; | |||||
| this.totalNumPublic = parseInt(res.data.count); | this.totalNumPublic = parseInt(res.data.count); | ||||
| let setCheckedKeysList = this.publicDatasetList.reduce((pre, cur) => { | let setCheckedKeysList = this.publicDatasetList.reduce((pre, cur) => { | ||||
| cur.Attachments.forEach((item) => { | cur.Attachments.forEach((item) => { | ||||
| @@ -808,7 +808,7 @@ export default { | |||||
| }, []); | }, []); | ||||
| this.$refs.publicTree.setCheckedKeys(setCheckedKeysList); | this.$refs.publicTree.setCheckedKeys(setCheckedKeysList); | ||||
| }) | }) | ||||
| .catch(function (error) { | |||||
| .catch((error) => { | |||||
| this.loadingPublic = false; | this.loadingPublic = false; | ||||
| console.log(error); | console.log(error); | ||||
| }); | }); | ||||
| @@ -830,7 +830,7 @@ export default { | |||||
| "favoriteTree", | "favoriteTree", | ||||
| this.paramsFavorite.page | this.paramsFavorite.page | ||||
| ); | ); | ||||
| this.initFavoriteTreeNode = [this.MyFavoriteDatasetList[0].id]; | |||||
| this.initFavoriteTreeNode = this.MyFavoriteDatasetList[0]?.id ? [this.MyFavoriteDatasetList[0].id] : []; | |||||
| this.totalNumFavorite = parseInt(res.data.count); | this.totalNumFavorite = parseInt(res.data.count); | ||||
| let setCheckedKeysList = this.MyFavoriteDatasetList.reduce( | let setCheckedKeysList = this.MyFavoriteDatasetList.reduce( | ||||
| (pre, cur) => { | (pre, cur) => { | ||||
| @@ -845,7 +845,7 @@ export default { | |||||
| ); | ); | ||||
| this.$refs.favoriteTree.setCheckedKeys(setCheckedKeysList); | this.$refs.favoriteTree.setCheckedKeys(setCheckedKeysList); | ||||
| }) | }) | ||||
| .catch(function (error) { | |||||
| .catch((error) => { | |||||
| this.loadingFavorite = false; | this.loadingFavorite = false; | ||||
| console.log(error); | console.log(error); | ||||
| }); | }); | ||||
| @@ -956,7 +956,6 @@ export default { | |||||
| this.benchmarkNew = true; | this.benchmarkNew = true; | ||||
| } | } | ||||
| if (location.href.indexOf("modelarts/notebook/create") !== -1 || location.href.indexOf("/cloudbrain/create") !== -1) { | if (location.href.indexOf("modelarts/notebook/create") !== -1 || location.href.indexOf("/cloudbrain/create") !== -1) { | ||||
| console.log("required is false;"); | |||||
| this.required = false; | this.required = false; | ||||
| } | } | ||||
| window.onresize = () => { | window.onresize = () => { | ||||