diff --git a/models/cloudbrain.go b/models/cloudbrain.go index 4840b78c0..4b4c2c099 100755 --- a/models/cloudbrain.go +++ b/models/cloudbrain.go @@ -1329,6 +1329,9 @@ func QueryModelTrainJobList(repoId int64) ([]*CloudbrainInfo, int, error) { cond = cond.And( builder.Eq{"job_type": "TRAIN"}, ) + cond = cond.And( + builder.In("type", 0, 1), + ) cloudbrains := make([]*CloudbrainInfo, 0) if err := sess.Select("job_id,display_job_name").Table(&Cloudbrain{}).Where(cond).OrderBy("created_unix DESC"). @@ -1795,3 +1798,44 @@ func CloudbrainAll(opts *CloudbrainsOptions) ([]*CloudbrainInfo, int64, error) { return cloudbrains, count, nil } +func CloudbrainAllStatic(opts *CloudbrainsOptions) ([]*CloudbrainInfo, int64, error) { + sess := x.NewSession() + defer sess.Close() + + var cond = builder.NewCond() + + if (opts.Type) >= 0 { + cond = cond.And( + builder.Eq{"cloudbrain.type": opts.Type}, + ) + } + if opts.BeginTimeUnix > 0 && opts.EndTimeUnix > 0 { + cond = cond.And( + builder.And(builder.Gte{"cloudbrain.created_unix": opts.BeginTimeUnix}, builder.Lte{"cloudbrain.created_unix": opts.EndTimeUnix}), + ) + } + var count int64 + var err error + count, err = sess.Unscoped().Where(cond).Count(new(Cloudbrain)) + + if err != nil { + return nil, 0, fmt.Errorf("Count: %v", err) + } + + if opts.Page >= 0 && opts.PageSize > 0 { + var start int + if opts.Page == 0 { + start = 0 + } else { + start = (opts.Page - 1) * opts.PageSize + } + sess.Limit(opts.PageSize, start) + } + sess.OrderBy("cloudbrain.created_unix DESC") + cloudbrains := make([]*CloudbrainInfo, 0, setting.UI.IssuePagingNum) + if err := sess.Cols("status", "type", "job_type", "train_job_duration", "duration", "compute_resource", "created_unix", "start_time", "end_time").Table(&Cloudbrain{}).Unscoped().Where(cond). + Find(&cloudbrains); err != nil { + return nil, 0, fmt.Errorf("Find: %v", err) + } + return cloudbrains, count, nil +} diff --git a/models/cloudbrain_static.go b/models/cloudbrain_static.go index 27cccf415..03cd7d2bc 100644 --- a/models/cloudbrain_static.go +++ b/models/cloudbrain_static.go @@ -213,7 +213,7 @@ func GetWaittingTop() ([]*CloudbrainInfo, error) { cond = cond.And( builder.Eq{"cloudbrain.status": string(JobWaiting)}, ) - sess.OrderBy("(cloudbrain.start_time-cloudbrain.created_unix) DESC limit 10") + sess.OrderBy("cloudbrain.created_unix ASC limit 10") cloudbrains := make([]*CloudbrainInfo, 0, 10) if err := sess.Table(&Cloudbrain{}).Where(cond). Find(&cloudbrains); err != nil { @@ -228,7 +228,7 @@ func GetRunningTop() ([]*CloudbrainInfo, error) { cond = cond.And( builder.Eq{"cloudbrain.status": string(JobRunning)}, ) - sess.OrderBy("(cloudbrain.end_time-cloudbrain.start_time) DESC limit 10") + sess.OrderBy("cloudbrain.duration DESC limit 10") cloudbrains := make([]*CloudbrainInfo, 0, 10) if err := sess.Table(&Cloudbrain{}).Where(cond). Find(&cloudbrains); err != nil { diff --git a/models/dataset.go b/models/dataset.go index 53b63185f..b7186ac0b 100755 --- a/models/dataset.go +++ b/models/dataset.go @@ -181,7 +181,6 @@ func SearchDatasetCondition(opts *SearchDatasetOptions) builder.Cond { if len(opts.DatasetIDs) > 0 { subCon := builder.NewCond() subCon = subCon.And(builder.In("dataset.id", opts.DatasetIDs)) - subCon = generateFilterCond(opts, subCon) cond = cond.Or(subCon) } @@ -461,12 +460,5 @@ func GetCollaboratorDatasetIdsByUserID(userID int64) []int64 { _ = x.Table("dataset").Join("INNER", "collaboration", "dataset.repo_id = collaboration.repo_id and collaboration.mode>0 and collaboration.user_id=?", userID). Cols("dataset.id").Find(&datasets) return datasets -} -func GetTeamDatasetIdsByUserID(userID int64) []int64 { - var datasets []int64 - _ = x.Table("dataset").Join("INNER", "team_repo", "dataset.repo_id = team_repo.repo_id"). - Join("INNER", "team_user", "team_repo.team_id=team_user.team_id and team_user.uid=?", userID). - Cols("dataset.id").Find(&datasets) - return datasets } diff --git a/models/user.go b/models/user.go index 7d4c8ce34..dd5a6f1d2 100755 --- a/models/user.go +++ b/models/user.go @@ -6,7 +6,6 @@ package models import ( - "code.gitea.io/gitea/modules/blockchain" "container/list" "context" "crypto/md5" @@ -25,6 +24,8 @@ import ( "time" "unicode/utf8" + "code.gitea.io/gitea/modules/blockchain" + "code.gitea.io/gitea/modules/avatar" "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/generate" @@ -1498,6 +1499,17 @@ func GetUsersByIDs(ids []int64) (UserList, error) { return ous, err } +func GetUsersByNames(names []string) (UserList, error) { + ous := make([]*User, 0, len(names)) + if len(names) == 0 { + return ous, nil + } + err := x.In("name", names). + Asc("name"). + Find(&ous) + return ous, err +} + // GetUserIDsByNames returns a slice of ids corresponds to names. func GetUserIDsByNames(names []string, ignoreNonExistent bool) ([]int64, error) { ids := make([]int64, 0, len(names)) diff --git a/public/home/home.js b/public/home/home.js index 9754de0cb..7343dba0b 100755 --- a/public/home/home.js +++ b/public/home/home.js @@ -217,9 +217,9 @@ function refresh3DInfo(record){ //console.log("cloudbrain two line length=" + lines.length); var span = $('.rotation3D__line').find("span")[1]; //console.log(span); - span.innerText =record.RefName; - //$('.rotation3D__line').find("span").eq(1).text(record.RefName) - //lines[1].find("span").text(record.RefName); + if(span != null){ + span.innerText =record.RefName; + } } } @@ -452,48 +452,12 @@ function queryRecommendData(){ displayOrg(json.org); displayRepo(json.repo); displayActivity(json.image); - displayCloudBrain(json.cloudbrain) }, error:function(response) { } }); - - // $.ajax({ - // type:"GET", - // url:"/recommend/repo", - // headers: { - // authorization:token, - // }, - // dataType:"json", - // async:false, - // success:function(json){ - // displayRepo(json); - // }, - // error:function(response) { - // } - // }); - - // $.ajax({ - // type:"GET", - // url:"/recommend/imageinfo", - // headers: { - // authorization:token, - // }, - // dataType:"json", - // async:false, - // success:function(json){ - // displayActivity(json); - // }, - // error:function(response) { - // } - // }); } -function displayCloudBrain(json){ - $('#completed_task').text(json.completed_task); - $('#running_task').text(json.running_task); - $('#wait_task').text(json.wait_task); -} function displayActivity(json){ var activityDiv = document.getElementById("recommendactivity"); diff --git a/routers/api/v1/repo/cloudbrain_dashboard.go b/routers/api/v1/repo/cloudbrain_dashboard.go index 07298ffdc..f102a0f05 100644 --- a/routers/api/v1/repo/cloudbrain_dashboard.go +++ b/routers/api/v1/repo/cloudbrain_dashboard.go @@ -67,7 +67,7 @@ func GetAllCloudbrainsOverview(ctx *context.Context) { pagesize := 1000 count := pagesize for count == pagesize && count != 0 { - cloudbrains, _, err := models.CloudbrainAll(&models.CloudbrainsOptions{ + cloudbrains, _, err := models.CloudbrainAllStatic(&models.CloudbrainsOptions{ ListOptions: models.ListOptions{ Page: page, PageSize: pagesize, @@ -121,6 +121,13 @@ func GetAllCloudbrainsOverview(ctx *context.Context) { } } + cloudBrainTypeList := []int{0, 1, 2} + for _, v := range cloudBrainTypeList { + if _, ok := cloudBrainNum[v]; !ok { + cloudBrainNum[v] = 0 + } + } + todayRunningCount := todayStatusResult[string(models.JobRunning)] todayCompletedCount := todayStatusResult[string(models.ModelArtsTrainJobCompleted)] + todayStatusResult[string(models.JobFailed)] + todayStatusResult[string(models.ModelArtsStartFailed)] + todayStatusResult[string(models.JobStopped)] + todayStatusResult[string(models.JobSucceeded)] + todayStatusResult[string(models.ModelArtsTrainJobKilled)] @@ -504,7 +511,7 @@ func GetAllCloudbrainsPeriodDistribution(ctx *context.Context) { count := pagesize //Each time a maximum of 1000 pieces of data are detected to the memory, batch processing for count == pagesize && count != 0 { - cloudbrains, _, err := models.CloudbrainAll(&models.CloudbrainsOptions{ + cloudbrains, _, err := models.CloudbrainAllStatic(&models.CloudbrainsOptions{ ListOptions: models.ListOptions{ Page: page, PageSize: pagesize, @@ -613,7 +620,7 @@ func GetCloudbrainsStatusAnalysis(ctx *context.Context) { pagesize := 1000 count := pagesize for count == pagesize && count != 0 { - cloudbrains, _, err := models.CloudbrainAll(&models.CloudbrainsOptions{ + cloudbrains, _, err := models.CloudbrainAllStatic(&models.CloudbrainsOptions{ ListOptions: models.ListOptions{ Page: page, PageSize: pagesize, @@ -1021,7 +1028,7 @@ func getCloudbrainCount(beginTime time.Time, endTime time.Time, cloudbrains []*m func getDayCloudbrainNum(beginTime time.Time, endTime time.Time) ([]DateCloudbrainNum, error) { var endTimeTemp time.Time endTimeTemp = beginTime.AddDate(0, 0, 1) - cloudbrains, _, err := models.CloudbrainAll(&models.CloudbrainsOptions{ + cloudbrains, _, err := models.CloudbrainAllStatic(&models.CloudbrainsOptions{ Type: models.TypeCloudBrainAll, BeginTimeUnix: beginTime.Unix(), EndTimeUnix: endTime.Unix(), @@ -1057,7 +1064,7 @@ func getMonthCloudbrainNum(beginTime time.Time, endTime time.Time) ([]DateCloudb endTimeTemp = beginTime.AddDate(0, 1, 0) endTimeTemp = time.Date(endTimeTemp.Year(), endTimeTemp.Month(), 1, 0, 0, 0, 0, now.Location()) monthCloudbrainNum := make([]DateCloudbrainNum, 0) - cloudbrains, _, err := models.CloudbrainAll(&models.CloudbrainsOptions{ + cloudbrains, _, err := models.CloudbrainAllStatic(&models.CloudbrainsOptions{ Type: models.TypeCloudBrainAll, BeginTimeUnix: beginTime.Unix(), EndTimeUnix: endTime.Unix(), @@ -1093,7 +1100,7 @@ func getDayCloudbrainInfo(beginTime time.Time, endTime time.Time) ([]DateCloudbr if endTimeTemp.Equal(endTime) { endTimeTemp = endTimeTemp.AddDate(0, 0, -1) } - cloudbrains, _, err := models.CloudbrainAll(&models.CloudbrainsOptions{ + cloudbrains, _, err := models.CloudbrainAllStatic(&models.CloudbrainsOptions{ Type: models.TypeCloudBrainAll, BeginTimeUnix: beginTime.Unix(), EndTimeUnix: endTime.Unix(), @@ -1124,7 +1131,7 @@ func getMonthCloudbrainInfo(beginTime time.Time, endTime time.Time) ([]DateCloud if endTimeTemp.Equal(endTime) { endTimeTemp = endTimeTemp.AddDate(0, -1, 0) } - cloudbrains, _, err := models.CloudbrainAll(&models.CloudbrainsOptions{ + cloudbrains, _, err := models.CloudbrainAllStatic(&models.CloudbrainsOptions{ Type: models.TypeCloudBrainAll, BeginTimeUnix: beginTime.Unix(), EndTimeUnix: endTime.Unix(), diff --git a/routers/home.go b/routers/home.go index a147a84ea..1ed5faaa8 100755 --- a/routers/home.go +++ b/routers/home.go @@ -7,7 +7,6 @@ package routers import ( "bytes" - "fmt" "net/http" "strconv" "strings" @@ -346,9 +345,7 @@ func ExploreDatasets(ctx *context.Context) { var datasetsIds []int64 if ownerID > 0 { - collaboratorDatasetsIds := models.GetCollaboratorDatasetIdsByUserID(ownerID) - teamDatasetsIds := models.GetTeamDatasetIdsByUserID(ownerID) - datasetsIds = append(collaboratorDatasetsIds, teamDatasetsIds...) + datasetsIds = models.GetCollaboratorDatasetIdsByUserID(ownerID) } opts := &models.SearchDatasetOptions{ @@ -675,10 +672,19 @@ func getRecommendOrg() ([]map[string]interface{}, error) { if err != nil { return nil, err } + names := make([]string, 0) + for _, userName := range result { + names = append(names, userName) + } + users, _ := models.GetUsersByNames(names) + userMap := make(map[string]*models.User, 0) + for _, user := range users { + userMap[user.Name] = user + } resultOrg := make([]map[string]interface{}, 0) for _, userName := range result { - user, err := models.GetUserByName(userName) - if err == nil { + user := userMap[userName] + if user != nil { userMap := make(map[string]interface{}) userMap["Name"] = user.Name userMap["Description"] = user.Description @@ -691,7 +697,7 @@ func getRecommendOrg() ([]map[string]interface{}, error) { userMap["NumMembers"] = user.NumMembers resultOrg = append(resultOrg, userMap) } else { - log.Info("query user error," + err.Error()) + log.Info("the user not exist," + userName) } } return resultOrg, nil @@ -760,15 +766,6 @@ func GetRankUser(index string) ([]map[string]interface{}, error) { return resultOrg, nil } -// func GetImageInfoFromPromote(ctx *context.Context) { -// imageInfo, err := GetImageInfo() -// if err != nil { -// ctx.ServerError("500", err) -// return -// } -// ctx.JSON(200, imageInfo) -// } - func GetUserRankFromPromote(ctx *context.Context) { index := ctx.Params("index") resultUserRank, err := GetRankUser(index) @@ -792,45 +789,15 @@ func RecommendHomeInfo(ctx *context.Context) { if err != nil { log.Info("error." + err.Error()) } - resultCloudBrain, err := getCloudbrainNums() - if err != nil { - log.Info("error." + err.Error()) - } + mapInterface := make(map[string]interface{}) mapInterface["org"] = resultOrg mapInterface["repo"] = resultRepo mapInterface["image"] = resultImage - mapInterface["cloudbrain"] = resultCloudBrain + //mapInterface["cloudbrain"] = resultCloudBrain ctx.JSON(http.StatusOK, mapInterface) } -func getCloudbrainNums() (map[string]string, error) { - result := make(map[string]string) - cloudStatusMap := models.GetAllStatusCloudBrain() - result["completed_task"] = fmt.Sprint(cloudStatusMap["COMPLETED"]) - result["running_task"] = fmt.Sprint(cloudStatusMap["RUNNING"]) - result["wait_task"] = fmt.Sprint(cloudStatusMap["WAITING"]) - return result, nil -} - -// func RecommendOrgFromPromote(ctx *context.Context) { -// resultOrg, err := GetRecommendOrg() -// if err != nil { -// ctx.ServerError("500", err) -// return -// } -// ctx.JSON(200, resultOrg) -// } - -func RecommendRepoFromPromote(ctx *context.Context) { - result, err := repository.GetRecommendRepoFromPromote("projects") - if err != nil { - ctx.ServerError("500", err) - } else { - ctx.JSON(200, result) - } -} - func HomeTerm(ctx *context.Context) { ctx.HTML(200, tplHomeTerm) } diff --git a/services/repository/repository.go b/services/repository/repository.go index 80518b666..6bf4ab283 100644 --- a/services/repository/repository.go +++ b/services/repository/repository.go @@ -131,11 +131,6 @@ func GetRecommendRepoFromPromote(filename string) ([]map[string]interface{}, err repoMap["ID"] = fmt.Sprint(repo.ID) repoMap["Name"] = repo.Name repoMap["Alias"] = repo.Alias - if repo.RepoType == models.RepoCourse { - //Load creator - repo.GetCreator() - repoMap["Creator"] = repo.Creator - } repoMap["OwnerName"] = repo.OwnerName repoMap["NumStars"] = repo.NumStars diff --git a/templates/repo/modelarts/trainjob/new.tmpl b/templates/repo/modelarts/trainjob/new.tmpl index cff51c524..9d6a45e83 100755 --- a/templates/repo/modelarts/trainjob/new.tmpl +++ b/templates/repo/modelarts/trainjob/new.tmpl @@ -1,67 +1,72 @@ {{template "base/head" .}}
-
-
-
-
-
-
-
+
+
+
+
+
+
+
{{template "repo/header" .}} @@ -82,29 +87,41 @@
- + {{.i18n.Tr "cloudbrain.job_name_rule"}}
- - + +
@@ -112,43 +129,45 @@
- - + +
- +
- {{range .engines}} - + {{end}}
- + {{range .engine_versions}} + + {{end}}
@@ -156,41 +175,49 @@
- - {{if .bootFile}} - - {{else}} - - {{end}} - - - - {{.i18n.Tr "cloudbrain.view_sample"}} + + {{if .bootFile}} + + {{else}} + + {{end}} + + + + {{.i18n.Tr "cloudbrain.view_sample"}}
- + {{template "custom/select_dataset_train" .}} - {{.i18n.Tr "cloudbrain.dataset_path_rule"}} + {{.i18n.Tr "cloudbrain.dataset_path_rule"}}
- {{.i18n.Tr "repo.modelarts.train_job.add_run_parameter"}} - + {{.i18n.Tr "repo.modelarts.train_job.add_run_parameter"}} +
- {{if ne 0 (len .params)}} + {{if ne 0 (len .params)}} {{range $k ,$v := .params}} -
-
- -
-
- -
- - - - +
+
+ +
+
+
+ + + + +
+ {{end}} {{end}} - {{end}}
@@ -199,13 +226,14 @@