From 36e88d0ab48cb5f7811b512257cab1a7de52a9b9 Mon Sep 17 00:00:00 2001 From: zouap Date: Mon, 14 Mar 2022 17:43:48 +0800 Subject: [PATCH 001/256] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=88=86=E6=9E=90=E4=B8=AD=E7=9A=84=E4=BB=A3=E7=A0=81=E8=A1=8C?= =?UTF-8?q?=E6=95=B0=E6=8C=87=E6=A0=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- models/user_business_analysis.go | 61 ++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 14 deletions(-) diff --git a/models/user_business_analysis.go b/models/user_business_analysis.go index 288762161..1c87f5d08 100644 --- a/models/user_business_analysis.go +++ b/models/user_business_analysis.go @@ -6,7 +6,6 @@ import ( "strconv" "time" - "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/timeutil" "xorm.io/builder" @@ -353,7 +352,7 @@ func QueryUserStaticDataPage(opts *UserBusinessAnalysisQueryOptions) ([]*UserBus return userBusinessAnalysisReturnList, count } -func refreshUserStaticTable(wikiCountMap map[string]int, CommitCodeSizeMap map[string]*git.UserKPIStats, tableName string, pageStartTime time.Time, pageEndTime time.Time) { +func refreshUserStaticTable(wikiCountMap map[string]int, tableName string, pageStartTime time.Time, pageEndTime time.Time) { sess := x.NewSession() defer sess.Close() @@ -379,7 +378,7 @@ func refreshUserStaticTable(wikiCountMap map[string]int, CommitCodeSizeMap map[s FocusRepoCountMap := queryWatch(start_unix, end_unix) StarRepoCountMap := queryStar(start_unix, end_unix) WatchedCountMap := queryFollow(start_unix, end_unix) - + CommitCodeSizeMap := queryCommitCodeSize(start_unix, end_unix) CommitDatasetSizeMap := queryDatasetSize(start_unix, end_unix) SolveIssueCountMap := querySolveIssue(start_unix, end_unix) CreateRepoCountMap := queryUserCreateRepo(start_unix, end_unix) @@ -455,10 +454,10 @@ func refreshUserStaticTable(wikiCountMap map[string]int, CommitCodeSizeMap map[s dateRecordAll.WatchedCount = WatchedCountMap[dateRecordAll.ID] } - if _, ok := CommitCodeSizeMap[dateRecordAll.Email]; !ok { + if _, ok := CommitCodeSizeMap[dateRecordAll.ID]; !ok { dateRecordAll.CommitCodeSize = 0 } else { - dateRecordAll.CommitCodeSize = int(CommitCodeSizeMap[dateRecordAll.Email].CommitLines) + dateRecordAll.CommitCodeSize = CommitCodeSizeMap[dateRecordAll.ID] } if _, ok := CommitDatasetSizeMap[dateRecordAll.ID]; !ok { @@ -546,36 +545,36 @@ func insertTable(dateRecords []UserBusinessAnalysisAll, tableName string, static statictisSess.Exec(insertBatchSql) } -func RefreshUserStaticAllTabel(wikiCountMap map[string]int, CommitCodeSizeMap map[string]*git.UserKPIStats) { +func RefreshUserStaticAllTabel(wikiCountMap map[string]int) { currentTimeNow := time.Now() pageStartTime := time.Date(2021, 11, 5, 0, 0, 0, 0, currentTimeNow.Location()) pageEndTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 23, 59, 59, 0, currentTimeNow.Location()) - refreshUserStaticTable(wikiCountMap, CommitCodeSizeMap, "user_business_analysis_all", pageStartTime, pageEndTime) + refreshUserStaticTable(wikiCountMap, "user_business_analysis_all", pageStartTime, pageEndTime) log.Info("refresh all data finished.") pageStartTime = time.Date(currentTimeNow.Year(), 1, 1, 0, 0, 0, 0, currentTimeNow.Location()) - refreshUserStaticTable(wikiCountMap, CommitCodeSizeMap, "user_business_analysis_current_year", pageStartTime, pageEndTime) + refreshUserStaticTable(wikiCountMap, "user_business_analysis_current_year", pageStartTime, pageEndTime) thisMonth := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), 1, 0, 0, 0, 0, currentTimeNow.Location()) - refreshUserStaticTable(wikiCountMap, CommitCodeSizeMap, "user_business_analysis_current_month", thisMonth, pageEndTime) + refreshUserStaticTable(wikiCountMap, "user_business_analysis_current_month", thisMonth, pageEndTime) offset := int(time.Monday - currentTimeNow.Weekday()) if offset > 0 { offset = -6 } pageStartTime = time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, offset) - refreshUserStaticTable(wikiCountMap, CommitCodeSizeMap, "user_business_analysis_current_week", pageStartTime, pageEndTime) + refreshUserStaticTable(wikiCountMap, "user_business_analysis_current_week", pageStartTime, pageEndTime) pageStartTime = time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, -30) - refreshUserStaticTable(wikiCountMap, CommitCodeSizeMap, "user_business_analysis_last30_day", pageStartTime, pageEndTime) + refreshUserStaticTable(wikiCountMap, "user_business_analysis_last30_day", pageStartTime, pageEndTime) pageStartTime = time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, -1) pageEndTime = time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 23, 59, 59, 0, currentTimeNow.Location()).AddDate(0, 0, -1) - refreshUserStaticTable(wikiCountMap, CommitCodeSizeMap, "user_business_analysis_yesterday", pageStartTime, pageEndTime) + refreshUserStaticTable(wikiCountMap, "user_business_analysis_yesterday", pageStartTime, pageEndTime) pageStartTime = thisMonth.AddDate(0, -1, 0) pageEndTime = time.Date(currentTimeNow.Year(), currentTimeNow.Month(), 1, 23, 59, 59, 0, currentTimeNow.Location()).AddDate(0, 0, -1) - refreshUserStaticTable(wikiCountMap, CommitCodeSizeMap, "user_business_analysis_last_month", pageStartTime, pageEndTime) + refreshUserStaticTable(wikiCountMap, "user_business_analysis_last_month", pageStartTime, pageEndTime) } @@ -747,7 +746,7 @@ func CounDataByDateAndReCount(wikiCountMap map[string]int, startTime time.Time, } } - RefreshUserStaticAllTabel(wikiCountMap, CommitCodeSizeMap) + RefreshUserStaticAllTabel(wikiCountMap) return nil } @@ -1212,6 +1211,40 @@ func queryLoginCount(start_unix int64, end_unix int64) map[int64]int { return resultMap } +func queryCommitCodeSize(start_unix int64, end_unix int64) map[int64]int { + statictisSess := xStatistic.NewSession() + defer statictisSess.Close() + + resultMap := make(map[int64]int) + cond := "count_date>=" + fmt.Sprint(start_unix) + " and count_date<=" + fmt.Sprint(end_unix) + count, err := statictisSess.Where(cond).Count(new(UserBusinessAnalysis)) + if err != nil { + log.Info("query commit code size error. return.") + return resultMap + } + var indexTotal int64 + indexTotal = 0 + for { + statictisSess.Select("id,commit_code_size").Table("user_business_analysis").Where(cond).OrderBy("id asc").Limit(PAGE_SIZE, int(indexTotal)) + userBusinessAnalysisList := make([]*UserBusinessAnalysis, 0) + statictisSess.Find(&userBusinessAnalysisList) + log.Info("query user login size=" + fmt.Sprint(len(userBusinessAnalysisList))) + for _, analysisRecord := range userBusinessAnalysisList { + if _, ok := resultMap[analysisRecord.ID]; !ok { + resultMap[analysisRecord.ID] = analysisRecord.CommitCodeSize + } else { + resultMap[analysisRecord.ID] += analysisRecord.CommitCodeSize + } + } + indexTotal += PAGE_SIZE + if indexTotal >= count { + break + } + } + log.Info("user commit code size=" + fmt.Sprint(len(resultMap))) + return resultMap +} + func subMonth(t1, t2 time.Time) (month int) { y1 := t1.Year() y2 := t2.Year() From 292236988b38327f9c7527462cc97307b1f6efa2 Mon Sep 17 00:00:00 2001 From: zouap Date: Thu, 17 Mar 2022 10:21:46 +0800 Subject: [PATCH 002/256] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- models/user_business_analysis.go | 365 +++++++++++++++++-------------- models/user_business_struct.go | 72 ++++++ 2 files changed, 278 insertions(+), 159 deletions(-) diff --git a/models/user_business_analysis.go b/models/user_business_analysis.go index 1c87f5d08..e059ef3e4 100644 --- a/models/user_business_analysis.go +++ b/models/user_business_analysis.go @@ -80,6 +80,19 @@ type UserBusinessAnalysisAll struct { Name string `xorm:"NOT NULL"` DataDate string `xorm:"NULL"` + + //cloudbraintask + CloudBrainTaskNum int `xorm:"NOT NULL DEFAULT 0"` + GpuDebugJob int `xorm:"NOT NULL DEFAULT 0"` + NpuDebugJob int `xorm:"NOT NULL DEFAULT 0"` + GpuTrainJob int `xorm:"NOT NULL DEFAULT 0"` + NpuTrainJob int `xorm:"NOT NULL DEFAULT 0"` + NpuInferenceJob int `xorm:"NOT NULL DEFAULT 0"` + GpuBenchMarkJob int `xorm:"NOT NULL DEFAULT 0"` + CloudBrainRunTime int `xorm:"NOT NULL DEFAULT 0"` + CommitDatasetNum int `xorm:"NOT NULL DEFAULT 0"` + UserIndex float64 `xorm:"NOT NULL DEFAULT 0"` + UserLocation string `xorm:"NULL"` } type UserBusinessAnalysis struct { @@ -145,6 +158,18 @@ type UserBusinessAnalysis struct { Name string `xorm:"NOT NULL"` DataDate string `xorm:"NULL"` + + CloudBrainTaskNum int `xorm:"NOT NULL DEFAULT 0"` + GpuDebugJob int `xorm:"NOT NULL DEFAULT 0"` + NpuDebugJob int `xorm:"NOT NULL DEFAULT 0"` + GpuTrainJob int `xorm:"NOT NULL DEFAULT 0"` + NpuTrainJob int `xorm:"NOT NULL DEFAULT 0"` + NpuInferenceJob int `xorm:"NOT NULL DEFAULT 0"` + GpuBenchMarkJob int `xorm:"NOT NULL DEFAULT 0"` + CloudBrainRunTime int `xorm:"NOT NULL DEFAULT 0"` + CommitDatasetNum int `xorm:"NOT NULL DEFAULT 0"` + UserIndex float64 `xorm:"NOT NULL DEFAULT 0"` + UserLocation string `xorm:"NULL"` } type UserBusinessAnalysisQueryOptions struct { @@ -333,6 +358,7 @@ func QueryUserStaticDataPage(opts *UserBusinessAnalysisQueryOptions) ([]*UserBus resultMap[userRecord.ID].WatchedCount += userRecord.WatchedCount resultMap[userRecord.ID].CommitCodeSize += userRecord.CommitCodeSize resultMap[userRecord.ID].CommitDatasetSize += userRecord.CommitDatasetSize + resultMap[userRecord.ID].CommitDatasetNum += userRecord.CommitDatasetNum resultMap[userRecord.ID].CommitModelCount += userRecord.CommitModelCount resultMap[userRecord.ID].SolveIssueCount += userRecord.SolveIssueCount resultMap[userRecord.ID].EncyclopediasCount += userRecord.EncyclopediasCount @@ -379,13 +405,14 @@ func refreshUserStaticTable(wikiCountMap map[string]int, tableName string, pageS StarRepoCountMap := queryStar(start_unix, end_unix) WatchedCountMap := queryFollow(start_unix, end_unix) CommitCodeSizeMap := queryCommitCodeSize(start_unix, end_unix) - CommitDatasetSizeMap := queryDatasetSize(start_unix, end_unix) + CommitDatasetSizeMap, CommitDatasetNumMap := queryDatasetSize(start_unix, end_unix) SolveIssueCountMap := querySolveIssue(start_unix, end_unix) CreateRepoCountMap := queryUserCreateRepo(start_unix, end_unix) LoginCountMap := queryLoginCount(start_unix, end_unix) OpenIIndexMap := queryUserRepoOpenIIndex(startTime.Unix(), end_unix) - + CloudBrainTaskMap, CloudBrainTaskItemMap := queryCloudBrainTask(start_unix, end_unix) + AiModelManageMap := queryUserModel(start_unix, end_unix) DataDate := currentTimeNow.Format("2006-01-02") + " 00:01" cond := "type != 1 and is_active=true" @@ -411,84 +438,22 @@ func refreshUserStaticTable(wikiCountMap map[string]int, tableName string, pageS dateRecordAll.Name = userRecord.Name dateRecordAll.GiteaAgeMonth = subMonth(currentTimeNow, userRecord.CreatedUnix.AsTime()) dateRecordAll.DataDate = DataDate - - if _, ok := CodeMergeCountMap[dateRecordAll.ID]; !ok { - dateRecordAll.CodeMergeCount = 0 - } else { - dateRecordAll.CodeMergeCount = CodeMergeCountMap[dateRecordAll.ID] - } - - if _, ok := CommitCountMap[dateRecordAll.ID]; !ok { - dateRecordAll.CommitCount = 0 - } else { - dateRecordAll.CommitCount = CommitCountMap[dateRecordAll.ID] - } - - if _, ok := IssueCountMap[dateRecordAll.ID]; !ok { - dateRecordAll.IssueCount = 0 - } else { - dateRecordAll.IssueCount = IssueCountMap[dateRecordAll.ID] - } - - if _, ok := CommentCountMap[dateRecordAll.ID]; !ok { - dateRecordAll.CommentCount = 0 - } else { - dateRecordAll.CommentCount = CommentCountMap[dateRecordAll.ID] - } - - if _, ok := FocusRepoCountMap[dateRecordAll.ID]; !ok { - dateRecordAll.FocusRepoCount = 0 - } else { - dateRecordAll.FocusRepoCount = FocusRepoCountMap[dateRecordAll.ID] - } - - if _, ok := StarRepoCountMap[dateRecordAll.ID]; !ok { - dateRecordAll.StarRepoCount = 0 - } else { - dateRecordAll.StarRepoCount = StarRepoCountMap[dateRecordAll.ID] - } - - if _, ok := WatchedCountMap[dateRecordAll.ID]; !ok { - dateRecordAll.WatchedCount = 0 - } else { - dateRecordAll.WatchedCount = WatchedCountMap[dateRecordAll.ID] - } - - if _, ok := CommitCodeSizeMap[dateRecordAll.ID]; !ok { - dateRecordAll.CommitCodeSize = 0 - } else { - dateRecordAll.CommitCodeSize = CommitCodeSizeMap[dateRecordAll.ID] - } - - if _, ok := CommitDatasetSizeMap[dateRecordAll.ID]; !ok { - dateRecordAll.CommitDatasetSize = 0 - } else { - dateRecordAll.CommitDatasetSize = CommitDatasetSizeMap[dateRecordAll.ID] - } - - if _, ok := SolveIssueCountMap[dateRecordAll.ID]; !ok { - dateRecordAll.SolveIssueCount = 0 - } else { - dateRecordAll.SolveIssueCount = SolveIssueCountMap[dateRecordAll.ID] - } - - if _, ok := wikiCountMap[dateRecordAll.Name]; !ok { - dateRecordAll.EncyclopediasCount = 0 - } else { - dateRecordAll.EncyclopediasCount = wikiCountMap[dateRecordAll.Name] - } - - if _, ok := CreateRepoCountMap[dateRecordAll.ID]; !ok { - dateRecordAll.CreateRepoCount = 0 - } else { - dateRecordAll.CreateRepoCount = CreateRepoCountMap[dateRecordAll.ID] - } - - if _, ok := LoginCountMap[dateRecordAll.ID]; !ok { - dateRecordAll.LoginCount = 0 - } else { - dateRecordAll.LoginCount = LoginCountMap[dateRecordAll.ID] - } + dateRecordAll.UserLocation = userRecord.Location + + dateRecordAll.CodeMergeCount = getMapValue(dateRecordAll.ID, CodeMergeCountMap) + dateRecordAll.CommitCount = getMapValue(dateRecordAll.ID, CommitCountMap) + dateRecordAll.IssueCount = getMapValue(dateRecordAll.ID, IssueCountMap) + dateRecordAll.CommentCount = getMapValue(dateRecordAll.ID, CommentCountMap) + dateRecordAll.FocusRepoCount = getMapValue(dateRecordAll.ID, FocusRepoCountMap) + dateRecordAll.StarRepoCount = getMapValue(dateRecordAll.ID, StarRepoCountMap) + dateRecordAll.WatchedCount = getMapValue(dateRecordAll.ID, WatchedCountMap) + dateRecordAll.CommitCodeSize = getMapValue(dateRecordAll.ID, CommitCodeSizeMap) + dateRecordAll.CommitDatasetSize = getMapValue(dateRecordAll.ID, CommitDatasetSizeMap) + dateRecordAll.CommitDatasetNum = getMapValue(dateRecordAll.ID, CommitDatasetNumMap) + dateRecordAll.SolveIssueCount = getMapValue(dateRecordAll.ID, SolveIssueCountMap) + dateRecordAll.EncyclopediasCount = getMapKeyStringValue(dateRecordAll.Name, wikiCountMap) + dateRecordAll.CreateRepoCount = getMapValue(dateRecordAll.ID, CreateRepoCountMap) + dateRecordAll.LoginCount = getMapValue(dateRecordAll.ID, LoginCountMap) if _, ok := OpenIIndexMap[dateRecordAll.ID]; !ok { dateRecordAll.OpenIIndex = 0 @@ -496,7 +461,15 @@ func refreshUserStaticTable(wikiCountMap map[string]int, tableName string, pageS dateRecordAll.OpenIIndex = OpenIIndexMap[dateRecordAll.ID] } - dateRecordAll.CommitModelCount = 0 + dateRecordAll.CloudBrainTaskNum = getMapValue(dateRecordAll.ID, CloudBrainTaskMap) + dateRecordAll.GpuDebugJob = getMapKeyStringValue(fmt.Sprint(dateRecordAll.ID)+"_GpuDebugJob", CloudBrainTaskItemMap) + dateRecordAll.NpuDebugJob = getMapKeyStringValue(fmt.Sprint(dateRecordAll.ID)+"_NpuDebugJob", CloudBrainTaskItemMap) + dateRecordAll.GpuTrainJob = getMapKeyStringValue(fmt.Sprint(dateRecordAll.ID)+"_GpuTrainJob", CloudBrainTaskItemMap) + dateRecordAll.NpuTrainJob = getMapKeyStringValue(fmt.Sprint(dateRecordAll.ID)+"_NpuTrainJob", CloudBrainTaskItemMap) + dateRecordAll.NpuInferenceJob = getMapKeyStringValue(fmt.Sprint(dateRecordAll.ID)+"_NpuInferenceJob", CloudBrainTaskItemMap) + dateRecordAll.GpuBenchMarkJob = getMapKeyStringValue(fmt.Sprint(dateRecordAll.ID)+"_GpuBenchMarkJob", CloudBrainTaskItemMap) + dateRecordAll.CommitModelCount = getMapValue(dateRecordAll.ID, AiModelManageMap) + //dateRecordAll.UserIndex = getUserIndex(dateRecordAll) dateRecordBatch = append(dateRecordBatch, dateRecordAll) if len(dateRecordBatch) >= BATCH_INSERT_SIZE { @@ -528,7 +501,7 @@ func insertTable(dateRecords []UserBusinessAnalysisAll, tableName string, static insertBatchSql := "INSERT INTO public." + tableName + "(id, count_date, code_merge_count, commit_count, issue_count, comment_count, focus_repo_count, star_repo_count, watched_count, gitea_age_month, commit_code_size, commit_dataset_size, " + - "commit_model_count, solve_issue_count, encyclopedias_count, regist_date, create_repo_count, login_count, open_i_index, email, name, data_date) " + + "commit_model_count, solve_issue_count, encyclopedias_count, regist_date, create_repo_count, login_count, open_i_index, email, name, data_date,cloud_brain_task_num,gpu_debug_job,npu_debug_job,gpu_train_job,npu_train_job,npu_inference_job,gpu_bench_mark_job,cloud_brain_run_time,commit_dataset_num,user_index,user_location) " + "VALUES" for i, record := range dateRecords { @@ -536,7 +509,7 @@ func insertTable(dateRecords []UserBusinessAnalysisAll, tableName string, static ", " + fmt.Sprint(record.IssueCount) + ", " + fmt.Sprint(record.CommentCount) + ", " + fmt.Sprint(record.FocusRepoCount) + ", " + fmt.Sprint(record.StarRepoCount) + ", " + fmt.Sprint(record.WatchedCount) + ", " + fmt.Sprint(record.GiteaAgeMonth) + ", " + fmt.Sprint(record.CommitCodeSize) + ", " + fmt.Sprint(record.CommitDatasetSize) + ", " + fmt.Sprint(record.CommitModelCount) + ", " + fmt.Sprint(record.SolveIssueCount) + ", " + fmt.Sprint(record.EncyclopediasCount) + ", " + fmt.Sprint(record.RegistDate) + - ", " + fmt.Sprint(record.CreateRepoCount) + ", " + fmt.Sprint(record.LoginCount) + ", " + fmt.Sprint(record.OpenIIndex) + ", '" + record.Email + "', '" + record.Name + "', '" + record.DataDate + "')" + ", " + fmt.Sprint(record.CreateRepoCount) + ", " + fmt.Sprint(record.LoginCount) + ", " + fmt.Sprint(record.OpenIIndex) + ", '" + record.Email + "', '" + record.Name + "', '" + record.DataDate + "'," + fmt.Sprint(record.CloudBrainTaskNum) + "," + fmt.Sprint(record.GpuDebugJob) + "," + fmt.Sprint(record.NpuDebugJob) + "," + fmt.Sprint(record.GpuTrainJob) + "," + fmt.Sprint(record.NpuTrainJob) + "," + fmt.Sprint(record.NpuInferenceJob) + "," + fmt.Sprint(record.GpuBenchMarkJob) + "," + fmt.Sprint(record.CloudBrainRunTime) + "," + fmt.Sprint(record.CommitDatasetNum) + "," + fmt.Sprint(record.UserIndex) + ",'" + record.UserLocation + "')" if i < (len(dateRecords) - 1) { insertBatchSql += "," } @@ -612,12 +585,13 @@ func CounDataByDateAndReCount(wikiCountMap map[string]int, startTime time.Time, } else { log.Info("query commit code size, len=" + fmt.Sprint(len(CommitCodeSizeMap))) } - CommitDatasetSizeMap := queryDatasetSize(start_unix, end_unix) + CommitDatasetSizeMap, CommitDatasetNumMap := queryDatasetSize(start_unix, end_unix) SolveIssueCountMap := querySolveIssue(start_unix, end_unix) CreateRepoCountMap := queryUserCreateRepo(start_unix, end_unix) LoginCountMap := queryLoginCount(start_unix, end_unix) OpenIIndexMap := queryUserRepoOpenIIndex(start_unix, end_unix) - + CloudBrainTaskMap, CloudBrainTaskItemMap := queryCloudBrainTask(start_unix, end_unix) + AiModelManageMap := queryUserModel(start_unix, end_unix) statictisSess := xStatistic.NewSession() defer statictisSess.Close() @@ -647,47 +621,14 @@ func CounDataByDateAndReCount(wikiCountMap map[string]int, startTime time.Time, dateRecord.Name = userRecord.Name dateRecord.GiteaAgeMonth = subMonth(currentTimeNow, userRecord.CreatedUnix.AsTime()) dateRecord.DataDate = DataDate - if _, ok := CodeMergeCountMap[dateRecord.ID]; !ok { - dateRecord.CodeMergeCount = 0 - } else { - dateRecord.CodeMergeCount = CodeMergeCountMap[dateRecord.ID] - } - if _, ok := CommitCountMap[dateRecord.ID]; !ok { - dateRecord.CommitCount = 0 - } else { - dateRecord.CommitCount = CommitCountMap[dateRecord.ID] - } - - if _, ok := IssueCountMap[dateRecord.ID]; !ok { - dateRecord.IssueCount = 0 - } else { - dateRecord.IssueCount = IssueCountMap[dateRecord.ID] - } - - if _, ok := CommentCountMap[dateRecord.ID]; !ok { - dateRecord.CommentCount = 0 - } else { - dateRecord.CommentCount = CommentCountMap[dateRecord.ID] - } - - if _, ok := FocusRepoCountMap[dateRecord.ID]; !ok { - dateRecord.FocusRepoCount = 0 - } else { - dateRecord.FocusRepoCount = FocusRepoCountMap[dateRecord.ID] - } - - if _, ok := StarRepoCountMap[dateRecord.ID]; !ok { - dateRecord.StarRepoCount = 0 - } else { - dateRecord.StarRepoCount = StarRepoCountMap[dateRecord.ID] - } - - if _, ok := WatchedCountMap[dateRecord.ID]; !ok { - dateRecord.WatchedCount = 0 - } else { - dateRecord.WatchedCount = WatchedCountMap[dateRecord.ID] - } + dateRecord.CodeMergeCount = getMapValue(dateRecord.ID, CodeMergeCountMap) + dateRecord.CommitCount = getMapValue(dateRecord.ID, CommitCountMap) + dateRecord.IssueCount = getMapValue(dateRecord.ID, IssueCountMap) + dateRecord.CommentCount = getMapValue(dateRecord.ID, CommentCountMap) + dateRecord.FocusRepoCount = getMapValue(dateRecord.ID, FocusRepoCountMap) + dateRecord.StarRepoCount = getMapValue(dateRecord.ID, StarRepoCountMap) + dateRecord.WatchedCount = getMapValue(dateRecord.ID, WatchedCountMap) if _, ok := CommitCodeSizeMap[dateRecord.Email]; !ok { dateRecord.CommitCodeSize = 0 @@ -695,35 +636,15 @@ func CounDataByDateAndReCount(wikiCountMap map[string]int, startTime time.Time, dateRecord.CommitCodeSize = int(CommitCodeSizeMap[dateRecord.Email].CommitLines) } - if _, ok := CommitDatasetSizeMap[dateRecord.ID]; !ok { - dateRecord.CommitDatasetSize = 0 - } else { - dateRecord.CommitDatasetSize = CommitDatasetSizeMap[dateRecord.ID] - } - - if _, ok := SolveIssueCountMap[dateRecord.ID]; !ok { - dateRecord.SolveIssueCount = 0 - } else { - dateRecord.SolveIssueCount = SolveIssueCountMap[dateRecord.ID] - } + dateRecord.CommitDatasetSize = getMapValue(dateRecord.ID, CommitDatasetSizeMap) + dateRecord.CommitDatasetNum = getMapValue(dateRecord.ID, CommitDatasetNumMap) + dateRecord.SolveIssueCount = getMapValue(dateRecord.ID, SolveIssueCountMap) - if _, ok := wikiCountMap[dateRecord.Name]; !ok { - dateRecord.EncyclopediasCount = 0 - } else { - dateRecord.EncyclopediasCount = wikiCountMap[dateRecord.Name] - } + dateRecord.EncyclopediasCount = getMapKeyStringValue(dateRecord.Name, wikiCountMap) - if _, ok := CreateRepoCountMap[dateRecord.ID]; !ok { - dateRecord.CreateRepoCount = 0 - } else { - dateRecord.CreateRepoCount = CreateRepoCountMap[dateRecord.ID] - } + dateRecord.CreateRepoCount = getMapValue(dateRecord.ID, CreateRepoCountMap) - if _, ok := LoginCountMap[dateRecord.ID]; !ok { - dateRecord.LoginCount = 0 - } else { - dateRecord.LoginCount = LoginCountMap[dateRecord.ID] - } + dateRecord.LoginCount = getMapValue(dateRecord.ID, LoginCountMap) if _, ok := OpenIIndexMap[dateRecord.ID]; !ok { dateRecord.OpenIIndex = 0 @@ -731,7 +652,16 @@ func CounDataByDateAndReCount(wikiCountMap map[string]int, startTime time.Time, dateRecord.OpenIIndex = OpenIIndexMap[dateRecord.ID] } - dateRecord.CommitModelCount = 0 + dateRecord.CloudBrainTaskNum = getMapValue(dateRecord.ID, CloudBrainTaskMap) + dateRecord.GpuDebugJob = getMapKeyStringValue(fmt.Sprint(dateRecord.ID)+"_GpuDebugJob", CloudBrainTaskItemMap) + dateRecord.NpuDebugJob = getMapKeyStringValue(fmt.Sprint(dateRecord.ID)+"_NpuDebugJob", CloudBrainTaskItemMap) + dateRecord.GpuTrainJob = getMapKeyStringValue(fmt.Sprint(dateRecord.ID)+"_GpuTrainJob", CloudBrainTaskItemMap) + dateRecord.NpuTrainJob = getMapKeyStringValue(fmt.Sprint(dateRecord.ID)+"_NpuTrainJob", CloudBrainTaskItemMap) + dateRecord.NpuInferenceJob = getMapKeyStringValue(fmt.Sprint(dateRecord.ID)+"_NpuInferenceJob", CloudBrainTaskItemMap) + dateRecord.GpuBenchMarkJob = getMapKeyStringValue(fmt.Sprint(dateRecord.ID)+"_GpuBenchMarkJob", CloudBrainTaskItemMap) + + dateRecord.CommitModelCount = getMapValue(dateRecord.ID, AiModelManageMap) + dateRecord.UserIndex = getUserIndex(dateRecord) _, err = statictisSess.Insert(&dateRecord) if err != nil { @@ -751,6 +681,27 @@ func CounDataByDateAndReCount(wikiCountMap map[string]int, startTime time.Time, return nil } +func getUserIndex(dateRecord UserBusinessAnalysis) float64 { + + return 0 +} + +func getMapKeyStringValue(key string, valueMap map[string]int) int { + if _, ok := valueMap[key]; !ok { + return 0 + } else { + return valueMap[key] + } +} + +func getMapValue(userId int64, valueMap map[int64]int) int { + if _, ok := valueMap[userId]; !ok { + return 0 + } else { + return valueMap[userId] + } +} + func getInt(str string) int { re, err := strconv.ParseInt(str, 10, 32) if err != nil { @@ -1051,16 +1002,17 @@ func queryFollow(start_unix int64, end_unix int64) map[int64]int { return resultMap } -func queryDatasetSize(start_unix int64, end_unix int64) map[int64]int { +func queryDatasetSize(start_unix int64, end_unix int64) (map[int64]int, map[int64]int) { sess := x.NewSession() defer sess.Close() - resultMap := make(map[int64]int) + resultSizeMap := make(map[int64]int) + resultNumMap := make(map[int64]int) cond := " created_unix>=" + fmt.Sprint(start_unix) + " and created_unix<=" + fmt.Sprint(end_unix) count, err := sess.Where(cond).Count(new(Attachment)) if err != nil { log.Info("query attachment error. return.") - return resultMap + return resultSizeMap, resultNumMap } var indexTotal int64 indexTotal = 0 @@ -1071,10 +1023,12 @@ func queryDatasetSize(start_unix int64, end_unix int64) map[int64]int { log.Info("query Attachment size=" + fmt.Sprint(len(attachmentList))) for _, attachRecord := range attachmentList { - if _, ok := resultMap[attachRecord.UploaderID]; !ok { - resultMap[attachRecord.UploaderID] = int(attachRecord.Size / (1024 * 1024)) //MB + if _, ok := resultSizeMap[attachRecord.UploaderID]; !ok { + resultSizeMap[attachRecord.UploaderID] = int(attachRecord.Size / (1024 * 1024)) //MB + resultNumMap[attachRecord.UploaderID] = 1 } else { - resultMap[attachRecord.UploaderID] += int(attachRecord.Size / (1024 * 1024)) //MB + resultSizeMap[attachRecord.UploaderID] += int(attachRecord.Size / (1024 * 1024)) //MB + resultNumMap[attachRecord.UploaderID] += 1 } } @@ -1084,7 +1038,7 @@ func queryDatasetSize(start_unix int64, end_unix int64) map[int64]int { } } - return resultMap + return resultSizeMap, resultNumMap } func queryUserCreateRepo(start_unix int64, end_unix int64) map[int64]int { @@ -1245,6 +1199,99 @@ func queryCommitCodeSize(start_unix int64, end_unix int64) map[int64]int { return resultMap } +func queryUserModel(start_unix int64, end_unix int64) map[int64]int { + sess := x.NewSession() + defer sess.Close() + resultMap := make(map[int64]int) + cond := " created_unix>=" + fmt.Sprint(start_unix) + " and created_unix<=" + fmt.Sprint(end_unix) + count, err := sess.Where(cond).Count(new(AiModelManage)) + if err != nil { + log.Info("query AiModelManage error. return.") + return resultMap + } + var indexTotal int64 + indexTotal = 0 + for { + sess.Select("id,user_id").Table("ai_model_manage").Where(cond).OrderBy("id asc").Limit(PAGE_SIZE, int(indexTotal)) + aiModelList := make([]*AiModelManage, 0) + sess.Find(&aiModelList) + log.Info("query AiModelManage size=" + fmt.Sprint(len(aiModelList))) + for _, aiModelRecord := range aiModelList { + if _, ok := resultMap[aiModelRecord.UserId]; !ok { + resultMap[aiModelRecord.UserId] = 1 + } else { + resultMap[aiModelRecord.UserId] += 1 + } + } + indexTotal += PAGE_SIZE + if indexTotal >= count { + break + } + } + return resultMap +} + +func queryCloudBrainTask(start_unix int64, end_unix int64) (map[int64]int, map[string]int) { + sess := x.NewSession() + defer sess.Close() + resultMap := make(map[int64]int) + resultItemMap := make(map[string]int) + + cond := " created_unix>=" + fmt.Sprint(start_unix) + " and created_unix<=" + fmt.Sprint(end_unix) + count, err := sess.Where(cond).Count(new(Cloudbrain)) + if err != nil { + log.Info("query cloudbrain error. return.") + return resultMap, resultItemMap + } + var indexTotal int64 + indexTotal = 0 + for { + sess.Select("id,job_type,user_id,duration,train_job_duration,type").Table("cloudbrain").Where(cond).OrderBy("id asc").Limit(PAGE_SIZE, int(indexTotal)) + cloudTaskList := make([]*Cloudbrain, 0) + sess.Find(&cloudTaskList) + log.Info("query cloudbrain size=" + fmt.Sprint(len(cloudTaskList))) + for _, cloudTaskRecord := range cloudTaskList { + if _, ok := resultMap[cloudTaskRecord.UserID]; !ok { + resultMap[cloudTaskRecord.UserID] = 1 + } else { + resultMap[cloudTaskRecord.UserID] += 1 + } + setMapKey("time", cloudTaskRecord.UserID, int(cloudTaskRecord.Duration), resultItemMap) + if cloudTaskRecord.Type == 1 { //npu + if cloudTaskRecord.JobType == "TRAIN" { + setMapKey("NpuTrainJob", cloudTaskRecord.UserID, 1, resultItemMap) + } else if cloudTaskRecord.JobType == "INFERENCE" { + setMapKey("NpuInferenceJob", cloudTaskRecord.UserID, 1, resultItemMap) + } else { + setMapKey("NpuDebugJob", cloudTaskRecord.UserID, 1, resultItemMap) + } + } else { //type=0 gpu + if cloudTaskRecord.JobType == "TRAIN" { + setMapKey("GpuTrainJob", cloudTaskRecord.UserID, 1, resultItemMap) + } else if cloudTaskRecord.JobType == "BENCHMARK" { + setMapKey("GpuBenchMarkJob", cloudTaskRecord.UserID, 1, resultItemMap) + } else { + setMapKey("GpuDebugJob", cloudTaskRecord.UserID, 1, resultItemMap) + } + } + } + indexTotal += PAGE_SIZE + if indexTotal >= count { + break + } + } + + return resultMap, resultItemMap +} +func setMapKey(key string, userId int64, value int, resultItemMap map[string]int) { + newKey := fmt.Sprint(userId) + "_" + key + if _, ok := resultItemMap[newKey]; !ok { + resultItemMap[newKey] = value + } else { + resultItemMap[newKey] += value + } +} + func subMonth(t1, t2 time.Time) (month int) { y1 := t1.Year() y2 := t2.Year() diff --git a/models/user_business_struct.go b/models/user_business_struct.go index c435c0b07..066e11314 100644 --- a/models/user_business_struct.go +++ b/models/user_business_struct.go @@ -44,6 +44,18 @@ type UserBusinessAnalysisCurrentYear struct { //user Name string `xorm:"NOT NULL"` DataDate string `xorm:"NULL"` + + CloudBrainTaskNum int `xorm:"NOT NULL DEFAULT 0"` + GpuDebugJob int `xorm:"NOT NULL DEFAULT 0"` + NpuDebugJob int `xorm:"NOT NULL DEFAULT 0"` + GpuTrainJob int `xorm:"NOT NULL DEFAULT 0"` + NpuTrainJob int `xorm:"NOT NULL DEFAULT 0"` + NpuInferenceJob int `xorm:"NOT NULL DEFAULT 0"` + GpuBenchMarkJob int `xorm:"NOT NULL DEFAULT 0"` + CloudBrainRunTime int `xorm:"NOT NULL DEFAULT 0"` + CommitDatasetNum int `xorm:"NOT NULL DEFAULT 0"` + UserIndex float64 `xorm:"NOT NULL DEFAULT 0"` + UserLocation string `xorm:"NULL"` } type UserBusinessAnalysisLast30Day struct { @@ -88,6 +100,18 @@ type UserBusinessAnalysisLast30Day struct { //user Name string `xorm:"NOT NULL"` DataDate string `xorm:"NULL"` + + CloudBrainTaskNum int `xorm:"NOT NULL DEFAULT 0"` + GpuDebugJob int `xorm:"NOT NULL DEFAULT 0"` + NpuDebugJob int `xorm:"NOT NULL DEFAULT 0"` + GpuTrainJob int `xorm:"NOT NULL DEFAULT 0"` + NpuTrainJob int `xorm:"NOT NULL DEFAULT 0"` + NpuInferenceJob int `xorm:"NOT NULL DEFAULT 0"` + GpuBenchMarkJob int `xorm:"NOT NULL DEFAULT 0"` + CloudBrainRunTime int `xorm:"NOT NULL DEFAULT 0"` + CommitDatasetNum int `xorm:"NOT NULL DEFAULT 0"` + UserIndex float64 `xorm:"NOT NULL DEFAULT 0"` + UserLocation string `xorm:"NULL"` } type UserBusinessAnalysisLastMonth struct { @@ -132,6 +156,18 @@ type UserBusinessAnalysisLastMonth struct { //user Name string `xorm:"NOT NULL"` DataDate string `xorm:"NULL"` + + CloudBrainTaskNum int `xorm:"NOT NULL DEFAULT 0"` + GpuDebugJob int `xorm:"NOT NULL DEFAULT 0"` + NpuDebugJob int `xorm:"NOT NULL DEFAULT 0"` + GpuTrainJob int `xorm:"NOT NULL DEFAULT 0"` + NpuTrainJob int `xorm:"NOT NULL DEFAULT 0"` + NpuInferenceJob int `xorm:"NOT NULL DEFAULT 0"` + GpuBenchMarkJob int `xorm:"NOT NULL DEFAULT 0"` + CloudBrainRunTime int `xorm:"NOT NULL DEFAULT 0"` + CommitDatasetNum int `xorm:"NOT NULL DEFAULT 0"` + UserIndex float64 `xorm:"NOT NULL DEFAULT 0"` + UserLocation string `xorm:"NULL"` } type UserBusinessAnalysisCurrentMonth struct { @@ -176,6 +212,18 @@ type UserBusinessAnalysisCurrentMonth struct { //user Name string `xorm:"NOT NULL"` DataDate string `xorm:"NULL"` + + CloudBrainTaskNum int `xorm:"NOT NULL DEFAULT 0"` + GpuDebugJob int `xorm:"NOT NULL DEFAULT 0"` + NpuDebugJob int `xorm:"NOT NULL DEFAULT 0"` + GpuTrainJob int `xorm:"NOT NULL DEFAULT 0"` + NpuTrainJob int `xorm:"NOT NULL DEFAULT 0"` + NpuInferenceJob int `xorm:"NOT NULL DEFAULT 0"` + GpuBenchMarkJob int `xorm:"NOT NULL DEFAULT 0"` + CloudBrainRunTime int `xorm:"NOT NULL DEFAULT 0"` + CommitDatasetNum int `xorm:"NOT NULL DEFAULT 0"` + UserIndex float64 `xorm:"NOT NULL DEFAULT 0"` + UserLocation string `xorm:"NULL"` } type UserBusinessAnalysisCurrentWeek struct { @@ -220,6 +268,18 @@ type UserBusinessAnalysisCurrentWeek struct { //user Name string `xorm:"NOT NULL"` DataDate string `xorm:"NULL"` + + CloudBrainTaskNum int `xorm:"NOT NULL DEFAULT 0"` + GpuDebugJob int `xorm:"NOT NULL DEFAULT 0"` + NpuDebugJob int `xorm:"NOT NULL DEFAULT 0"` + GpuTrainJob int `xorm:"NOT NULL DEFAULT 0"` + NpuTrainJob int `xorm:"NOT NULL DEFAULT 0"` + NpuInferenceJob int `xorm:"NOT NULL DEFAULT 0"` + GpuBenchMarkJob int `xorm:"NOT NULL DEFAULT 0"` + CloudBrainRunTime int `xorm:"NOT NULL DEFAULT 0"` + CommitDatasetNum int `xorm:"NOT NULL DEFAULT 0"` + UserIndex float64 `xorm:"NOT NULL DEFAULT 0"` + UserLocation string `xorm:"NULL"` } type UserBusinessAnalysisYesterday struct { @@ -264,4 +324,16 @@ type UserBusinessAnalysisYesterday struct { //user Name string `xorm:"NOT NULL"` DataDate string `xorm:"NULL"` + + CloudBrainTaskNum int `xorm:"NOT NULL DEFAULT 0"` + GpuDebugJob int `xorm:"NOT NULL DEFAULT 0"` + NpuDebugJob int `xorm:"NOT NULL DEFAULT 0"` + GpuTrainJob int `xorm:"NOT NULL DEFAULT 0"` + NpuTrainJob int `xorm:"NOT NULL DEFAULT 0"` + NpuInferenceJob int `xorm:"NOT NULL DEFAULT 0"` + GpuBenchMarkJob int `xorm:"NOT NULL DEFAULT 0"` + CloudBrainRunTime int `xorm:"NOT NULL DEFAULT 0"` + CommitDatasetNum int `xorm:"NOT NULL DEFAULT 0"` + UserIndex float64 `xorm:"NOT NULL DEFAULT 0"` + UserLocation string `xorm:"NULL"` } From 491de2004c253c6422108a43f8d08faa38b2d91c Mon Sep 17 00:00:00 2001 From: yanchao Date: Sun, 20 Mar 2022 11:33:21 +0800 Subject: [PATCH 003/256] =?UTF-8?q?=E7=BB=84=E7=BB=87=E5=B9=BF=E5=9C=BA?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/models.go | 1 + models/org.go | 99 +++++++++++++++++++++++++++++++++++++ models/repo_statistic.go | 10 ++++ modules/cron/tasks_basic.go | 12 +++++ routers/home.go | 39 +++++++++++---- routers/private/internal.go | 2 + routers/private/tool.go | 4 ++ 7 files changed, 158 insertions(+), 9 deletions(-) diff --git a/models/models.go b/models/models.go index 0f4679b4f..fafb63018 100755 --- a/models/models.go +++ b/models/models.go @@ -137,6 +137,7 @@ func init() { new(OfficialTag), new(OfficialTagRepos), new(WechatBindLog), + new(OrgStatistic), ) tablesStatistic = append(tablesStatistic, diff --git a/models/org.go b/models/org.go index 85fb157ae..8b3e60ef8 100755 --- a/models/org.go +++ b/models/org.go @@ -8,6 +8,7 @@ package models import ( "fmt" "os" + "strconv" "strings" "code.gitea.io/gitea/modules/log" @@ -19,6 +20,17 @@ import ( "xorm.io/xorm" ) +type OrgStatistic struct { + ID int64 `xorm:"pk autoincr"` + OrgID int64 `xorm:"UNIQUE"` + NumScore int `xorm:"INDEX NOT NULL DEFAULT 0"` +} + +type OrgScore struct { + *User + Score string +} + // IsOwnedBy returns true if given user is in the owner team. func (org *User) IsOwnedBy(uid int64) (bool, error) { return IsOrganizationOwner(org.ID, uid) @@ -135,6 +147,93 @@ func (org *User) RemoveOrgRepo(repoID int64) error { return org.removeOrgRepo(x, repoID) } +func UpdateOrgStatistics() { + ids, err := GetOrganizationsId() + if err != nil { + return + } + for _, id := range ids { + org := User{ID: id} + orgStat := &OrgStatistic{OrgID: id} + numScore, err := org.getOrgStatistics() + if err == nil { + has, _ := x.Get(orgStat) + + orgStat.NumScore = numScore + if has { + x.ID(orgStat.ID).Cols("num_score").Update(&orgStat) + } else { + x.Insert(orgStat) + } + + } + } + +} + +func (org *User) getOrgStatistics() (int, error) { + count, err := getRepositoryCount(x, org) + if err != nil { + return 0, err + } + + err = org.GetRepositories(ListOptions{int(count), 1}) + + if err != nil { + return 0, err + } + var numScore = 0 + for _, repo := range org.Repos { + + numScore += int(getOpenIByRepoId(repo.ID)) + } + + return numScore, nil + +} + +func FindTopNStarsOrgs(n int) ([]*OrgScore, error) { + sql := "select a.id,sum(b.num_stars) score from \"user\" a ,repository b where a.id=b.owner_id and a.type=1 group by a.id order by score desc limit " + strconv.Itoa(n) + + return findTopNOrgs(sql) +} +func FindTopNMembersOrgs(n int) ([]*OrgScore, error) { + sql := "select id, count(user_id) score from" + + " (select org_id as id, uid as user_id from org_user " + + "union select a.id,b.user_id from \"user\" a,collaboration b,repository c " + + "where a.type=1 and a.id=c.owner_id and b.repo_id=c.id) d " + + "group by id order by score desc limit " + strconv.Itoa(n) + + return findTopNOrgs(sql) +} + +func FindTopNOpenIOrgs(n int) ([]*OrgScore, error) { + sql := "select org_id id,num_score score from org_statistic order by num_score desc limit 10" + strconv.Itoa(n) + + return findTopNOrgs(sql) +} + +func findTopNOrgs(sql string) ([]*OrgScore, error) { + resutls, err := x.QueryString(sql) + + if err != nil { + return nil, err + } + var orgScore []*OrgScore + for _, record := range resutls { + id, _ := strconv.ParseInt(record["id"], 10, 64) + user, err := getUserByID(x, id) + if err != nil { + continue + } + orgScore = append(orgScore, &OrgScore{user, record["score"]}) + + } + + return orgScore, nil + +} + // CreateOrganization creates record of a new organization. func CreateOrganization(org, owner *User) (err error) { if !owner.CanCreateOrganization() { diff --git a/models/repo_statistic.go b/models/repo_statistic.go index a9e9593af..4f8f13ed7 100755 --- a/models/repo_statistic.go +++ b/models/repo_statistic.go @@ -73,6 +73,16 @@ func (repo *RepoStatistic) DisplayName() string { return repo.Alias } +func getOpenIByRepoId(repoId int64) float64 { + repoStatistic := new(RepoStatistic) + has, err := xStatistic.Cols("radar_total").Where("repo_id=?", repoId).Desc("id").Limit(1).Get(repoStatistic) + if !has || err != nil { + return 0 + } + return repoStatistic.RadarTotal + +} + func DeleteRepoStatDaily(date string) error { sess := xStatistic.NewSession() defer sess.Close() diff --git a/modules/cron/tasks_basic.go b/modules/cron/tasks_basic.go index b9838e66f..b3a6c02a1 100755 --- a/modules/cron/tasks_basic.go +++ b/modules/cron/tasks_basic.go @@ -185,6 +185,17 @@ func registerHandleSummaryStatistic() { }) } +func registerHandleOrgStatistic() { + RegisterTaskFatal("handle_org_statistic", &BaseConfig{ + Enabled: true, + RunAtStart: false, + Schedule: "0 0 2 * * ?", + }, func(ctx context.Context, _ *models.User, _ Config) error { + models.UpdateOrgStatistics() + return nil + }) +} + func registerSyncCloudbrainStatus() { RegisterTaskFatal("sync_cloudbrain_status", &BaseConfig{ Enabled: true, @@ -215,4 +226,5 @@ func initBasicTasks() { registerHandleSummaryStatistic() registerSyncCloudbrainStatus() + registerHandleOrgStatistic() } diff --git a/routers/home.go b/routers/home.go index 2db8d2112..a9f05067b 100755 --- a/routers/home.go +++ b/routers/home.go @@ -418,17 +418,38 @@ func ExploreOrganizations(ctx *context.Context) { ctx.Data["PageIsExploreOrganizations"] = true ctx.Data["IsRepoIndexerEnabled"] = setting.Indexer.RepoIndexerEnabled - visibleTypes := []structs.VisibleType{structs.VisibleTypePublic} - if ctx.User != nil { - visibleTypes = append(visibleTypes, structs.VisibleTypeLimited, structs.VisibleTypePrivate) + N := 10 + starInfo, err := models.FindTopNStarsOrgs(N) + if err != nil { + log.Error("GetStarOrgInfos failed:%v", err.Error(), ctx.Data["MsgID"]) + ctx.ServerError("GetStarOrgInfos", err) + return + } + memberInfo, err := models.FindTopNMembersOrgs(N) + if err != nil { + log.Error("GetMemberOrgInfos failed:%v", err.Error(), ctx.Data["MsgID"]) + ctx.ServerError("GetMemberOrgInfos", err) + return + } + openIInfo, err := models.FindTopNOpenIOrgs(N) + if err != nil { + log.Error("GetOpenIOrgInfos failed:%v", err.Error(), ctx.Data["MsgID"]) + ctx.ServerError("GetOpenIOrgInfos", err) + return } - RenderUserSearch(ctx, &models.SearchUserOptions{ - Actor: ctx.User, - Type: models.UserTypeOrganization, - ListOptions: models.ListOptions{PageSize: setting.UI.ExplorePagingNum}, - Visible: visibleTypes, - }, tplExploreOrganizations) + recommendOrgs, err := models.GetRecommendOrgInfos() + if err != nil { + log.Error("GetRecommendOrgInfos failed:%v", err.Error(), ctx.Data["MsgID"]) + ctx.ServerError("GetRecommendOrgInfos", err) + return + } + ctx.Data["RecommendOrgs"] = recommendOrgs + ctx.Data["StarOrgs"] = starInfo + ctx.Data["MemberOrgs"] = memberInfo + ctx.Data["ActiveOrgs"] = openIInfo + + ctx.HTML(http.StatusOK, tplExploreOrganizations) } // ExploreCode render explore code page diff --git a/routers/private/internal.go b/routers/private/internal.go index 0dd725ca3..18dad5537 100755 --- a/routers/private/internal.go +++ b/routers/private/internal.go @@ -44,6 +44,8 @@ func RegisterRoutes(m *macaron.Macaron) { m.Post("/manager/flush-queues", bind(private.FlushOptions{}), FlushQueues) m.Post("/tool/update_all_repo_commit_cnt", UpdateAllRepoCommitCnt) m.Post("/tool/repo_stat/:date", RepoStatisticManually) + + m.Get("/tool/org_stat", OrgStatisticManually) m.Post("/tool/update_repo_visit/:date", UpdateRepoVisit) }, CheckInternalToken) diff --git a/routers/private/tool.go b/routers/private/tool.go index d01c5b2ab..122a41afe 100755 --- a/routers/private/tool.go +++ b/routers/private/tool.go @@ -45,6 +45,10 @@ func RepoStatisticManually(ctx *macaron.Context) { repo.TimingCountDataByDate(date) } +func OrgStatisticManually() { + models.UpdateOrgStatistics() +} + func UpdateRepoVisit(ctx *macaron.Context) { date := ctx.Params("date") log.Info("date(%s)", date) From 478dc4c59d3f364a19cfb8b25b44bf3393224d40 Mon Sep 17 00:00:00 2001 From: ychao_1983 Date: Mon, 21 Mar 2022 09:19:36 +0800 Subject: [PATCH 004/256] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/user.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/models/user.go b/models/user.go index f7857248b..a181a4d72 100755 --- a/models/user.go +++ b/models/user.go @@ -2103,6 +2103,12 @@ func GetOrganizationsCount() (int64, error) { } +func GetOrganizationsId() ([]int64, error) { + var ids []int64 + err := x.Table("user").Where("type=1").Cols("id").Find(&ids) + return ids, err +} + func GetBlockChainUnSuccessUsers() ([]*User, error) { users := make([]*User, 0, 10) err := x.Where("public_key = ''"). From ccb70b0c4a021b94b0026c3cc31f60b0f9127094 Mon Sep 17 00:00:00 2001 From: ychao_1983 Date: Tue, 22 Mar 2022 10:13:03 +0800 Subject: [PATCH 005/256] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8E=A8=E8=8D=90?= =?UTF-8?q?=E7=BB=84=E7=BB=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routers/home.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/routers/home.go b/routers/home.go index a9f05067b..8ce709c6d 100755 --- a/routers/home.go +++ b/routers/home.go @@ -438,7 +438,7 @@ func ExploreOrganizations(ctx *context.Context) { return } - recommendOrgs, err := models.GetRecommendOrgInfos() + recommendOrgs, err := GetRecommendOrg() if err != nil { log.Error("GetRecommendOrgInfos failed:%v", err.Error(), ctx.Data["MsgID"]) ctx.ServerError("GetRecommendOrgInfos", err) @@ -581,12 +581,12 @@ func NotFound(ctx *context.Context) { ctx.NotFound("home.NotFound", nil) } -func RecommendOrgFromPromote(ctx *context.Context) { +func GetRecommendOrg() ([]map[string]interface{}, error) { url := setting.RecommentRepoAddr + "organizations" result, err := repository.RecommendFromPromote(url) + if err != nil { - ctx.ServerError("500", err) - return + return nil, err } resultOrg := make([]map[string]interface{}, 0) for _, userName := range result { @@ -606,7 +606,15 @@ func RecommendOrgFromPromote(ctx *context.Context) { log.Info("query user error," + err.Error()) } } + return resultOrg, nil +} +func RecommendOrgFromPromote(ctx *context.Context) { + resultOrg, err := GetRecommendOrg() + if err != nil { + ctx.ServerError("500", err) + return + } ctx.JSON(200, resultOrg) } From 3b6e6e5f36392fa807d22d2b1f3a04e8e3902562 Mon Sep 17 00:00:00 2001 From: ychao_1983 Date: Tue, 22 Mar 2022 11:08:05 +0800 Subject: [PATCH 006/256] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routers/home.go | 1 + 1 file changed, 1 insertion(+) diff --git a/routers/home.go b/routers/home.go index 8ce709c6d..aeb67b638 100755 --- a/routers/home.go +++ b/routers/home.go @@ -596,6 +596,7 @@ func GetRecommendOrg() ([]map[string]interface{}, error) { userMap["Name"] = user.Name userMap["Description"] = user.Description userMap["FullName"] = user.FullName + userMap["HomeLink"] = user.HomeLink() userMap["ID"] = user.ID userMap["Avatar"] = user.RelAvatarLink() userMap["NumRepos"] = user.NumRepos From 0e3c44921daf56e0b1b40f6db2359e330231e624 Mon Sep 17 00:00:00 2001 From: zouap Date: Tue, 22 Mar 2022 16:31:12 +0800 Subject: [PATCH 007/256] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- models/user_business_analysis.go | 86 ++++++++++++++++++++++++++++++-- models/user_business_struct.go | 5 ++ 2 files changed, 87 insertions(+), 4 deletions(-) diff --git a/models/user_business_analysis.go b/models/user_business_analysis.go index e059ef3e4..04c0eb5f0 100644 --- a/models/user_business_analysis.go +++ b/models/user_business_analysis.go @@ -421,6 +421,7 @@ func refreshUserStaticTable(wikiCountMap map[string]int, tableName string, pageS log.Info("query user error. return.") return } + ParaWeight := getParaWeight() var indexTotal int64 indexTotal = 0 insertCount := 0 @@ -469,7 +470,7 @@ func refreshUserStaticTable(wikiCountMap map[string]int, tableName string, pageS dateRecordAll.NpuInferenceJob = getMapKeyStringValue(fmt.Sprint(dateRecordAll.ID)+"_NpuInferenceJob", CloudBrainTaskItemMap) dateRecordAll.GpuBenchMarkJob = getMapKeyStringValue(fmt.Sprint(dateRecordAll.ID)+"_GpuBenchMarkJob", CloudBrainTaskItemMap) dateRecordAll.CommitModelCount = getMapValue(dateRecordAll.ID, AiModelManageMap) - //dateRecordAll.UserIndex = getUserIndex(dateRecordAll) + dateRecordAll.UserIndex = getUserIndexFromAnalysisAll(dateRecordAll, ParaWeight) dateRecordBatch = append(dateRecordBatch, dateRecordAll) if len(dateRecordBatch) >= BATCH_INSERT_SIZE { @@ -601,6 +602,9 @@ func CounDataByDateAndReCount(wikiCountMap map[string]int, startTime time.Time, log.Info("query user error. return.") return err } + + ParaWeight := getParaWeight() + var indexTotal int64 indexTotal = 0 for { @@ -661,7 +665,7 @@ func CounDataByDateAndReCount(wikiCountMap map[string]int, startTime time.Time, dateRecord.GpuBenchMarkJob = getMapKeyStringValue(fmt.Sprint(dateRecord.ID)+"_GpuBenchMarkJob", CloudBrainTaskItemMap) dateRecord.CommitModelCount = getMapValue(dateRecord.ID, AiModelManageMap) - dateRecord.UserIndex = getUserIndex(dateRecord) + dateRecord.UserIndex = getUserIndex(dateRecord, ParaWeight) _, err = statictisSess.Insert(&dateRecord) if err != nil { @@ -681,9 +685,83 @@ func CounDataByDateAndReCount(wikiCountMap map[string]int, startTime time.Time, return nil } -func getUserIndex(dateRecord UserBusinessAnalysis) float64 { +func getParaWeight() map[string]float64 { + result := make(map[string]float64) + statictisSess := xStatistic.NewSession() + defer statictisSess.Close() + statictisSess.Select("*").Table(new(UserAnalysisPara)) + paraList := make([]*UserAnalysisPara, 0) + statictisSess.Find(¶List) + for _, paraRecord := range paraList { + result[paraRecord.Key] = paraRecord.Value + } + return result +} + +func getUserIndexFromAnalysisAll(dateRecord UserBusinessAnalysisAll, ParaWeight map[string]float64) float64 { + var result float64 + // PR数 0.20 + // commit数 0.20 + // 提出任务数 0.20 + // 评论数 0.20 + // 关注项目数 0.10 + // 点赞项目数 0.10 + // 登录次数 0.10 + result = float64(dateRecord.CodeMergeCount) * getParaWeightValue("CodeMergeCount", ParaWeight, 0.2) + result += float64(dateRecord.CommitCount) * getParaWeightValue("CommitCount", ParaWeight, 0.2) + log.Info("1 result=" + fmt.Sprint(result)) + result += float64(dateRecord.IssueCount) * getParaWeightValue("IssueCount", ParaWeight, 0.2) + result += float64(dateRecord.CommentCount) * getParaWeightValue("CommentCount", ParaWeight, 0.2) + result += float64(dateRecord.FocusRepoCount) * getParaWeightValue("FocusRepoCount", ParaWeight, 0.1) + result += float64(dateRecord.StarRepoCount) * getParaWeightValue("StarRepoCount", ParaWeight, 0.1) + result += float64(dateRecord.LoginCount) * getParaWeightValue("LoginCount", ParaWeight, 0.1) + result += float64(dateRecord.WatchedCount) * getParaWeightValue("WatchedCount", ParaWeight, 0.3) + result += float64(dateRecord.CommitCodeSize) * getParaWeightValue("CommitCodeSize", ParaWeight, 0.1) + result += float64(dateRecord.SolveIssueCount) * getParaWeightValue("SolveIssueCount", ParaWeight, 0.2) + result += float64(dateRecord.EncyclopediasCount) * getParaWeightValue("EncyclopediasCount", ParaWeight, 0.1) + result += float64(dateRecord.CreateRepoCount) * getParaWeightValue("CreateRepoCount", ParaWeight, 0.05) + result += float64(dateRecord.CloudBrainTaskNum) * getParaWeightValue("CloudBrainTaskNum", ParaWeight, 0.3) + result += float64(dateRecord.CommitModelCount) * getParaWeightValue("CommitModelCount", ParaWeight, 0.2) + result += dateRecord.OpenIIndex * getParaWeightValue("OpenIIndex", ParaWeight, 0.1) + + return result +} + +func getUserIndex(dateRecord UserBusinessAnalysis, ParaWeight map[string]float64) float64 { + var result float64 + // PR数 0.20 + // commit数 0.20 + // 提出任务数 0.20 + // 评论数 0.20 + // 关注项目数 0.10 + // 点赞项目数 0.10 + // 登录次数 0.10 + result = float64(dateRecord.CodeMergeCount) * getParaWeightValue("CodeMergeCount", ParaWeight, 0.2) + result += float64(dateRecord.CommitCount) * getParaWeightValue("CommitCount", ParaWeight, 0.2) + log.Info("2 result=" + fmt.Sprint(result)) + result += float64(dateRecord.IssueCount) * getParaWeightValue("IssueCount", ParaWeight, 0.2) + result += float64(dateRecord.CommentCount) * getParaWeightValue("CommentCount", ParaWeight, 0.2) + result += float64(dateRecord.FocusRepoCount) * getParaWeightValue("FocusRepoCount", ParaWeight, 0.1) + result += float64(dateRecord.StarRepoCount) * getParaWeightValue("StarRepoCount", ParaWeight, 0.1) + result += float64(dateRecord.LoginCount) * getParaWeightValue("LoginCount", ParaWeight, 0.1) + result += float64(dateRecord.WatchedCount) * getParaWeightValue("WatchedCount", ParaWeight, 0.3) + result += float64(dateRecord.CommitCodeSize) * getParaWeightValue("CommitCodeSize", ParaWeight, 0.1) + result += float64(dateRecord.SolveIssueCount) * getParaWeightValue("SolveIssueCount", ParaWeight, 0.2) + result += float64(dateRecord.EncyclopediasCount) * getParaWeightValue("EncyclopediasCount", ParaWeight, 0.1) + result += float64(dateRecord.CreateRepoCount) * getParaWeightValue("CreateRepoCount", ParaWeight, 0.05) + result += float64(dateRecord.CloudBrainTaskNum) * getParaWeightValue("CloudBrainTaskNum", ParaWeight, 0.3) + result += float64(dateRecord.CommitModelCount) * getParaWeightValue("CommitModelCount", ParaWeight, 0.2) + result += dateRecord.OpenIIndex * getParaWeightValue("OpenIIndex", ParaWeight, 0.1) + + return result +} - return 0 +func getParaWeightValue(key string, valueMap map[string]float64, defaultValue float64) float64 { + if _, ok := valueMap[key]; !ok { + return defaultValue + } else { + return valueMap[key] + } } func getMapKeyStringValue(key string, valueMap map[string]int) int { diff --git a/models/user_business_struct.go b/models/user_business_struct.go index 066e11314..3bfebf3e0 100644 --- a/models/user_business_struct.go +++ b/models/user_business_struct.go @@ -337,3 +337,8 @@ type UserBusinessAnalysisYesterday struct { UserIndex float64 `xorm:"NOT NULL DEFAULT 0"` UserLocation string `xorm:"NULL"` } + +type UserAnalysisPara struct { + Key string `xorm:"NOT NULL"` + Value float64 `xorm:"NOT NULL DEFAULT 0"` +} From 53144be9b6ca9793d4d3649b6b50d029d7f3402a Mon Sep 17 00:00:00 2001 From: wangjr Date: Tue, 22 Mar 2022 16:46:19 +0800 Subject: [PATCH 008/256] =?UTF-8?q?=E7=BB=84=E7=BB=87=E6=8E=A8=E8=8D=90?= =?UTF-8?q?=E7=BB=84=E7=BB=87=E9=A6=96=E6=AC=A1=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- options/locale/locale_en-US.ini | 7 ++ options/locale/locale_zh-CN.ini | 8 +++ templates/explore/organizations.tmpl | 100 +++++++++++++++++++++++++++ 3 files changed, 115 insertions(+) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 226fa2147..e10b2d1b4 100755 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -2104,6 +2104,13 @@ customize = Customize selected_project=Selected Projects fold = Fold unfold = Unfold +org_member = Member +org_members = Members +org_team = Team +org_teams = Teams +org_repository = Repository +org_repositories = Repositories + form.name_reserved = The organization name '%s' is reserved. form.name_pattern_not_allowed = The pattern '%s' is not allowed in an organization name. diff --git a/options/locale/locale_zh-CN.ini b/options/locale/locale_zh-CN.ini index ce5367d98..a8d1a7399 100755 --- a/options/locale/locale_zh-CN.ini +++ b/options/locale/locale_zh-CN.ini @@ -2111,6 +2111,14 @@ customize = 自定义 selected_project=精选项目 fold = 收起 unfold = 展开 +org_member = 成员 +org_members = 成员 +org_team = 团队 +org_teams = 团队 +org_repository = 项目 +org_repositories = 项目 + + form.name_reserved=组织名称 '%s' 是被保留的。 form.name_pattern_not_allowed=组织名称中不允许使用 "%s"。 diff --git a/templates/explore/organizations.tmpl b/templates/explore/organizations.tmpl index 1151c5a94..84a2d77a8 100644 --- a/templates/explore/organizations.tmpl +++ b/templates/explore/organizations.tmpl @@ -1,9 +1,76 @@ + + + + + + + {{template "base/head" .}}
{{template "explore/search" .}} + {{template "base/footer" .}} + + From de101e88008e9c549c5e07227c59cd99332be97f Mon Sep 17 00:00:00 2001 From: zouap Date: Tue, 22 Mar 2022 17:15:06 +0800 Subject: [PATCH 009/256] =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=88=86=E6=9E=90?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- options/locale/locale_zh-CN.ini | 5 ++++ routers/repo/user_data_analysis.go | 15 ++++++++++-- web_src/js/components/UserAnalysis.vue | 32 +++++++++++++++++++++++++- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/options/locale/locale_zh-CN.ini b/options/locale/locale_zh-CN.ini index ce5367d98..79e43f437 100755 --- a/options/locale/locale_zh-CN.ini +++ b/options/locale/locale_zh-CN.ini @@ -470,6 +470,11 @@ static.encyclopediascount=百科页面贡献次数 static.createrepocount=创建项目数 static.openiindex=OpenI指数 static.registdate=用户注册时间 +static.CloudBrainTaskNum=云脑任务数 +static.CloudBrainRunTime=云脑运行时间(小时) +static.CommitDatasetNum=上传(提交)数据集文件数 +static.CommitModelCount=提交模型数 +static.UserIndex=用户指数 static.countdate=系统统计时间 static.all=所有 static.public.user_business_analysis_current_month=本月 diff --git a/routers/repo/user_data_analysis.go b/routers/repo/user_data_analysis.go index b4adfc347..15bb55e84 100755 --- a/routers/repo/user_data_analysis.go +++ b/routers/repo/user_data_analysis.go @@ -54,7 +54,12 @@ func queryUserDataPage(ctx *context.Context, tableName string, queryObj interfac "N1": ctx.Tr("user.static.createrepocount"), "O1": ctx.Tr("user.static.openiindex"), "P1": ctx.Tr("user.static.registdate"), - "Q1": ctx.Tr("user.static.countdate"), + "Q1": ctx.Tr("user.static.CloudBrainTaskNum"), + "R1": ctx.Tr("user.static.CloudBrainRunTime"), + "S1": ctx.Tr("user.static.CommitDatasetNum"), + "T1": ctx.Tr("user.static.CommitModelCount"), + "U1": ctx.Tr("user.static.UserIndex"), + "V1": ctx.Tr("user.static.countdate"), } for k, v := range dataHeader { //设置单元格的值 @@ -89,8 +94,14 @@ func queryUserDataPage(ctx *context.Context, tableName string, queryObj interfac formatTime := userRecord.RegistDate.Format("2006-01-02 15:04:05") xlsx.SetCellValue(sheetName, "P"+rows, formatTime[0:len(formatTime)-3]) + xlsx.SetCellValue(sheetName, "Q"+rows, userRecord.CloudBrainTaskNum) + xlsx.SetCellValue(sheetName, "R"+rows, userRecord.CloudBrainRunTime) + xlsx.SetCellValue(sheetName, "S"+rows, userRecord.CommitDatasetNum) + xlsx.SetCellValue(sheetName, "T"+rows, userRecord.CommitModelCount) + xlsx.SetCellValue(sheetName, "U"+rows, userRecord.UserIndex) + formatTime = userRecord.DataDate - xlsx.SetCellValue(sheetName, "Q"+rows, formatTime) + xlsx.SetCellValue(sheetName, "V"+rows, formatTime) } indexTotal += PAGE_SIZE diff --git a/web_src/js/components/UserAnalysis.vue b/web_src/js/components/UserAnalysis.vue index 682dbc78c..71a2de096 100755 --- a/web_src/js/components/UserAnalysis.vue +++ b/web_src/js/components/UserAnalysis.vue @@ -133,7 +133,37 @@ + + + + + + + + + + Date: Tue, 22 Mar 2022 17:19:46 +0800 Subject: [PATCH 010/256] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- options/locale/locale_en-US.ini | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 226fa2147..1280cb956 100755 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -467,6 +467,11 @@ static.encyclopediascount=Encyclopedias Count static.createrepocount=Create Repo Count static.openiindex=OpenI Index static.registdate=Regist Date +static.CloudBrainTaskNum=CloudBrain Task Count +static.CloudBrainRunTime=CloudBrain Run Time +static.CommitDatasetNum=Commit Dataset Count +static.CommitModelCount=Commit Model Count +static.UserIndex=User Index static.countdate=Count Date static.all=All static.public.user_business_analysis_current_month=Current_Month From 70e22a3131c429b48ca8cb05c08ab8bc965aa479 Mon Sep 17 00:00:00 2001 From: zouap Date: Tue, 22 Mar 2022 17:33:38 +0800 Subject: [PATCH 011/256] =?UTF-8?q?=E4=BF=9D=E7=95=99=E4=B8=A4=E4=BD=8D?= =?UTF-8?q?=E5=B0=8F=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- routers/repo/user_data_analysis.go | 2 +- web_src/js/components/UserAnalysis.vue | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/routers/repo/user_data_analysis.go b/routers/repo/user_data_analysis.go index 15bb55e84..8574e240b 100755 --- a/routers/repo/user_data_analysis.go +++ b/routers/repo/user_data_analysis.go @@ -98,7 +98,7 @@ func queryUserDataPage(ctx *context.Context, tableName string, queryObj interfac xlsx.SetCellValue(sheetName, "R"+rows, userRecord.CloudBrainRunTime) xlsx.SetCellValue(sheetName, "S"+rows, userRecord.CommitDatasetNum) xlsx.SetCellValue(sheetName, "T"+rows, userRecord.CommitModelCount) - xlsx.SetCellValue(sheetName, "U"+rows, userRecord.UserIndex) + xlsx.SetCellValue(sheetName, "U"+rows, fmt.Sprintf("%.2f", userRecord.UserIndex)) formatTime = userRecord.DataDate xlsx.SetCellValue(sheetName, "V"+rows, formatTime) diff --git a/web_src/js/components/UserAnalysis.vue b/web_src/js/components/UserAnalysis.vue index 71a2de096..a9381a383 100755 --- a/web_src/js/components/UserAnalysis.vue +++ b/web_src/js/components/UserAnalysis.vue @@ -163,6 +163,9 @@ label="用户指数" width="120px" align="center"> + Date: Wed, 23 Mar 2022 10:05:26 +0800 Subject: [PATCH 012/256] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=8E=A8=E8=8D=90?= =?UTF-8?q?=E7=BB=84=E7=BB=87=E6=A0=B7=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/explore/organizations.tmpl | 143 ++++++++++++++++----------- 1 file changed, 85 insertions(+), 58 deletions(-) diff --git a/templates/explore/organizations.tmpl b/templates/explore/organizations.tmpl index 84a2d77a8..872490c8a 100644 --- a/templates/explore/organizations.tmpl +++ b/templates/explore/organizations.tmpl @@ -4,72 +4,99 @@ + {{template "base/head" .}}
{{template "explore/search" .}} +
+
+

+ 推荐组织 +

+

这些优秀的组织正在使用启智AI开发协作平台;你的组织也想展示到这里, 点此提交

+
-
-
-
-
- -
-
- +
+
+
-
+fdf
+
+fdfd + +
+
+dfgfg + +
+
+ +
+ +
+
+ {{template "explore/navbar" .}}
@@ -140,7 +167,7 @@ window.onload = function() { var swiperOrg = new Swiper(".homeorg-list", { slidesPerView: 1, - slidesPerColumn: 4, + slidesPerColumn: 3, slidesPerColumnFill:'row', spaceBetween: 15, pagination: { @@ -153,10 +180,10 @@ window.onload = function() { }, breakpoints: { 768: { - slidesPerView: 2, + slidesPerView: 3, }, 1024: { - slidesPerView: 3, + slidesPerView: 4, }, }, From 26d1df4a0d8b5e3bc75cc1bf806b1e85835896d0 Mon Sep 17 00:00:00 2001 From: zouap Date: Thu, 24 Mar 2022 10:13:05 +0800 Subject: [PATCH 013/256] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- models/models.go | 2 + models/user_business_analysis.go | 65 ++++++++++++++++++++++++++------ models/user_business_struct.go | 9 +++++ 3 files changed, 64 insertions(+), 12 deletions(-) diff --git a/models/models.go b/models/models.go index 0f4679b4f..2ebdb4206 100755 --- a/models/models.go +++ b/models/models.go @@ -151,6 +151,8 @@ func init() { new(UserBusinessAnalysisCurrentWeek), new(UserBusinessAnalysisYesterday), new(UserLoginLog), + new(UserMetrics), + new(UserAnalysisPara), ) gonicNames := []string{"SSL", "UID"} diff --git a/models/user_business_analysis.go b/models/user_business_analysis.go index 04c0eb5f0..644398d48 100644 --- a/models/user_business_analysis.go +++ b/models/user_business_analysis.go @@ -378,7 +378,7 @@ func QueryUserStaticDataPage(opts *UserBusinessAnalysisQueryOptions) ([]*UserBus return userBusinessAnalysisReturnList, count } -func refreshUserStaticTable(wikiCountMap map[string]int, tableName string, pageStartTime time.Time, pageEndTime time.Time) { +func refreshUserStaticTable(wikiCountMap map[string]int, tableName string, pageStartTime time.Time, pageEndTime time.Time, userMetrics map[string]int) { sess := x.NewSession() defer sess.Close() @@ -481,6 +481,11 @@ func refreshUserStaticTable(wikiCountMap map[string]int, tableName string, pageS } dateRecordBatch = make([]UserBusinessAnalysisAll, 0) } + if tableName == "user_business_analysis_all" { + if dateRecordAll.UserIndex > 0 || dateRecordAll.LoginCount > 0 { + userMetrics["TotalHasActivityUser"] = getMapKeyStringValue("TotalHasActivityUser", userMetrics) + 1 + } + } } indexTotal += PAGE_SIZE if indexTotal >= count { @@ -519,36 +524,36 @@ func insertTable(dateRecords []UserBusinessAnalysisAll, tableName string, static statictisSess.Exec(insertBatchSql) } -func RefreshUserStaticAllTabel(wikiCountMap map[string]int) { +func RefreshUserStaticAllTabel(wikiCountMap map[string]int, userMetrics map[string]int) { currentTimeNow := time.Now() pageStartTime := time.Date(2021, 11, 5, 0, 0, 0, 0, currentTimeNow.Location()) pageEndTime := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 23, 59, 59, 0, currentTimeNow.Location()) - refreshUserStaticTable(wikiCountMap, "user_business_analysis_all", pageStartTime, pageEndTime) + refreshUserStaticTable(wikiCountMap, "user_business_analysis_all", pageStartTime, pageEndTime, userMetrics) log.Info("refresh all data finished.") pageStartTime = time.Date(currentTimeNow.Year(), 1, 1, 0, 0, 0, 0, currentTimeNow.Location()) - refreshUserStaticTable(wikiCountMap, "user_business_analysis_current_year", pageStartTime, pageEndTime) + refreshUserStaticTable(wikiCountMap, "user_business_analysis_current_year", pageStartTime, pageEndTime, userMetrics) thisMonth := time.Date(currentTimeNow.Year(), currentTimeNow.Month(), 1, 0, 0, 0, 0, currentTimeNow.Location()) - refreshUserStaticTable(wikiCountMap, "user_business_analysis_current_month", thisMonth, pageEndTime) + refreshUserStaticTable(wikiCountMap, "user_business_analysis_current_month", thisMonth, pageEndTime, userMetrics) offset := int(time.Monday - currentTimeNow.Weekday()) if offset > 0 { offset = -6 } pageStartTime = time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, offset) - refreshUserStaticTable(wikiCountMap, "user_business_analysis_current_week", pageStartTime, pageEndTime) + refreshUserStaticTable(wikiCountMap, "user_business_analysis_current_week", pageStartTime, pageEndTime, userMetrics) pageStartTime = time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, -30) - refreshUserStaticTable(wikiCountMap, "user_business_analysis_last30_day", pageStartTime, pageEndTime) + refreshUserStaticTable(wikiCountMap, "user_business_analysis_last30_day", pageStartTime, pageEndTime, userMetrics) pageStartTime = time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 0, 0, 0, 0, time.Local).AddDate(0, 0, -1) pageEndTime = time.Date(currentTimeNow.Year(), currentTimeNow.Month(), currentTimeNow.Day(), 23, 59, 59, 0, currentTimeNow.Location()).AddDate(0, 0, -1) - refreshUserStaticTable(wikiCountMap, "user_business_analysis_yesterday", pageStartTime, pageEndTime) + refreshUserStaticTable(wikiCountMap, "user_business_analysis_yesterday", pageStartTime, pageEndTime, userMetrics) pageStartTime = thisMonth.AddDate(0, -1, 0) pageEndTime = time.Date(currentTimeNow.Year(), currentTimeNow.Month(), 1, 23, 59, 59, 0, currentTimeNow.Location()).AddDate(0, 0, -1) - refreshUserStaticTable(wikiCountMap, "user_business_analysis_last_month", pageStartTime, pageEndTime) + refreshUserStaticTable(wikiCountMap, "user_business_analysis_last_month", pageStartTime, pageEndTime, userMetrics) } @@ -604,7 +609,7 @@ func CounDataByDateAndReCount(wikiCountMap map[string]int, startTime time.Time, } ParaWeight := getParaWeight() - + userMetrics := make(map[string]int) var indexTotal int64 indexTotal = 0 for { @@ -666,7 +671,7 @@ func CounDataByDateAndReCount(wikiCountMap map[string]int, startTime time.Time, dateRecord.CommitModelCount = getMapValue(dateRecord.ID, AiModelManageMap) dateRecord.UserIndex = getUserIndex(dateRecord, ParaWeight) - + setUserMetrics(userMetrics, userRecord, start_unix, end_unix, dateRecord) _, err = statictisSess.Insert(&dateRecord) if err != nil { log.Info("insert daterecord failed." + err.Error()) @@ -680,11 +685,47 @@ func CounDataByDateAndReCount(wikiCountMap map[string]int, startTime time.Time, } } - RefreshUserStaticAllTabel(wikiCountMap) + RefreshUserStaticAllTabel(wikiCountMap, userMetrics) + + //insert userMetrics table + var useMetrics UserMetrics + useMetrics.CountDate = CountDate.Unix() + statictisSess.Delete(&useMetrics) + + useMetrics.ActivateRegistUser = getMapKeyStringValue("ActivateRegistUser", userMetrics) + useMetrics.HasActivityUser = getMapKeyStringValue("HasActivityUser", userMetrics) + useMetrics.NotActivateRegistUser = getMapKeyStringValue("NotActivateRegistUser", userMetrics) + useMetrics.TotalActivateRegistUser = getMapKeyStringValue("TotalActivateRegistUser", userMetrics) + useMetrics.TotalHasActivityUser = getMapKeyStringValue("TotalHasActivityUser", userMetrics) + statictisSess.Insert(&useMetrics) return nil } +func setUserMetrics(userMetrics map[string]int, user *User, start_time int64, end_time int64, dateRecord UserBusinessAnalysis) { + //ActivateRegistUser int `xorm:"NOT NULL DEFAULT 0"` + //NotActivateRegistUser int `xorm:"NOT NULL DEFAULT 0"` + //HasActivityUser int `xorm:"NOT NULL DEFAULT 0"` + //TotalActivateRegistUser int `xorm:"NOT NULL DEFAULT 0"` + //TotalHasActivityUser + regist_time := user.CreatedUnix.AsTime().Unix() + if regist_time >= start_time && regist_time <= end_time { + if user.IsActive { + userMetrics["ActivateRegistUser"] = getMapKeyStringValue("ActivateRegistUser", userMetrics) + 1 + } else { + userMetrics["NotActivateRegistUser"] = getMapKeyStringValue("NotActivateRegistUser", userMetrics) + 1 + } + } + if user.IsActive { + userMetrics["TotalActivateRegistUser"] = getMapKeyStringValue("TotalActivateRegistUser", userMetrics) + 1 + } + + if dateRecord.UserIndex > 0 || dateRecord.LoginCount > 0 { + userMetrics["HasActivityUser"] = getMapKeyStringValue("HasActivityUser", userMetrics) + 1 + } + +} + func getParaWeight() map[string]float64 { result := make(map[string]float64) statictisSess := xStatistic.NewSession() diff --git a/models/user_business_struct.go b/models/user_business_struct.go index 3bfebf3e0..17d9f046f 100644 --- a/models/user_business_struct.go +++ b/models/user_business_struct.go @@ -342,3 +342,12 @@ type UserAnalysisPara struct { Key string `xorm:"NOT NULL"` Value float64 `xorm:"NOT NULL DEFAULT 0"` } + +type UserMetrics struct { + CountDate int64 `xorm:"pk"` + ActivateRegistUser int `xorm:"NOT NULL DEFAULT 0"` + NotActivateRegistUser int `xorm:"NOT NULL DEFAULT 0"` + HasActivityUser int `xorm:"NOT NULL DEFAULT 0"` + TotalActivateRegistUser int `xorm:"NOT NULL DEFAULT 0"` + TotalHasActivityUser int `xorm:"NOT NULL DEFAULT 0"` +} From 756222d96ef6e352c2152cbd8b1811fc6d5ebf80 Mon Sep 17 00:00:00 2001 From: zouap Date: Thu, 24 Mar 2022 11:10:47 +0800 Subject: [PATCH 014/256] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- models/user_business_analysis.go | 4 ++-- routers/repo/user_data_analysis.go | 17 +++++++++++++---- web_src/js/components/UserAnalysis.vue | 6 ++++++ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/models/user_business_analysis.go b/models/user_business_analysis.go index 644398d48..edfe73939 100644 --- a/models/user_business_analysis.go +++ b/models/user_business_analysis.go @@ -668,7 +668,7 @@ func CounDataByDateAndReCount(wikiCountMap map[string]int, startTime time.Time, dateRecord.NpuTrainJob = getMapKeyStringValue(fmt.Sprint(dateRecord.ID)+"_NpuTrainJob", CloudBrainTaskItemMap) dateRecord.NpuInferenceJob = getMapKeyStringValue(fmt.Sprint(dateRecord.ID)+"_NpuInferenceJob", CloudBrainTaskItemMap) dateRecord.GpuBenchMarkJob = getMapKeyStringValue(fmt.Sprint(dateRecord.ID)+"_GpuBenchMarkJob", CloudBrainTaskItemMap) - + dateRecord.CloudBrainRunTime = getMapKeyStringValue(fmt.Sprint(dateRecord.ID)+"_CloudBrainRunTime", CloudBrainTaskItemMap) dateRecord.CommitModelCount = getMapValue(dateRecord.ID, AiModelManageMap) dateRecord.UserIndex = getUserIndex(dateRecord, ParaWeight) setUserMetrics(userMetrics, userRecord, start_unix, end_unix, dateRecord) @@ -1375,7 +1375,7 @@ func queryCloudBrainTask(start_unix int64, end_unix int64) (map[int64]int, map[s } else { resultMap[cloudTaskRecord.UserID] += 1 } - setMapKey("time", cloudTaskRecord.UserID, int(cloudTaskRecord.Duration), resultItemMap) + setMapKey("CloudBrainRunTime", cloudTaskRecord.UserID, int(cloudTaskRecord.Duration), resultItemMap) if cloudTaskRecord.Type == 1 { //npu if cloudTaskRecord.JobType == "TRAIN" { setMapKey("NpuTrainJob", cloudTaskRecord.UserID, 1, resultItemMap) diff --git a/routers/repo/user_data_analysis.go b/routers/repo/user_data_analysis.go index 8574e240b..96503e5c9 100755 --- a/routers/repo/user_data_analysis.go +++ b/routers/repo/user_data_analysis.go @@ -95,7 +95,7 @@ func queryUserDataPage(ctx *context.Context, tableName string, queryObj interfac xlsx.SetCellValue(sheetName, "P"+rows, formatTime[0:len(formatTime)-3]) xlsx.SetCellValue(sheetName, "Q"+rows, userRecord.CloudBrainTaskNum) - xlsx.SetCellValue(sheetName, "R"+rows, userRecord.CloudBrainRunTime) + xlsx.SetCellValue(sheetName, "R"+rows, fmt.Sprintf("%.2f", float64(userRecord.CloudBrainRunTime)/3600)) xlsx.SetCellValue(sheetName, "S"+rows, userRecord.CommitDatasetNum) xlsx.SetCellValue(sheetName, "T"+rows, userRecord.CommitModelCount) xlsx.SetCellValue(sheetName, "U"+rows, fmt.Sprintf("%.2f", userRecord.UserIndex)) @@ -232,7 +232,12 @@ func QueryUserStaticDataPage(ctx *context.Context) { "N1": ctx.Tr("user.static.createrepocount"), "O1": ctx.Tr("user.static.openiindex"), "P1": ctx.Tr("user.static.registdate"), - "Q1": ctx.Tr("user.static.countdate"), + "Q1": ctx.Tr("user.static.CloudBrainTaskNum"), + "R1": ctx.Tr("user.static.CloudBrainRunTime"), + "S1": ctx.Tr("user.static.CommitDatasetNum"), + "T1": ctx.Tr("user.static.CommitModelCount"), + "U1": ctx.Tr("user.static.UserIndex"), + "V1": ctx.Tr("user.static.countdate"), } for k, v := range dataHeader { //设置单元格的值 @@ -260,9 +265,13 @@ func QueryUserStaticDataPage(ctx *context.Context) { formatTime := userRecord.RegistDate.Format("2006-01-02 15:04:05") xlsx.SetCellValue(sheetName, "P"+rows, formatTime[0:len(formatTime)-3]) - + xlsx.SetCellValue(sheetName, "Q"+rows, userRecord.CloudBrainTaskNum) + xlsx.SetCellValue(sheetName, "R"+rows, fmt.Sprintf("%.2f", float64(userRecord.CloudBrainRunTime)/3600)) + xlsx.SetCellValue(sheetName, "S"+rows, userRecord.CommitDatasetNum) + xlsx.SetCellValue(sheetName, "T"+rows, userRecord.CommitModelCount) + xlsx.SetCellValue(sheetName, "U"+rows, fmt.Sprintf("%.2f", userRecord.UserIndex)) formatTime = userRecord.DataDate - xlsx.SetCellValue(sheetName, "Q"+rows, formatTime+" 00:01") + xlsx.SetCellValue(sheetName, "V"+rows, formatTime) } //设置默认打开的表单 diff --git a/web_src/js/components/UserAnalysis.vue b/web_src/js/components/UserAnalysis.vue index a9381a383..241768c15 100755 --- a/web_src/js/components/UserAnalysis.vue +++ b/web_src/js/components/UserAnalysis.vue @@ -145,6 +145,9 @@ label="云脑运行时间(小时)" width="120px" align="center"> + Date: Thu, 24 Mar 2022 17:06:21 +0800 Subject: [PATCH 015/256] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routers/home.go | 1 + 1 file changed, 1 insertion(+) diff --git a/routers/home.go b/routers/home.go index aeb67b638..e7067524f 100755 --- a/routers/home.go +++ b/routers/home.go @@ -444,6 +444,7 @@ func ExploreOrganizations(ctx *context.Context) { ctx.ServerError("GetRecommendOrgInfos", err) return } + ctx.Data["RecommendURL"] = setting.RecommentRepoAddr ctx.Data["RecommendOrgs"] = recommendOrgs ctx.Data["StarOrgs"] = starInfo ctx.Data["MemberOrgs"] = memberInfo From 9ab71724f501a810cbf6d8d094be02d516b4ce2e Mon Sep 17 00:00:00 2001 From: ychao_1983 Date: Thu, 24 Mar 2022 17:55:05 +0800 Subject: [PATCH 016/256] =?UTF-8?q?=E6=8F=90=E4=BA=A4=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- routers/home.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/routers/home.go b/routers/home.go index e7067524f..55c077f66 100755 --- a/routers/home.go +++ b/routers/home.go @@ -49,7 +49,7 @@ func Home(ctx *context.Context) { ctx.HTML(200, tplHome) } -func setRecommendURL(ctx *context.Context) { +func setRecommendURLOnly(ctx *context.Context) { addr := setting.RecommentRepoAddr[10:] start := strings.Index(addr, "/") end := strings.Index(addr, "raw") @@ -58,7 +58,10 @@ func setRecommendURL(ctx *context.Context) { } else { ctx.Data["RecommendURL"] = setting.RecommentRepoAddr } +} +func setRecommendURL(ctx *context.Context) { + setRecommendURLOnly(ctx) ctx.Data["page_title"] = ctx.Tr("home.page_title") ctx.Data["page_small_title"] = ctx.Tr("home.page_small_title") ctx.Data["page_description"] = ctx.Tr("home.page_description") @@ -444,7 +447,7 @@ func ExploreOrganizations(ctx *context.Context) { ctx.ServerError("GetRecommendOrgInfos", err) return } - ctx.Data["RecommendURL"] = setting.RecommentRepoAddr + setRecommendURLOnly(ctx) ctx.Data["RecommendOrgs"] = recommendOrgs ctx.Data["StarOrgs"] = starInfo ctx.Data["MemberOrgs"] = memberInfo From 212b63c5a97de094142ab75e622872b1d9f6ea08 Mon Sep 17 00:00:00 2001 From: wangjr Date: Fri, 25 Mar 2022 10:50:02 +0800 Subject: [PATCH 017/256] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=BB=84=E7=BB=87?= =?UTF-8?q?=E5=B9=BF=E5=9C=BA=E6=8E=92=E5=90=8D=E5=88=97=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- options/locale/locale_en-US.ini | 3 + options/locale/locale_zh-CN.ini | 4 +- templates/explore/organizations.tmpl | 207 +++++++++++++++------------ web_src/less/openi.less | 84 +++++++++++ 4 files changed, 208 insertions(+), 90 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 51e8a6c45..28250ab0c 100755 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -2141,6 +2141,9 @@ org_teams = Teams org_repository = Repository org_repositories = Repositories +star = Star Top10 +member = Members Top10 +active = Active Top10 form.name_reserved = The organization name '%s' is reserved. form.name_pattern_not_allowed = The pattern '%s' is not allowed in an organization name. diff --git a/options/locale/locale_zh-CN.ini b/options/locale/locale_zh-CN.ini index 535f65ee1..18f6293f3 100755 --- a/options/locale/locale_zh-CN.ini +++ b/options/locale/locale_zh-CN.ini @@ -2145,7 +2145,9 @@ org_teams = 团队 org_repository = 项目 org_repositories = 项目 - +star = 点赞榜 +member = 成员榜 +active = 活跃榜 form.name_reserved=组织名称 '%s' 是被保留的。 form.name_pattern_not_allowed=组织名称中不允许使用 "%s"。 diff --git a/templates/explore/organizations.tmpl b/templates/explore/organizations.tmpl index 872490c8a..d88272e71 100644 --- a/templates/explore/organizations.tmpl +++ b/templates/explore/organizations.tmpl @@ -4,27 +4,15 @@ - - {{template "base/head" .}}
{{template "explore/search" .}}

- 推荐组织 + {{$.i18n.Tr "home.page_recommend_org"}}

-

这些优秀的组织正在使用启智AI开发协作平台;你的组织也想展示到这里, 点此提交

+

{{$.i18n.Tr "home.page_recommend_org_desc"}} {{$.i18n.Tr "home.page_recommend_org_commit"}}

@@ -76,88 +64,130 @@
-
-
-
- -fdf -
-
-fdfd - -
-
-dfgfg - -
-
- -
- -
-
- - - {{template "explore/navbar" .}} -
-

- {{.i18n.Tr "explore.organizations"}} -

- {{template "base/footer" .}} @@ -191,5 +221,4 @@ window.onload = function() { } - diff --git a/web_src/less/openi.less b/web_src/less/openi.less index 7871d8148..ad252dde7 100644 --- a/web_src/less/openi.less +++ b/web_src/less/openi.less @@ -779,4 +779,88 @@ display: block; border: none !important; color: #0366d6 !important; box-shadow: -15px 0px 10px #fff; +} + +.content_top10{ + padding:10px; + padding-top:0px; +} +.re_con{ + color: rgba(136, 136, 136, 100); + font-size: 14px; + text-align: center; + font-family: SourceHanSansSC-light; +} +.title_re{ + margin-top: 50px !important; +} +.card_list { + width: calc(33.33333333333333% - 2em); + margin-left: 1em; + margin-right: 1em +} +.list_title{ + height: 52px; + text-align: center +} +.star_title{ + background-color: #3291F8; +} +.memb_title{ + background-color: #706FE3; +} +.act_title{ + background-color: #13C28D; +} +.p_text{ + line-height: 50px; + text-align:left; + padding-left:15px; + font-size:18px; + color:#FFFFFF; +} +.orgs { + display: flex; + flex-flow: row wrap; + padding: 0; + margin-top:20px +} +.orgs li { + display: flex; + border-bottom: 0!important; + padding: 3px!important; +} +.p_score{ + line-height: 28px; + width: 100%; + + /* padding-right: 20px; */ + text-align: right; +} +.org_line_hight{ + line-height: 28px; +} +.org_icon{ + margin-top: 10px; + margin-right: 10px; + padding-left: 15px; +} +.org_icon_num{ + margin-left: 2px; + margin-right: 12px; +} +.org_icon_color{ + color: #FA8C16; +} +.li_name{ + list-style:none; + width: 55%; +} +.li_avatar{ + list-style: none; + width: 10%; +} +.li_score{ + list-style:none; + margin-left: 2px; } \ No newline at end of file From ed289fba93da1295d21a3eb03ddc37e33ecae705 Mon Sep 17 00:00:00 2001 From: liuzx Date: Fri, 25 Mar 2022 16:27:25 +0800 Subject: [PATCH 018/256] fix-1647 --- routers/repo/modelarts.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/repo/modelarts.go b/routers/repo/modelarts.go index 9c670e203..83dba1796 100755 --- a/routers/repo/modelarts.go +++ b/routers/repo/modelarts.go @@ -1475,7 +1475,7 @@ func TrainJobShow(ctx *context.Context) { ctx.Data["displayJobName"] = VersionListTasks[0].DisplayJobName ctx.Data["version_list_task"] = VersionListTasks ctx.Data["version_list_count"] = VersionListCount - ctx.Data["canDownload"] = cloudbrain.CanDeleteJob(ctx, &VersionListTasks[0].Cloudbrain) + ctx.Data["canDownload"] = canNewJob ctx.HTML(http.StatusOK, tplModelArtsTrainJobShow) } From 38674e71da9dbcf0fce12f8c4612b6a99beef40e Mon Sep 17 00:00:00 2001 From: chenyifan01 Date: Mon, 28 Mar 2022 15:12:18 +0800 Subject: [PATCH 019/256] #1641 fix bug --- routers/repo/view.go | 24 ++++++++++++++---------- templates/repo/view_file.tmpl | 4 ++-- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/routers/repo/view.go b/routers/repo/view.go index 320102ba4..b28e21aa1 100755 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -247,7 +247,11 @@ func renderDirectory(ctx *context.Context, treeLink string) { ctx.Data["ReadmeInList"] = true ctx.Data["ReadmeExist"] = true ctx.Data["FileIsSymlink"] = readmeFile.isSymlink - ctx.Data["ReadmeName"] = readmeFile.name + if ctx.Repo.TreePath == "" { + ctx.Data["ReadmeRelativePath"] = readmeFile.name + } else { + ctx.Data["ReadmeRelativePath"] = ctx.Repo.TreePath + "/" + readmeFile.name + } if ctx.Repo.CanEnableEditor() { ctx.Data["CanEditFile"] = true @@ -579,11 +583,11 @@ func safeURL(address string) string { } type ContributorInfo struct { - UserInfo *models.User // nil for contributor who is not a registered user - RelAvatarLink string `json:"rel_avatar_link"` - UserName string `json:"user_name"` - Email string `json:"email"` - CommitCnt int `json:"commit_cnt"` + UserInfo *models.User // nil for contributor who is not a registered user + RelAvatarLink string `json:"rel_avatar_link"` + UserName string `json:"user_name"` + Email string `json:"email"` + CommitCnt int `json:"commit_cnt"` } type GetContributorsInfo struct { @@ -642,7 +646,7 @@ func Home(ctx *context.Context) { existedContributorInfo.CommitCnt += c.CommitCnt } else { var newContributor = &ContributorInfo{ - user, "", "",c.Email, c.CommitCnt, + user, "", "", c.Email, c.CommitCnt, } count++ contributorInfos = append(contributorInfos, newContributor) @@ -839,7 +843,7 @@ func renderCode(ctx *context.Context) { compareInfo, err = baseGitRepo.GetCompareInfo(ctx.Repo.Repository.RepoPath(), ctx.Repo.BranchName, ctx.Repo.Repository.BaseRepo.DefaultBranch) ctx.Data["UpstreamSameBranchName"] = false } - if err==nil && compareInfo != nil { + if err == nil && compareInfo != nil { if compareInfo.Commits != nil { log.Info("compareInfoCommits数量:%d", compareInfo.Commits.Len()) ctx.Data["FetchUpstreamCnt"] = compareInfo.Commits.Len() @@ -950,7 +954,7 @@ func ContributorsAPI(ctx *context.Context) { } else { // new committer info var newContributor = &ContributorInfo{ - user, user.RelAvatarLink(),user.Name, user.Email,c.CommitCnt, + user, user.RelAvatarLink(), user.Name, user.Email, c.CommitCnt, } count++ contributorInfos = append(contributorInfos, newContributor) @@ -963,7 +967,7 @@ func ContributorsAPI(ctx *context.Context) { existedContributorInfo.CommitCnt += c.CommitCnt } else { var newContributor = &ContributorInfo{ - user, "", "",c.Email,c.CommitCnt, + user, "", "", c.Email, c.CommitCnt, } count++ contributorInfos = append(contributorInfos, newContributor) diff --git a/templates/repo/view_file.tmpl b/templates/repo/view_file.tmpl index a0cae31f3..a559dd611 100755 --- a/templates/repo/view_file.tmpl +++ b/templates/repo/view_file.tmpl @@ -40,7 +40,7 @@
{{if .Repository.CanEnableEditor}} {{if .CanEditFile}} - {{svg "octicon-pencil" 16}} + {{svg "octicon-pencil" 16}} {{else}} {{svg "octicon-pencil" 16}} {{end}} @@ -48,7 +48,7 @@
{{end}} - + {{if not .ReadmeInList}}
From 9fcbd70f1e5bab1239bc1d986ef120f975210d74 Mon Sep 17 00:00:00 2001 From: zhoupzh Date: Mon, 28 Mar 2022 17:05:42 +0800 Subject: [PATCH 020/256] fix issue --- web_src/js/index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/web_src/js/index.js b/web_src/js/index.js index 902750c5b..f245045db 100755 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -2788,6 +2788,9 @@ $(document).ready(async () => { }); } }); + this.on('addedfile',(file)=>{ + console.log("addfile",file) + }) } }); } From ce3d50cd068e6789d0b5b3a3a001dad628bbb582 Mon Sep 17 00:00:00 2001 From: zhoupzh Date: Tue, 29 Mar 2022 10:23:57 +0800 Subject: [PATCH 021/256] fix issue --- templates/repo/editor/upload.tmpl | 2 +- web_src/js/index.js | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/templates/repo/editor/upload.tmpl b/templates/repo/editor/upload.tmpl index 7794c2a2d..08727600c 100644 --- a/templates/repo/editor/upload.tmpl +++ b/templates/repo/editor/upload.tmpl @@ -27,7 +27,7 @@
-
+
{{template "repo/editor/commit_form" .}} diff --git a/web_src/js/index.js b/web_src/js/index.js index f245045db..a832c0b4b 100755 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -2769,6 +2769,7 @@ $(document).ready(async () => { dictInvalidFileType: $dropzone.data('invalid-input-type'), dictFileTooBig: $dropzone.data('file-too-big'), dictRemoveFile: $dropzone.data('remove-file'), + dictMaxFilesExceeded:'上次超过限制', init() { this.on('success', (file, data) => { filenameDict[file.name] = data.uuid; @@ -2789,8 +2790,20 @@ $(document).ready(async () => { } }); this.on('addedfile',(file)=>{ - console.log("addfile",file) + console.log("addfile",file,filenameDict,this.files.length) + if(file.size/(1000*1000)>3){ + this.removeFile(file) + $('.maxfilesize.ui.red.message').text('单次最多上传XX个文件,每个文件不超过XXM。') + $('.maxfilesize.ui.red.message').css('display','block') + } + + }); + this.on('maxfilesexceeded',(file)=>{ + this.removeFile(file) + $('.maxfilesize.ui.red.message').text('一次最多只能上传 5 个文件, 上传已达到上限,请勿再添加文件。') + $('.maxfilesize.ui.red.message').css('display','block') }) + } }); } From 4793fae46b3d3bbf991e9b1abd9b5937ad68ff44 Mon Sep 17 00:00:00 2001 From: ychao_1983 Date: Wed, 30 Mar 2022 15:32:53 +0800 Subject: [PATCH 022/256] =?UTF-8?q?=E9=95=9C=E5=83=8F=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/cloudbrain.go | 10 +- models/cloudbrain_image.go | 415 +++++++++++++++++++++++++++++++ models/models.go | 2 + modules/auth/cloudbrain.go | 20 +- modules/cloudbrain/cloudbrain.go | 34 +++ modules/cloudbrain/resty.go | 35 ++- modules/setting/cloudbrain.go | 8 +- options/locale/locale_en-US.ini | 8 +- options/locale/locale_zh-CN.ini | 6 +- routers/admin/cloudbrains.go | 6 + routers/repo/cloudbrain.go | 84 ++++++- routers/routes/routes.go | 13 +- 12 files changed, 616 insertions(+), 25 deletions(-) create mode 100644 models/cloudbrain_image.go diff --git a/models/cloudbrain.go b/models/cloudbrain.go index 17761a1dc..12e9ee2b1 100755 --- a/models/cloudbrain.go +++ b/models/cloudbrain.go @@ -518,13 +518,21 @@ type PoolInfo struct { PoolType string `json:"pool_type"` } -type CommitImageParams struct { +type CommitImageCloudBrainParams struct { Ip string `json:"ip"` TaskContainerId string `json:"taskContainerId"` ImageTag string `json:"imageTag"` ImageDescription string `json:"imageDescription"` } +type CommitImageParams struct { + CommitImageCloudBrainParams + IsPrivate bool + Topics []string + CloudBrainType int + UID int64 +} + type CommitImageResult struct { Code string `json:"code"` Msg string `json:"msg"` diff --git a/models/cloudbrain_image.go b/models/cloudbrain_image.go new file mode 100644 index 000000000..a6ca35f29 --- /dev/null +++ b/models/cloudbrain_image.go @@ -0,0 +1,415 @@ +package models + +import ( + "fmt" + "strings" + + "xorm.io/builder" + + "code.gitea.io/gitea/modules/timeutil" +) + +const RECOMMOND_TYPE = 5 +const NORMAL_TYPE = 0 + +type Image struct { + ID int64 `xorm:"pk autoincr"` + Type int `xorm:"INDEX NOT NULL"` //0 normal 5官方推荐,中间值保留为后续扩展 + CloudbrainType int `xorm:"INDEX NOT NULL"` //0 云脑一 1云脑二 + UID int64 `xorm:"INDEX NOT NULL"` + IsPrivate bool `xorm:"INDEX NOT NULL"` + Tag string `xorm:"varchar(100) UNIQUE"` + Description string `xorm:"varchar(765)"` + Topics []string `xorm:"TEXT JSON"` + Place string `xorm:"varchar(300)"` + NumStars int `xorm:"NOT NULL DEFAULT 0"` + CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` + UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` +} + +type ImageStar struct { + ID int64 `xorm:"pk autoincr"` + UID int64 `xorm:"UNIQUE(s)"` + ImageID int64 `xorm:"UNIQUE(s)"` + CreatedUnix timeutil.TimeStamp `xorm:"created"` +} + +type ImageTopic struct { + ID int64 + Name string `xorm:"UNIQUE VARCHAR(105)"` + ImageCount int + CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` + UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` +} + +type ImageTopicRelation struct { + ImageID int64 `xorm:"UNIQUE(s)"` + TopicID int64 `xorm:"UNIQUE(s)"` +} + +type SearchImageOptions struct { + Keyword string + UID int64 + IncludePublic bool + IncludeStarByMe bool + IncludeCustom bool + CodeLanguage string + Framework string + CudaVersion string + ListOptions + SearchOrderBy +} +type ErrorImageTagExist struct { + Tag string +} + +func (err ErrorImageTagExist) Error() string { + return fmt.Sprintf("Image already exists [tag: %s]", err.Tag) +} + +type ErrImageNotExist struct { + ID int64 +} + +func (err ErrImageNotExist) Error() string { + return fmt.Sprintf("Image does not exist [id: %d]", err.ID) +} + +func IsErrImageTagExist(err error) bool { + _, ok := err.(ErrorImageTagExist) + return ok +} + +func IsImageExist(tag string) (bool, error) { + return x.Exist(&Image{ + Tag: tag, + }) +} + +type FindImageTopicOptions struct { + ListOptions + ImageID int64 + Keyword string +} + +func (opts *FindImageTopicOptions) toConds() builder.Cond { + var cond = builder.NewCond() + if opts.ImageID > 0 { + cond = cond.And(builder.Eq{"image_topic.image_id": opts.ImageID}) + } + + if opts.Keyword != "" { + cond = cond.And(builder.Like{"image_topic.name", strings.ToLower(opts.Keyword)}) + } + + return cond +} + +func GetImageByID(id int64) (*Image, error) { + rel := new(Image) + has, err := x. + ID(id). + Get(rel) + if err != nil { + return nil, err + } else if !has { + return nil, ErrImageNotExist{id} + } + + return rel, nil +} +func FindImageTopics(opts *FindImageTopicOptions) (topics []*ImageTopic, err error) { + sess := x.Select("image_topic.*").Where(opts.toConds()) + if opts.ImageID > 0 { + sess.Join("INNER", "image_topic_relation", "image_topic_relation.topic_id = image_topic.id") + } + if opts.PageSize != 0 && opts.Page != 0 { + sess = opts.setSessionPagination(sess) + } + return topics, sess.Desc("image_topic.image_count").Find(&topics) +} + +func SaveImageTopics(imageID int64, topicNames ...string) error { + topics, err := FindImageTopics(&FindImageTopicOptions{ + ImageID: imageID, + }) + if err != nil { + return err + } + + sess := x.NewSession() + defer sess.Close() + + if err := sess.Begin(); err != nil { + return err + } + + var addedTopicNames []string + for _, topicName := range topicNames { + if strings.TrimSpace(topicName) == "" { + continue + } + + var found bool + for _, t := range topics { + if strings.EqualFold(topicName, t.Name) { + found = true + break + } + } + if !found { + addedTopicNames = append(addedTopicNames, topicName) + } + } + + var removeTopics []*ImageTopic + for _, t := range topics { + var found bool + for _, topicName := range topicNames { + if strings.EqualFold(topicName, t.Name) { + found = true + break + } + } + if !found { + removeTopics = append(removeTopics, t) + } + } + + for _, topicName := range addedTopicNames { + _, err := addTopicByNameToImage(sess, imageID, topicName) + if err != nil { + return err + } + } + + for _, topic := range removeTopics { + err := removeTopicFromImage(sess, imageID, topic) + if err != nil { + return err + } + } + + topicNames = make([]string, 0, 25) + if err := sess.Table("image_topic").Cols("name"). + Join("INNER", "image_topic_relation", "image_topic_relation.topic_id = image_topic.id"). + Where("image_topic_relation.image_id = ?", imageID).Desc("image_topic.image_count").Find(&topicNames); err != nil { + return err + } + + if _, err := sess.ID(imageID).Cols("topics").Update(&Image{ + Topics: topicNames, + }); err != nil { + return err + } + + return sess.Commit() +} + +func addTopicByNameToImage(e Engine, imageID int64, topicName string) (*ImageTopic, error) { + var topic ImageTopic + has, err := e.Where("name = ?", topicName).Get(&topic) + if err != nil { + return nil, err + } + if !has { + topic.Name = topicName + topic.ImageCount = 1 + if _, err := e.Insert(&topic); err != nil { + return nil, err + } + } else { + topic.ImageCount++ + if _, err := e.ID(topic.ID).Cols("image_count").Update(&topic); err != nil { + return nil, err + } + } + + if _, err := e.Insert(&ImageTopicRelation{ + ImageID: imageID, + TopicID: topic.ID, + }); err != nil { + return nil, err + } + + return &topic, nil +} + +func removeTopicFromImage(e Engine, imageId int64, topic *ImageTopic) error { + topic.ImageCount-- + if _, err := e.ID(topic.ID).Cols("image_count").Update(topic); err != nil { + return err + } + + if _, err := e.Delete(&ImageTopicRelation{ + ImageID: imageId, + TopicID: topic.ID, + }); err != nil { + return err + } + + return nil +} + +/*func SearchImage(opts *SearchImageOptions) ([]*Image, int64, error) { + cond := SearchImageCondition(opts) + return SearchImageByCondition(opts, cond) +}*/ + +func SearchImageCondition(opts *SearchImageOptions) builder.Cond { + var cond = builder.NewCond() + + if len(opts.Keyword) > 0 { + cond = cond.And(builder.Or(builder.Like{"image.tag", opts.Keyword}, builder.Like{"image.description", opts.Keyword})) + } + + if len(opts.CudaVersion) > 0 { + cond = cond.And(builder.Eq{"image.cuda_version": opts.CudaVersion}) + } + + if len(opts.CodeLanguage) > 0 { + cond = cond.And(builder.Eq{"image.code_language": opts.CodeLanguage}) + } + if len(opts.Framework) > 0 { + cond = cond.And(builder.Eq{"image.framework": opts.Framework}) + } + + if opts.IncludePublic { + cond = cond.And(builder.Eq{"image.is_private": false}) + } + /** + if opts.IncludeStarByMe { + cond = cond.And(builder.Eq{"dataset.status": DatasetStatusPublic}) + cond = cond.And(builder.Eq{"attachment.is_private": false}) + if opts.OwnerID > 0 { + if len(opts.Keyword) == 0 { + cond = cond.Or(builder.Eq{"repository.owner_id": opts.OwnerID}) + } else { + subCon := builder.NewCond() + subCon = subCon.And(builder.Eq{"repository.owner_id": opts.OwnerID}, builder.Or(builder.Like{"dataset.title", opts.Keyword}, builder.Like{"dataset.description", opts.Keyword})) + cond = cond.Or(subCon) + + } + } + } else if opts.OwnerID > 0 { + cond = cond.And(builder.Eq{"repository.owner_id": opts.OwnerID}) + if !opts.IsOwner { + cond = cond.And(builder.Eq{"dataset.status": DatasetStatusPublic}) + cond = cond.And(builder.Eq{"attachment.is_private": false}) + } + }*/ + + return cond +} + +/*func SearchImageByCondition(opts *SearchImageOptions, cond builder.Cond) ([]*Image, int64, error) { + if opts.Page <= 0 { + opts.Page = 1 + } + + var err error + sess := x.NewSession() + defer sess.Close() + + datasets := make(DatasetList, 0, opts.PageSize) + selectColumnsSql := "distinct dataset.id,dataset.title, dataset.status, dataset.category, dataset.description, dataset.download_times, dataset.license, dataset.task, dataset.release_id, dataset.user_id, dataset.repo_id, dataset.created_unix,dataset.updated_unix,dataset.num_stars" + + count, err := sess.Distinct("dataset.id").Join("INNER", "repository", "repository.id = dataset.repo_id"). + Join("INNER", "attachment", "attachment.dataset_id=dataset.id"). + Where(cond).Count(new(Dataset)) + + if err != nil { + return nil, 0, fmt.Errorf("Count: %v", err) + } + + sess.Select(selectColumnsSql).Join("INNER", "repository", "repository.id = dataset.repo_id"). + Join("INNER", "attachment", "attachment.dataset_id=dataset.id"). + Where(cond).OrderBy(opts.SearchOrderBy.String()) + + if opts.PageSize > 0 { + sess.Limit(opts.PageSize, (opts.Page-1)*opts.PageSize) + } + if err = sess.Find(&datasets); err != nil { + return nil, 0, fmt.Errorf("Dataset: %v", err) + } + + if err = datasets.loadAttributes(sess); err != nil { + return nil, 0, fmt.Errorf("LoadAttributes: %v", err) + } + + return datasets, count, nil +}*/ + +func CreateLocalImage(image *Image) error { + + _, err := x.Insert(image) + return err +} + +//star or unstar Image +func StarImage(userID, imageID int64, star bool) error { + sess := x.NewSession() + defer sess.Close() + + if err := sess.Begin(); err != nil { + return err + } + + if star { + if isImageStaring(sess, userID, imageID) { + return nil + } + + if _, err := sess.Insert(&ImageStar{UID: userID, ImageID: imageID}); err != nil { + return err + } + if _, err := sess.Exec("UPDATE `image` SET num_stars = num_stars + 1 WHERE id = ?", imageID); err != nil { + return err + } + if _, err := sess.Exec("UPDATE `user` SET num_image_stars = num_image_stars + 1 WHERE id = ?", userID); err != nil { + return err + } + } else { + if !isImageStaring(sess, userID, imageID) { + return nil + } + + if _, err := sess.Delete(&ImageStar{0, userID, imageID, 0}); err != nil { + return err + } + if _, err := sess.Exec("UPDATE `image` SET num_stars = num_stars - 1 WHERE id = ?", imageID); err != nil { + return err + } + if _, err := sess.Exec("UPDATE `user` SET num_image_stars = num_image_stars - 1 WHERE id = ?", userID); err != nil { + return err + } + } + + return sess.Commit() +} + +func IsImageStaring(userID, datasetID int64) bool { + return isImageStaring(x, userID, datasetID) + +} + +func isImageStaring(e Engine, userID, imageID int64) bool { + has, _ := e.Get(&ImageStar{0, userID, imageID, 0}) + return has +} +func RecommendImage(imageId int64, recommond bool) error { + + image := Image{Type: getRecommondType(recommond)} + _, err := x.ID(imageId).Cols("type").Update(image) + return err +} + +func getRecommondType(recommond bool) int { + if recommond { + + return RECOMMOND_TYPE + } else { + return NORMAL_TYPE + } + +} diff --git a/models/models.go b/models/models.go index 36527f78d..57137448d 100755 --- a/models/models.go +++ b/models/models.go @@ -131,6 +131,8 @@ func init() { new(Dataset), new(DatasetStar), new(Cloudbrain), + new(Image), + new(ImageStar), new(FileChunk), new(BlockChain), new(RecommendOrg), diff --git a/modules/auth/cloudbrain.go b/modules/auth/cloudbrain.go index 9949feddc..2f345e6c5 100755 --- a/modules/auth/cloudbrain.go +++ b/modules/auth/cloudbrain.go @@ -24,9 +24,27 @@ type CreateCloudBrainForm struct { type CommitImageCloudBrainForm struct { Description string `form:"description" binding:"Required"` - Tag string `form:"tag" binding:"Required"` + Type int `form:"type" binding:"Required"` + Tag string `form:"tag" binding:"Required;MaxSize(64)" ` + IsPrivate bool `form:"isPrivate" binding:"Required"` + Topics string `form:"topics"` +} + +type EditImageCloudBrainForm struct { + ID int64 `form:"id" binding:"Required"` + Description string `form:"description" binding:"Required"` + IsPrivate bool `form:"isPrivate" binding:"Required"` + Topics string `form:"topics"` } func (f *CreateCloudBrainForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors { return validate(errs, ctx.Data, f, ctx.Locale) } + +func (f *CommitImageCloudBrainForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors { + return validate(errs, ctx.Data, f, ctx.Locale) +} + +func (f *EditImageCloudBrainForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors { + return validate(errs, ctx.Data, f, ctx.Locale) +} diff --git a/modules/cloudbrain/cloudbrain.go b/modules/cloudbrain/cloudbrain.go index 9aae447b0..d10fe4e22 100755 --- a/modules/cloudbrain/cloudbrain.go +++ b/modules/cloudbrain/cloudbrain.go @@ -83,6 +83,18 @@ func isAdminOrJobCreater(ctx *context.Context, job *models.Cloudbrain, err error } +func isAdminOrImageCreater(ctx *context.Context, image *models.Image, err error) bool { + if !ctx.IsSigned { + return false + } + if err != nil { + return ctx.IsUserSiteAdmin() + } else { + return ctx.IsUserSiteAdmin() || ctx.User.ID == image.UID + } + +} + func AdminOrOwnerOrJobCreaterRight(ctx *context.Context) { var ID = ctx.Params(":id") @@ -147,6 +159,28 @@ func AdminOrJobCreaterRightForTrain(ctx *context.Context) { } +func AdminOrImageCreaterRight(ctx *context.Context) { + + id, err := strconv.ParseInt(ctx.Params(":id"), 10, 64) + var image *models.Image + if err != nil { + log.Error("Get Image by ID failed:%v", err.Error()) + + } else { + image, err = models.GetImageByID(id) + if err != nil { + log.Error("Get Image by ID failed:%v", err.Error()) + return + } + } + + if !isAdminOrImageCreater(ctx, image, err) { + log.Error("!isAdminOrImageCreater error:%v", err.Error()) + ctx.NotFound(ctx.Req.URL.RequestURI(), nil) + } + +} + func GenerateTask(ctx *context.Context, displayJobName, jobName, image, command, uuid, codePath, modelPath, benchmarkPath, snn4imagenetPath, brainScorePath, jobType, gpuQueue, description string, benchmarkTypeID, benchmarkChildTypeID, resourceSpecId int) error { dataActualPath := setting.Attachment.Minio.RealPath + setting.Attachment.Minio.Bucket + "/" + diff --git a/modules/cloudbrain/resty.go b/modules/cloudbrain/resty.go index 46b7c991b..d3ce40191 100755 --- a/modules/cloudbrain/resty.go +++ b/modules/cloudbrain/resty.go @@ -210,6 +210,17 @@ func getQueryString(page int, size int, name string) string { } func CommitImage(jobID string, params models.CommitImageParams) error { + + has, err := models.IsImageExist(params.ImageTag) + if err != nil { + return fmt.Errorf("resty CommitImage: %v", err) + } + if has { + return models.ErrorImageTagExist{ + Tag: params.ImageTag, + } + } + checkSetting() client := getRestyClient() var result models.CommitImageResult @@ -220,7 +231,7 @@ sendjob: res, err := client.R(). SetHeader("Content-Type", "application/json"). SetAuthToken(TOKEN). - SetBody(params). + SetBody(params.CommitImageCloudBrainParams). SetResult(&result). Post(HOST + "/rest-server/api/v1/jobs/" + jobID + "/commitImage") @@ -238,7 +249,27 @@ sendjob: return fmt.Errorf("CommitImage err: %s", res.String()) } - return nil + err = models.WithTx(func(ctx models.DBContext) error { + image := models.Image{ + Type: models.NORMAL_TYPE, + CloudbrainType: params.CloudBrainType, + UID: params.UID, + IsPrivate: params.IsPrivate, + Tag: params.ImageTag, + Description: params.ImageDescription, + Place: setting.Cloudbrain.ImageURLPrefix + params.ImageTag, + } + if err := models.CreateLocalImage(&image); err != nil { + log.Error("Failed to insert image record.", err) + return fmt.Errorf("CommitImage err: %s", res.String()) + } + if err := models.SaveImageTopics(image.ID, params.Topics...); err != nil { + log.Error("Failed to insert image record.", err) + return fmt.Errorf("CommitImage err: %s", res.String()) + } + return nil + }) + return err } func StopJob(jobID string) error { diff --git a/modules/setting/cloudbrain.go b/modules/setting/cloudbrain.go index c0ab3b275..2d80eea25 100755 --- a/modules/setting/cloudbrain.go +++ b/modules/setting/cloudbrain.go @@ -1,9 +1,10 @@ package setting type CloudbrainLoginConfig struct { - Username string - Password string - Host string + Username string + Password string + Host string + ImageURLPrefix string } var ( @@ -15,5 +16,6 @@ func GetCloudbrainConfig() CloudbrainLoginConfig { Cloudbrain.Username = cloudbrainSec.Key("USERNAME").MustString("") Cloudbrain.Password = cloudbrainSec.Key("PASSWORD").MustString("") Cloudbrain.Host = cloudbrainSec.Key("REST_SERVER_HOST").MustString("") + Cloudbrain.ImageURLPrefix = cloudbrainSec.Key("IMAGE_URL_PREFIX").MustString("") return Cloudbrain } diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index a990e9aee..10a105627 100755 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -878,7 +878,7 @@ readme_helper = Select a README file template. auto_init = Initialize Repository (Adds .gitignore, License and README) create_repo = Create Repository create_course = Publish Course -failed_to_create_course=Fail to publish course, please try again later. +failed_to_create_course=Failed to publish course, please try again later. default_branch = Default Branch mirror_prune = Prune mirror_prune_desc = Remove obsolete remote-tracking references @@ -912,6 +912,8 @@ more=More gpu_type_all=All model_download=Model Download submit_image=Submit Image +image_exist=Image name has been used, please use a new one. +image_commit_fail=Failed to submit image, please try again later. download=Download score=Score @@ -948,7 +950,7 @@ total_count_get_error=Can not get the total page. last_update_time_error=Can not get the last updated time. get_repo_stat_error=Can not get the statistics of the repository. get_repo_info_error=Can not get the information of the repository. -generate_statistic_file_error=Fail to generate file. +generate_statistic_file_error=Failed to generate file. repo_stat_inspect=ProjectAnalysis all=All @@ -1097,7 +1099,7 @@ form.name_reserved = The repository name '%s' is reserved. form.course_name_reserved=The course name '%s' is reserved. form.name_pattern_not_allowed = The pattern '%s' is not allowed in a repository name. form.course_name_pattern_not_allowed=The pattern '%s' is not allowed in a course name. -add_course_org_fail=Fail to add organization, please try again later. +add_course_org_fail=Failed to add organization, please try again later. need_auth = Clone Authorization migrate_type = Migration Type diff --git a/options/locale/locale_zh-CN.ini b/options/locale/locale_zh-CN.ini index 4e73fbad5..c2f81e4dd 100755 --- a/options/locale/locale_zh-CN.ini +++ b/options/locale/locale_zh-CN.ini @@ -917,6 +917,8 @@ more=更多 gpu_type_all=全部 model_download=结果下载 submit_image=提交镜像 +image_exist=镜像名称已被使用,请修改镜像名称。 +image_commit_fail=提交镜像失败,请稍后再试。 download=模型下载 score=评分 @@ -2142,8 +2144,8 @@ branch.included=已包含 topic.manage_topics=管理主题 topic.done=保存 -topic.count_prompt=您最多选择25个主题 -topic.format_prompt=主题必须以中文、字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符 +topic.count_prompt=您最多选择25个标签 +topic.format_prompt=标签必须以中文、字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符 [org] org_name_holder=组织名称 diff --git a/routers/admin/cloudbrains.go b/routers/admin/cloudbrains.go index 6bbd534b9..86e81cb87 100644 --- a/routers/admin/cloudbrains.go +++ b/routers/admin/cloudbrains.go @@ -20,6 +20,7 @@ import ( const ( tplCloudBrains base.TplName = "admin/cloudbrain/list" + tplImages base.TplName = "admin/cloudbrain/images" EXCEL_DATE_FORMAT = "20060102150405" CREATE_TIME_FORMAT = "2006/01/02 15:04:05" ) @@ -107,6 +108,11 @@ func CloudBrains(ctx *context.Context) { } +func Images(ctx *context.Context) { + ctx.HTML(200, tplImages) + +} + func DownloadCloudBrains(ctx *context.Context) { page := 1 diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index fc1dbfbd0..4d1b08418 100755 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -37,6 +37,8 @@ const ( tplCloudBrainBenchmarkIndex base.TplName = "repo/cloudbrain/benchmark/index" tplCloudBrainBenchmarkNew base.TplName = "repo/cloudbrain/benchmark/new" tplCloudBrainBenchmarkShow base.TplName = "repo/cloudbrain/benchmark/show" + tplCloudBrainImageSubmit base.TplName = "repo/cloudbrain/image/submit" + tplCloudBrainImageEdit base.TplName = "repo/cloudbrain/image/edit" ) var ( @@ -447,26 +449,84 @@ func CloudBrainDebug(ctx *context.Context) { ctx.Redirect(debugUrl) } +func CloudBrainCommitImageShow(ctx *context.Context) { + ctx.Data["PageIsCloudBrain"] = true + ctx.Data["Type"] = ctx.Cloudbrain.Type + ctx.HTML(200, tplCloudBrainImageSubmit) +} + +func CloudBrainImageEdit(ctx *context.Context) { + ctx.Data["PageIsImageEdit"] = true + ctx.Data["PageFrom"] = ctx.Params(":from") + var ID = ctx.Params(":id") + id, err := strconv.ParseInt(ID, 10, 64) + if err != nil { + log.Error("GetCloudbrainByID failed:%v", err.Error()) + ctx.NotFound(ctx.Req.URL.RequestURI(), nil) + + image, err := models.GetImageByID(id) + if err != nil { + log.Error("GetCloudbrainByID failed:%v", err.Error()) + ctx.NotFound(ctx.Req.URL.RequestURI(), nil) + } + ctx.Data["Image"] = image + ctx.HTML(http.StatusOK, tplCloudBrainImageSubmit) + } +} + +func CloudBrainImageEditPost(ctx *context.Context, form auth.EditImageCloudBrainForm) { + +} + +func CloudBrainImageDelete(ctx *context.Context) { + +} + func CloudBrainCommitImage(ctx *context.Context, form auth.CommitImageCloudBrainForm) { + + var topics = make([]string, 0) + var topicsStr = strings.TrimSpace(form.Topics) + if len(topicsStr) > 0 { + topics = strings.Split(topicsStr, ",") + } + + validTopics, invalidTopics := models.SanitizeAndValidateTopics(topics) + + if len(validTopics) > 25 { + ctx.JSON(200, models.BaseErrorMessage(ctx.Tr("repo.topic.count_prompt"))) + return + } + + if len(invalidTopics) > 0 { + ctx.JSON(200, models.BaseErrorMessage(ctx.Tr("repo.topic.format_prompt"))) + return + } + err := cloudbrain.CommitImage(ctx.Cloudbrain.JobID, models.CommitImageParams{ - Ip: ctx.Cloudbrain.ContainerIp, - TaskContainerId: ctx.Cloudbrain.ContainerID, - ImageDescription: form.Description, - ImageTag: form.Tag, + CommitImageCloudBrainParams: models.CommitImageCloudBrainParams{ + Ip: ctx.Cloudbrain.ContainerIp, + TaskContainerId: ctx.Cloudbrain.ContainerID, + ImageDescription: form.Description, + ImageTag: form.Tag, + }, + IsPrivate: form.IsPrivate, + CloudBrainType: form.Type, + Topics: validTopics, + UID: ctx.User.ID, }) if err != nil { log.Error("CommitImage(%s) failed:%v", ctx.Cloudbrain.JobName, err.Error(), ctx.Data["msgID"]) - ctx.JSON(200, map[string]string{ - "result_code": "-1", - "error_msg": "CommitImage failed", - }) + if models.IsErrImageTagExist(err) { + ctx.JSON(200, models.BaseErrorMessage(ctx.Tr("repo.image_exist"))) + + } else { + ctx.JSON(200, models.BaseErrorMessage(ctx.Tr("repo.image_commit_fail"))) + } + return } - ctx.JSON(200, map[string]string{ - "result_code": "0", - "error_msg": "", - }) + ctx.JSON(200, models.BaseOKMessage) } func CloudBrainStop(ctx *context.Context) { diff --git a/routers/routes/routes.go b/routers/routes/routes.go index c1ff24216..f12ebbab8 100755 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -330,6 +330,8 @@ func RegisterRoutes(m *macaron.Macaron) { }) m.Get("/images/public", repo.GetPublicImages) m.Get("/images/custom", repo.GetCustomImages) + m.Get("/images/star", repo.GetCustomImages) + m.Get("/repos", routers.ExploreRepos) m.Get("/datasets", routers.ExploreDatasets) m.Get("/users", routers.ExploreUsers) @@ -523,6 +525,9 @@ func RegisterRoutes(m *macaron.Macaron) { m.Get("", admin.CloudBrains) m.Get("/download", admin.DownloadCloudBrains) }) + m.Group("/images", func() { + m.Get("", admin.Images) + }) m.Group("/^:configType(hooks|system-hooks)$", func() { m.Get("", admin.DefaultOrSystemWebhooks) @@ -970,7 +975,12 @@ func RegisterRoutes(m *macaron.Macaron) { m.Group("/:username/:reponame", func() { m.Post("/topics", repo.TopicsPost) }, context.RepoAssignment(), context.RepoMustNotBeArchived(), reqRepoAdmin) - + + m.Group("/image/:id", func() { + m.Get("/:from", cloudbrain.AdminOrImageCreaterRight, repo.CloudBrainImageEdit) + m.Post("", cloudbrain.AdminOrImageCreaterRight, bindIgnErr(auth.EditImageCloudBrainForm{}), repo.CloudBrainImageEditPost) + m.Delete("", cloudbrain.AdminOrImageCreaterRight, repo.CloudBrainImageDelete) + }) m.Group("/:username/:reponame", func() { m.Group("", func() { m.Get("/^:type(issues|pulls)$", repo.Issues) @@ -1012,6 +1022,7 @@ func RegisterRoutes(m *macaron.Macaron) { m.Group("/:id", func() { m.Get("", reqRepoCloudBrainReader, repo.CloudBrainShow) m.Get("/debug", cloudbrain.AdminOrJobCreaterRight, repo.CloudBrainDebug) + m.Get("/commit_image", cloudbrain.AdminOrJobCreaterRight, repo.CloudBrainCommitImageShow) m.Post("/commit_image", cloudbrain.AdminOrJobCreaterRight, bindIgnErr(auth.CommitImageCloudBrainForm{}), repo.CloudBrainCommitImage) m.Post("/stop", cloudbrain.AdminOrOwnerOrJobCreaterRight, repo.CloudBrainStop) m.Post("/del", cloudbrain.AdminOrOwnerOrJobCreaterRight, repo.CloudBrainDel) From 1dbe882c47a4fee7090708e64b4f6ba792283b5b Mon Sep 17 00:00:00 2001 From: zhoupzh Date: Thu, 31 Mar 2022 10:51:14 +0800 Subject: [PATCH 023/256] fix issue --- templates/repo/cloudbrain/image/submit.tmpl | 5 +++++ templates/repo/debugjob/index.tmpl | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 templates/repo/cloudbrain/image/submit.tmpl diff --git a/templates/repo/cloudbrain/image/submit.tmpl b/templates/repo/cloudbrain/image/submit.tmpl new file mode 100644 index 000000000..c3ec70157 --- /dev/null +++ b/templates/repo/cloudbrain/image/submit.tmpl @@ -0,0 +1,5 @@ +{{template "base/head" .}} +
+ asdasd +
+{{template "base/footer" .}} \ No newline at end of file diff --git a/templates/repo/debugjob/index.tmpl b/templates/repo/debugjob/index.tmpl index ddcccc926..0bbe605bf 100755 --- a/templates/repo/debugjob/index.tmpl +++ b/templates/repo/debugjob/index.tmpl @@ -382,7 +382,7 @@ {{if .CanDebug}} - {{$.i18n.Tr "repo.submit_image"}} + {{$.i18n.Tr "repo.submit_image"}} {{else}} {{$.i18n.Tr "repo.submit_image"}} {{end}} From 294f056306eab69ebb67698e43c2c37157923c2c Mon Sep 17 00:00:00 2001 From: ychao_1983 Date: Thu, 31 Mar 2022 16:25:15 +0800 Subject: [PATCH 024/256] =?UTF-8?q?=E9=95=9C=E5=83=8F=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=90=8E=E7=AB=AF=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/cloudbrain_image.go | 197 +++++++++++++++++++++----------- models/models.go | 2 + modules/convert/convert.go | 10 ++ modules/structs/repo_topic.go | 8 ++ options/locale/locale_en-US.ini | 3 + options/locale/locale_zh-CN.ini | 3 + routers/api/v1/api.go | 3 + routers/api/v1/repo/topic.go | 60 ++++++++++ routers/repo/cloudbrain.go | 173 +++++++++++++++++++++++----- routers/routes/routes.go | 3 +- 10 files changed, 367 insertions(+), 95 deletions(-) diff --git a/models/cloudbrain_image.go b/models/cloudbrain_image.go index a6ca35f29..8a06e2d8c 100644 --- a/models/cloudbrain_image.go +++ b/models/cloudbrain_image.go @@ -13,20 +13,23 @@ const RECOMMOND_TYPE = 5 const NORMAL_TYPE = 0 type Image struct { - ID int64 `xorm:"pk autoincr"` - Type int `xorm:"INDEX NOT NULL"` //0 normal 5官方推荐,中间值保留为后续扩展 - CloudbrainType int `xorm:"INDEX NOT NULL"` //0 云脑一 1云脑二 - UID int64 `xorm:"INDEX NOT NULL"` - IsPrivate bool `xorm:"INDEX NOT NULL"` - Tag string `xorm:"varchar(100) UNIQUE"` - Description string `xorm:"varchar(765)"` - Topics []string `xorm:"TEXT JSON"` - Place string `xorm:"varchar(300)"` - NumStars int `xorm:"NOT NULL DEFAULT 0"` - CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"` - UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"` + ID int64 `xorm:"pk autoincr" json:"id"` + Type int `xorm:"INDEX NOT NULL" json:"type"` //0 normal 5官方推荐,中间值保留为后续扩展 + CloudbrainType int `xorm:"INDEX NOT NULL" json:"cloudbrainType"` //0 云脑一 1云脑二 + UID int64 `xorm:"INDEX NOT NULL" json:"uid"` + IsPrivate bool `xorm:"INDEX NOT NULL" json:"isPrivate"` + Tag string `xorm:"varchar(100) UNIQUE" json:"tag"` + Description string `xorm:"varchar(765)" json:"description"` + Topics []string `xorm:"TEXT JSON" json:"topics"` + Place string `xorm:"varchar(300)" json:"place"` + NumStars int `xorm:"NOT NULL DEFAULT 0" json:"numStars"` + Creator *User `xorm:"-" json:"creator"` + CreatedUnix timeutil.TimeStamp `xorm:"INDEX created" json:"createdUnix"` + UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated" json:"updatedUnix"` } +type ImageList []*Image + type ImageStar struct { ID int64 `xorm:"pk autoincr"` UID int64 `xorm:"UNIQUE(s)"` @@ -48,14 +51,14 @@ type ImageTopicRelation struct { } type SearchImageOptions struct { - Keyword string - UID int64 - IncludePublic bool - IncludeStarByMe bool - IncludeCustom bool - CodeLanguage string - Framework string - CudaVersion string + Keyword string + UID int64 + IncludePublicOnly bool + IncludePrivateOnly bool + IncludeStarByMe bool + IncludeCustom bool + IncludeOwnerOnly bool + Topics string ListOptions SearchOrderBy } @@ -63,6 +66,11 @@ type ErrorImageTagExist struct { Tag string } +type ImagesPageResult struct { + Count int64 `json:"count"` + Images []*Image `json:"images"` +} + func (err ErrorImageTagExist) Error() string { return fmt.Sprintf("Image already exists [tag: %s]", err.Tag) } @@ -251,58 +259,80 @@ func removeTopicFromImage(e Engine, imageId int64, topic *ImageTopic) error { return nil } -/*func SearchImage(opts *SearchImageOptions) ([]*Image, int64, error) { +func SearchImage(opts *SearchImageOptions) (ImageList, int64, error) { cond := SearchImageCondition(opts) return SearchImageByCondition(opts, cond) -}*/ +} func SearchImageCondition(opts *SearchImageOptions) builder.Cond { var cond = builder.NewCond() if len(opts.Keyword) > 0 { - cond = cond.And(builder.Or(builder.Like{"image.tag", opts.Keyword}, builder.Like{"image.description", opts.Keyword})) - } - if len(opts.CudaVersion) > 0 { - cond = cond.And(builder.Eq{"image.cuda_version": opts.CudaVersion}) + var subQueryCond = builder.NewCond() + for _, v := range strings.Split(opts.Keyword, ",") { + + subQueryCond = subQueryCond.Or(builder.Like{"LOWER(image_topic.name)", strings.ToLower(v)}) + + } + subQuery := builder.Select("image_topic_relation.image_id").From("image_topic_relation"). + Join("INNER", "image_topic", "image_topic.id = image_topic_relation.image_id"). + Where(subQueryCond). + GroupBy("image_topic_relation.image_id") + var keywordCond = builder.In("id", subQuery) + + var likes = builder.NewCond() + for _, v := range strings.Split(opts.Keyword, ",") { + likes = likes.Or(builder.Like{"LOWER(tag)", strings.ToLower(v)}) + + likes = likes.Or(builder.Like{"LOWER(description)", strings.ToLower(v)}) + + } + keywordCond = keywordCond.Or(likes) + + cond = cond.And(keywordCond) + + } + if len(opts.Topics) > 0 { //标签精确匹配 + var subQueryCond = builder.NewCond() + for _, v := range strings.Split(opts.Keyword, ",") { + + subQueryCond = subQueryCond.Or(builder.Eq{"LOWER(image_topic.name)": strings.ToLower(v)}) + subQuery := builder.Select("image_topic_relation.image_id").From("image_topic_relation"). + Join("INNER", "image_topic", "image_topic.id = image_topic_relation.image_id"). + Where(subQueryCond). + GroupBy("image_topic_relation.image_id") + var topicCond = builder.In("id", subQuery) + cond = cond.And(topicCond) + } } - if len(opts.CodeLanguage) > 0 { - cond = cond.And(builder.Eq{"image.code_language": opts.CodeLanguage}) + if opts.IncludePublicOnly { + cond = cond.And(builder.Eq{"is_private": false}) } - if len(opts.Framework) > 0 { - cond = cond.And(builder.Eq{"image.framework": opts.Framework}) + + if opts.IncludePrivateOnly { + cond = cond.And(builder.Eq{"is_private": true}) } - if opts.IncludePublic { - cond = cond.And(builder.Eq{"image.is_private": false}) + if opts.IncludeOwnerOnly { + + cond = cond.And(builder.Eq{"uid": opts.UID}) } - /** + if opts.IncludeStarByMe { - cond = cond.And(builder.Eq{"dataset.status": DatasetStatusPublic}) - cond = cond.And(builder.Eq{"attachment.is_private": false}) - if opts.OwnerID > 0 { - if len(opts.Keyword) == 0 { - cond = cond.Or(builder.Eq{"repository.owner_id": opts.OwnerID}) - } else { - subCon := builder.NewCond() - subCon = subCon.And(builder.Eq{"repository.owner_id": opts.OwnerID}, builder.Or(builder.Like{"dataset.title", opts.Keyword}, builder.Like{"dataset.description", opts.Keyword})) - cond = cond.Or(subCon) - } - } - } else if opts.OwnerID > 0 { - cond = cond.And(builder.Eq{"repository.owner_id": opts.OwnerID}) - if !opts.IsOwner { - cond = cond.And(builder.Eq{"dataset.status": DatasetStatusPublic}) - cond = cond.And(builder.Eq{"attachment.is_private": false}) - } - }*/ + subQuery := builder.Select("image_id").From("image_star"). + Where(builder.Eq{"uid": opts.UID}) + var starCond = builder.In("id", subQuery) + cond = cond.And(starCond) + + } return cond } -/*func SearchImageByCondition(opts *SearchImageOptions, cond builder.Cond) ([]*Image, int64, error) { +func SearchImageByCondition(opts *SearchImageOptions, cond builder.Cond) (ImageList, int64, error) { if opts.Page <= 0 { opts.Page = 1 } @@ -311,34 +341,57 @@ func SearchImageCondition(opts *SearchImageOptions) builder.Cond { sess := x.NewSession() defer sess.Close() - datasets := make(DatasetList, 0, opts.PageSize) - selectColumnsSql := "distinct dataset.id,dataset.title, dataset.status, dataset.category, dataset.description, dataset.download_times, dataset.license, dataset.task, dataset.release_id, dataset.user_id, dataset.repo_id, dataset.created_unix,dataset.updated_unix,dataset.num_stars" - - count, err := sess.Distinct("dataset.id").Join("INNER", "repository", "repository.id = dataset.repo_id"). - Join("INNER", "attachment", "attachment.dataset_id=dataset.id"). - Where(cond).Count(new(Dataset)) + images := make(ImageList, 0, opts.PageSize) + count, err := sess.Where(cond).Count(new(Image)) if err != nil { return nil, 0, fmt.Errorf("Count: %v", err) } - sess.Select(selectColumnsSql).Join("INNER", "repository", "repository.id = dataset.repo_id"). - Join("INNER", "attachment", "attachment.dataset_id=dataset.id"). - Where(cond).OrderBy(opts.SearchOrderBy.String()) + sess.Where(cond).OrderBy(opts.SearchOrderBy.String()) if opts.PageSize > 0 { sess.Limit(opts.PageSize, (opts.Page-1)*opts.PageSize) } - if err = sess.Find(&datasets); err != nil { - return nil, 0, fmt.Errorf("Dataset: %v", err) + if err = sess.Find(&images); err != nil { + return nil, 0, fmt.Errorf("Images: %v", err) } - if err = datasets.loadAttributes(sess); err != nil { + if err = images.loadAttributes(sess); err != nil { return nil, 0, fmt.Errorf("LoadAttributes: %v", err) } - return datasets, count, nil -}*/ + return images, count, nil +} + +func (images ImageList) loadAttributes(e Engine) error { + if len(images) == 0 { + return nil + } + + set := make(map[int64]struct{}) + + for i := range images { + set[images[i].UID] = struct{}{} + } + + // Load creators. + users := make(map[int64]*User, len(set)) + if err := e.Table("\"user\""). + Cols("name", "lower_name", "avatar", "email"). + Where("id > 0"). + In("id", keysInt64(set)). + Find(&users); err != nil { + return fmt.Errorf("find users: %v", err) + } + + for i := range images { + images[i].Creator = users[images[i].UID] + + } + + return nil +} func CreateLocalImage(image *Image) error { @@ -346,6 +399,18 @@ func CreateLocalImage(image *Image) error { return err } +func UpdateLocalImage(image *Image) error { + + _, err := x.ID(image.ID).Update(image) + return err +} + +func DeleteLocalImage(id int64) error { + image := new(Image) + _, err := x.ID(id).Delete(image) + return err +} + //star or unstar Image func StarImage(userID, imageID int64, star bool) error { sess := x.NewSession() diff --git a/models/models.go b/models/models.go index 57137448d..b00263982 100755 --- a/models/models.go +++ b/models/models.go @@ -133,6 +133,8 @@ func init() { new(Cloudbrain), new(Image), new(ImageStar), + new(ImageTopic), + new(ImageTopicRelation), new(FileChunk), new(BlockChain), new(RecommendOrg), diff --git a/modules/convert/convert.go b/modules/convert/convert.go index fa2e8f2e7..a542fe78b 100755 --- a/modules/convert/convert.go +++ b/modules/convert/convert.go @@ -403,6 +403,16 @@ func ToTopicResponse(topic *models.Topic) *api.TopicResponse { } } +func ToImageTopicResponse(topic *models.ImageTopic) *api.ImageTopicResponse { + return &api.ImageTopicResponse{ + ID: topic.ID, + Name: topic.Name, + ImageCount: topic.ImageCount, + Created: topic.CreatedUnix.AsTime(), + Updated: topic.UpdatedUnix.AsTime(), + } +} + // ToOAuth2Application convert from models.OAuth2Application to api.OAuth2Application func ToOAuth2Application(app *models.OAuth2Application) *api.OAuth2Application { return &api.OAuth2Application{ diff --git a/modules/structs/repo_topic.go b/modules/structs/repo_topic.go index 294d56a95..6fb6a92b4 100644 --- a/modules/structs/repo_topic.go +++ b/modules/structs/repo_topic.go @@ -17,6 +17,14 @@ type TopicResponse struct { Updated time.Time `json:"updated"` } +type ImageTopicResponse struct { + ID int64 `json:"id"` + Name string `json:"topic_name"` + ImageCount int `json:"image_count"` + Created time.Time `json:"created"` + Updated time.Time `json:"updated"` +} + // TopicName a list of repo topic names type TopicName struct { TopicNames []string `json:"topics"` diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 10a105627..71148c801 100755 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -914,6 +914,9 @@ model_download=Model Download submit_image=Submit Image image_exist=Image name has been used, please use a new one. image_commit_fail=Failed to submit image, please try again later. +image_not_exist=Image does not exits. +image_edit_fail=Failed to edit image, please try again later. +image_delete_fail=Failed to delete image, please try again later. download=Download score=Score diff --git a/options/locale/locale_zh-CN.ini b/options/locale/locale_zh-CN.ini index c2f81e4dd..57f3dc35b 100755 --- a/options/locale/locale_zh-CN.ini +++ b/options/locale/locale_zh-CN.ini @@ -919,6 +919,9 @@ model_download=结果下载 submit_image=提交镜像 image_exist=镜像名称已被使用,请修改镜像名称。 image_commit_fail=提交镜像失败,请稍后再试。 +image_not_exist=镜像不存在。 +image_edit_fail=编辑镜像失败,请稍后再试。 +image_delete_fail=删除镜像失败,请稍后再试。 download=模型下载 score=评分 diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 306854af3..32b7556af 100755 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -997,6 +997,9 @@ func RegisterRoutes(m *macaron.Macaron) { m.Group("/topics", func() { m.Get("/search", repo.TopicSearch) }) + m.Group("/image/topics", func() { + m.Get("/search", repo.ImageTopicSearch) + }) m.Group("/from_wechat", func() { m.Get("/event", authentication.ValidEventSource) m.Post("/event", authentication.AcceptWechatEvent) diff --git a/routers/api/v1/repo/topic.go b/routers/api/v1/repo/topic.go index 530b92a10..f4ff7a329 100644 --- a/routers/api/v1/repo/topic.go +++ b/routers/api/v1/repo/topic.go @@ -300,3 +300,63 @@ func TopicSearch(ctx *context.APIContext) { "topics": topicResponses, }) } + +func ImageTopicSearch(ctx *context.APIContext) { + // swagger:operation GET /image/topics/search image topicSearch + // --- + // summary: search topics via keyword + // produces: + // - application/json + // parameters: + // - name: q + // in: query + // description: keywords to search + // required: true + // type: string + // - name: page + // in: query + // description: page number of results to return (1-based) + // type: integer + // - name: limit + // in: query + // description: page size of results, maximum page size is 50 + // type: integer + // responses: + // "200": + // "$ref": "#/responses/TopicListResponse" + // "403": + // "$ref": "#/responses/forbidden" + + if ctx.User == nil { + ctx.Error(http.StatusForbidden, "UserIsNil", "Only owners could change the topics.") + return + } + + kw := ctx.Query("q") + + listOptions := utils.GetListOptions(ctx) + if listOptions.Page < 1 { + listOptions.Page = 1 + } + if listOptions.PageSize < 1 { + listOptions.PageSize = 10 + } + + topics, err := models.FindImageTopics(&models.FindImageTopicOptions{ + Keyword: kw, + ListOptions: listOptions, + }) + if err != nil { + log.Error("SearchImageTopics failed: %v", err) + ctx.InternalServerError(err) + return + } + + topicResponses := make([]*api.ImageTopicResponse, len(topics)) + for i, topic := range topics { + topicResponses[i] = convert.ToImageTopicResponse(topic) + } + ctx.JSON(http.StatusOK, map[string]interface{}{ + "topics": topicResponses, + }) +} diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index 4d1b08418..cd322ba52 100755 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -461,12 +461,12 @@ func CloudBrainImageEdit(ctx *context.Context) { var ID = ctx.Params(":id") id, err := strconv.ParseInt(ID, 10, 64) if err != nil { - log.Error("GetCloudbrainByID failed:%v", err.Error()) + log.Error("GetImageByID failed:%v", err.Error()) ctx.NotFound(ctx.Req.URL.RequestURI(), nil) image, err := models.GetImageByID(id) if err != nil { - log.Error("GetCloudbrainByID failed:%v", err.Error()) + log.Error("GetImageByID failed:%v", err.Error()) ctx.NotFound(ctx.Req.URL.RequestURI(), nil) } ctx.Data["Image"] = image @@ -476,29 +476,62 @@ func CloudBrainImageEdit(ctx *context.Context) { func CloudBrainImageEditPost(ctx *context.Context, form auth.EditImageCloudBrainForm) { -} + validTopics, errMessage := checkTopics(form.Topics) + if errMessage != "" { + ctx.JSON(http.StatusOK, models.BaseErrorMessage(ctx.Tr(errMessage))) + return + } + image, err := models.GetImageByID(form.ID) + if err != nil { + ctx.JSON(http.StatusOK, models.BaseErrorMessage(ctx.Tr("repo.image_not_exist"))) -func CloudBrainImageDelete(ctx *context.Context) { + } -} + image.IsPrivate = form.IsPrivate + image.Description = form.Description -func CloudBrainCommitImage(ctx *context.Context, form auth.CommitImageCloudBrainForm) { + err = models.WithTx(func(ctx models.DBContext) error { + if err := models.UpdateLocalImage(image); err != nil { + return err + } + if err := models.SaveImageTopics(image.ID, validTopics...); err != nil { + return err + } + return nil - var topics = make([]string, 0) - var topicsStr = strings.TrimSpace(form.Topics) - if len(topicsStr) > 0 { - topics = strings.Split(topicsStr, ",") + }) + + if err != nil { + ctx.JSON(http.StatusOK, models.BaseErrorMessage(ctx.Tr("repo.image_not_exist"))) + + } else { + ctx.JSON(http.StatusOK, models.BaseOKMessage) } - validTopics, invalidTopics := models.SanitizeAndValidateTopics(topics) +} - if len(validTopics) > 25 { - ctx.JSON(200, models.BaseErrorMessage(ctx.Tr("repo.topic.count_prompt"))) +func CloudBrainImageDelete(ctx *context.Context) { + var ID = ctx.Params(":id") + id, err := strconv.ParseInt(ID, 10, 64) + if err != nil { + ctx.JSON(http.StatusOK, models.BaseErrorMessage(ctx.Tr("repo.image_not_exist"))) return } - if len(invalidTopics) > 0 { - ctx.JSON(200, models.BaseErrorMessage(ctx.Tr("repo.topic.format_prompt"))) + err = models.DeleteLocalImage(id) + if err != nil { + ctx.JSON(http.StatusOK, models.BaseErrorMessage(ctx.Tr("repo.image_delete_fail"))) + } else { + ctx.JSON(http.StatusOK, models.BaseOKMessage) + } + +} + +func CloudBrainCommitImage(ctx *context.Context, form auth.CommitImageCloudBrainForm) { + + validTopics, errMessage := checkTopics(form.Topics) + if errMessage != "" { + ctx.JSON(http.StatusOK, ctx.Tr(errMessage)) return } @@ -529,6 +562,27 @@ func CloudBrainCommitImage(ctx *context.Context, form auth.CommitImageCloudBrain ctx.JSON(200, models.BaseOKMessage) } +func checkTopics(Topics string) ([]string, string) { + var topics = make([]string, 0) + var topicsStr = strings.TrimSpace(Topics) + if len(topicsStr) > 0 { + topics = strings.Split(topicsStr, ",") + } + + validTopics, invalidTopics := models.SanitizeAndValidateTopics(topics) + + if len(validTopics) > 25 { + return nil, "repo.topic.count_prompt" + + } + + if len(invalidTopics) > 0 { + return nil, "repo.topic.count_prompt" + + } + return validTopics, "" +} + func CloudBrainStop(ctx *context.Context) { var ID = ctx.Params(":id") var resultCode = "0" @@ -743,34 +797,97 @@ func CloudBrainShowModels(ctx *context.Context) { func GetPublicImages(ctx *context.Context) { - getImages(ctx, cloudbrain.Public) + opts := models.SearchImageOptions{ + IncludePrivateOnly: true, + UID: -1, + Keyword: ctx.Query("q"), + Topics: ctx.Query("topic"), + SearchOrderBy: "type desc, num_stars desc", + } + + getImages(ctx, &opts) } func GetCustomImages(ctx *context.Context) { + var uid int64 = -1 + if ctx.IsSigned { + uid = ctx.User.ID + } + opts := models.SearchImageOptions{ + UID: uid, + IncludeOwnerOnly: true, + Keyword: ctx.Query("q"), + Topics: ctx.Query("topic"), + SearchOrderBy: "id desc", + } + getImages(ctx, &opts) + +} +func GetStarImages(ctx *context.Context) { - getImages(ctx, cloudbrain.Custom) + var uid int64 = -1 + if ctx.IsSigned { + uid = ctx.User.ID + } + opts := models.SearchImageOptions{ + UID: uid, + IncludeStarByMe: true, + Keyword: ctx.Query("q"), + Topics: ctx.Query("topic"), + SearchOrderBy: "id desc", + } + getImages(ctx, &opts) } -func getImages(ctx *context.Context, imageType string) { - log.Info("Get images begin") +func GetAllImages(ctx *context.Context) { + + opts := models.SearchImageOptions{ + UID: -1, + Keyword: ctx.Query("q"), + Topics: ctx.Query("topic"), + SearchOrderBy: "id desc", + } + + if ctx.Query("private") != "" { + if ctx.QueryBool("private") { + opts.IncludePrivateOnly = true + } else { + opts.IncludePublicOnly = true + } + } + getImages(ctx, &opts) + +} +func getImages(ctx *context.Context, opts *models.SearchImageOptions) { page := ctx.QueryInt("page") - size := ctx.QueryInt("size") - name := ctx.Query("name") - getImagesResult, err := cloudbrain.GetImagesPageable(page, size, imageType, name) + if page <= 0 { + page = 1 + } + + pageSize := ctx.QueryInt("pageSize") + if pageSize <= 0 { + pageSize = 15 + } + opts.ListOptions = models.ListOptions{ + Page: page, + PageSize: pageSize, + } + imageList, total, err := models.SearchImage(opts) if err != nil { log.Error("Can not get images:%v", err) - ctx.JSON(http.StatusOK, models.GetImagesPayload{ - Count: 0, - TotalPages: 0, - ImageInfo: []*models.ImageInfo{}, + ctx.JSON(http.StatusOK, models.ImagesPageResult{ + Count: 0, + Images: []*models.Image{}, }) } else { - ctx.JSON(http.StatusOK, getImagesResult.Payload) + ctx.JSON(http.StatusOK, models.ImagesPageResult{ + Count: total, + Images: imageList, + }) } - log.Info("Get images end") } func GetModelDirs(jobName string, parentDir string) (string, error) { diff --git a/routers/routes/routes.go b/routers/routes/routes.go index f12ebbab8..f847cb8be 100755 --- a/routers/routes/routes.go +++ b/routers/routes/routes.go @@ -330,7 +330,7 @@ func RegisterRoutes(m *macaron.Macaron) { }) m.Get("/images/public", repo.GetPublicImages) m.Get("/images/custom", repo.GetCustomImages) - m.Get("/images/star", repo.GetCustomImages) + m.Get("/images/star", repo.GetStarImages) m.Get("/repos", routers.ExploreRepos) m.Get("/datasets", routers.ExploreDatasets) @@ -527,6 +527,7 @@ func RegisterRoutes(m *macaron.Macaron) { }) m.Group("/images", func() { m.Get("", admin.Images) + m.Get("/data", repo.GetAllImages) }) m.Group("/^:configType(hooks|system-hooks)$", func() { From c89713bcf6a996f8247cd60930ef4d87ef84372c Mon Sep 17 00:00:00 2001 From: ychao_1983 Date: Thu, 31 Mar 2022 16:44:47 +0800 Subject: [PATCH 025/256] =?UTF-8?q?=E6=94=AF=E6=8C=81=E4=BB=85=E5=AE=98?= =?UTF-8?q?=E6=96=B9=E6=8E=A8=E8=8D=90=E7=9A=84=E8=BF=87=E6=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/cloudbrain_image.go | 20 ++++++++++++-------- routers/repo/cloudbrain.go | 11 ++++++----- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/models/cloudbrain_image.go b/models/cloudbrain_image.go index 8a06e2d8c..f651a5ce1 100644 --- a/models/cloudbrain_image.go +++ b/models/cloudbrain_image.go @@ -51,14 +51,15 @@ type ImageTopicRelation struct { } type SearchImageOptions struct { - Keyword string - UID int64 - IncludePublicOnly bool - IncludePrivateOnly bool - IncludeStarByMe bool - IncludeCustom bool - IncludeOwnerOnly bool - Topics string + Keyword string + UID int64 + IncludePublicOnly bool + IncludeOfficialOnly bool + IncludePrivateOnly bool + IncludeStarByMe bool + IncludeCustom bool + IncludeOwnerOnly bool + Topics string ListOptions SearchOrderBy } @@ -319,6 +320,9 @@ func SearchImageCondition(opts *SearchImageOptions) builder.Cond { cond = cond.And(builder.Eq{"uid": opts.UID}) } + if opts.IncludeOfficialOnly { + cond = cond.And(builder.Eq{"type": RECOMMOND_TYPE}) + } if opts.IncludeStarByMe { diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index cd322ba52..076fe36b4 100755 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -798,11 +798,12 @@ func CloudBrainShowModels(ctx *context.Context) { func GetPublicImages(ctx *context.Context) { opts := models.SearchImageOptions{ - IncludePrivateOnly: true, - UID: -1, - Keyword: ctx.Query("q"), - Topics: ctx.Query("topic"), - SearchOrderBy: "type desc, num_stars desc", + IncludePrivateOnly: true, + UID: -1, + Keyword: ctx.Query("q"), + Topics: ctx.Query("topic"), + IncludeOfficialOnly: ctx.QueryBool("recommend"), + SearchOrderBy: "type desc, num_stars desc", } getImages(ctx, &opts) From c968c489247112537ba42868c0c060961742bc56 Mon Sep 17 00:00:00 2001 From: zhoupzh Date: Thu, 31 Mar 2022 17:14:12 +0800 Subject: [PATCH 026/256] fix issue --- options/locale/locale_en-US.ini | 5 + options/locale/locale_zh-CN.ini | 6 + templates/repo/cloudbrain/image/submit.tmpl | 116 +++++++++++++++++++- templates/repo/createCourse.tmpl | 2 +- templates/repo/debugjob/index.tmpl | 2 +- web_src/js/features/images.js | 26 +++++ 6 files changed, 152 insertions(+), 5 deletions(-) create mode 100644 web_src/js/features/images.js diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 10a105627..422b14302 100755 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -917,6 +917,11 @@ image_commit_fail=Failed to submit image, please try again later. download=Download score=Score +images.name = Image Name +images.name_placerholder = Please enter the image name +image.label_tooltips = Example Python 3.7, Tensorflow 2.0, cuda 10, pytorch 1.6 +images.public_tooltips = After the image is set to public, it can be seen by other users. + cloudbrain=Cloudbrain cloudbrain.new=New cloudbrain cloudbrain.desc=Cloudbrain diff --git a/options/locale/locale_zh-CN.ini b/options/locale/locale_zh-CN.ini index c2f81e4dd..875010bf6 100755 --- a/options/locale/locale_zh-CN.ini +++ b/options/locale/locale_zh-CN.ini @@ -922,6 +922,12 @@ image_commit_fail=提交镜像失败,请稍后再试。 download=模型下载 score=评分 + +images.name = 镜像名称 +images.name_placerholder = 请输入镜像名称 +image.label_tooltips = 如Python 3.7, Tensorflow 2.0, cuda 10, pytorch 1.6 +images.public_tooltips = 镜像设置为公开后,可被其他用户看到。 + cloudbrain=云脑 cloudbrain.new=新建任务 cloudbrain.desc=云脑功能 diff --git a/templates/repo/cloudbrain/image/submit.tmpl b/templates/repo/cloudbrain/image/submit.tmpl index c3ec70157..e12dc5923 100644 --- a/templates/repo/cloudbrain/image/submit.tmpl +++ b/templates/repo/cloudbrain/image/submit.tmpl @@ -1,5 +1,115 @@ + {{template "base/head" .}} -
- asdasd +
+ {{template "repo/header" .}} +
+
+

+ {{.i18n.Tr "repo.submit_image"}} +

+
+
+
+ +
+ + CPU/GPU +
+
+
+ + + {{.i18n.Tr "cloudbrain.job_name_rule"}} +
+
+ + +
+
+   + + + +
+ {{.i18n.Tr "repo.image.label_tooltips"}} +
+ +
+
+ + +
+
+
+
+ + +
+
+
+ {{.i18n.Tr "repo.images.public_tooltips"}} +
+ +
+ +
+ + + {{.i18n.Tr "repo.cloudbrain.cancel"}} +
+
+
+
+
-{{template "base/footer" .}} \ No newline at end of file +{{template "base/footer" .}} + + \ No newline at end of file diff --git a/templates/repo/createCourse.tmpl b/templates/repo/createCourse.tmpl index a354dade2..fea257a5e 100644 --- a/templates/repo/createCourse.tmpl +++ b/templates/repo/createCourse.tmpl @@ -46,7 +46,7 @@
-
+