From 36e88d0ab48cb5f7811b512257cab1a7de52a9b9 Mon Sep 17 00:00:00 2001 From: zouap Date: Mon, 14 Mar 2022 17:43:48 +0800 Subject: [PATCH 01/36] =?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 02/36] =?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 0e3c44921daf56e0b1b40f6db2359e330231e624 Mon Sep 17 00:00:00 2001 From: zouap Date: Tue, 22 Mar 2022 16:31:12 +0800 Subject: [PATCH 03/36] =?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 de101e88008e9c549c5e07227c59cd99332be97f Mon Sep 17 00:00:00 2001 From: zouap Date: Tue, 22 Mar 2022 17:15:06 +0800 Subject: [PATCH 04/36] =?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 05/36] =?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 06/36] =?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: Thu, 24 Mar 2022 10:13:05 +0800 Subject: [PATCH 07/36] =?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 08/36] =?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: Mon, 28 Mar 2022 15:12:18 +0800 Subject: [PATCH 09/36] #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 a13f4cfbe4e8883fa6520d3b5c61d23a991462ce Mon Sep 17 00:00:00 2001 From: zhoupzh Date: Fri, 1 Apr 2022 09:40:32 +0800 Subject: [PATCH 10/36] fix issue --- templates/repo/datasets/index.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/repo/datasets/index.tmpl b/templates/repo/datasets/index.tmpl index a38e86525..065ada386 100755 --- a/templates/repo/datasets/index.tmpl +++ b/templates/repo/datasets/index.tmpl @@ -131,7 +131,7 @@ {{.i18n.Tr "repo.modelarts.modify"}}
- {{if and (.dataset.Category) (.dataset.Task) (.dataset.License)}} + {{if or (.dataset.Category) (.dataset.Task) (.dataset.License)}}
{{if .dataset.Category}} {{$category := .dataset.Category}} From 6dc72806a17e7cb6b3faeb991047f81dc9884258 Mon Sep 17 00:00:00 2001 From: lewis <747342561@qq.com> Date: Fri, 1 Apr 2022 10:01:37 +0800 Subject: [PATCH 11/36] show restart action --- modules/cloudbrain/cloudbrain.go | 16 +++++++++------- routers/repo/modelarts.go | 4 +++- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/modules/cloudbrain/cloudbrain.go b/modules/cloudbrain/cloudbrain.go index bd0f11507..4a89f9393 100755 --- a/modules/cloudbrain/cloudbrain.go +++ b/modules/cloudbrain/cloudbrain.go @@ -21,7 +21,7 @@ const ( CodeMountPath = "/code" DataSetMountPath = "/dataset" ModelMountPath = "/model" - LogFile = "log.txt" + LogFile = "log.txt" BenchMarkMountPath = "/benchmark" BenchMarkResourceID = 1 Snn4imagenetMountPath = "/snn4imagenet" @@ -291,16 +291,16 @@ func GenerateTask(ctx *context.Context, displayJobName, jobName, image, command, IsLatestVersion: "1", VersionCount: versionCount, BranchName: branchName, - BootFile: bootFile, - DatasetName: datasetName, - Parameters: params, + BootFile: bootFile, + DatasetName: datasetName, + Parameters: params, }) if err != nil { return err } - task, err := models.GetCloudbrainByName(jobName) + task, err := models.GetCloudbrainByJobID(jobID) if err != nil { log.Error("GetCloudbrainByName failed: %v", err.Error()) return err @@ -440,8 +440,10 @@ func RestartTask(ctx *context.Context, task *models.Cloudbrain, newID *string) e return err } - idString := strconv.FormatInt(newTask.ID, 10) - *newID = idString + stringId := strconv.FormatInt(newTask.ID, 10) + *newID = stringId + + notification.NotifyOtherTask(ctx.User, ctx.Repo.Repository, stringId, task.DisplayJobName, models.ActionCreateDebugGPUTask) return nil } diff --git a/routers/repo/modelarts.go b/routers/repo/modelarts.go index 5a2e4691e..32d9db9ce 100755 --- a/routers/repo/modelarts.go +++ b/routers/repo/modelarts.go @@ -2,6 +2,7 @@ package repo import ( "archive/zip" + "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/timeutil" "encoding/json" "errors" @@ -430,7 +431,7 @@ func NotebookManage(ctx *context.Context) { Uuid: task.Uuid, Image: task.Image, ComputeResource: task.ComputeResource, - Description: task.Description, + Description: task.Description, } err = models.RestartCloudbrain(task, newTask) @@ -441,6 +442,7 @@ func NotebookManage(ctx *context.Context) { break } ID = strconv.FormatInt(newTask.ID, 10) + notification.NotifyOtherTask(ctx.User, ctx.Repo.Repository, ID, task.DisplayJobName, models.ActionCreateDebugNPUTask) } else { task.Status = res.Status if task.EndTime == 0 && models.IsModelArtsDebugJobTerminal(task.Status) { From 2c7d9faa07f5ac588e7b09e389bfb6ad6ab4d360 Mon Sep 17 00:00:00 2001 From: lewis <747342561@qq.com> Date: Fri, 1 Apr 2022 15:11:37 +0800 Subject: [PATCH 12/36] show restart --- models/cloudbrain.go | 16 ++++++++++++++++ routers/repo/cloudbrain.go | 24 +++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/models/cloudbrain.go b/models/cloudbrain.go index 1662dcd96..67d1b695b 100755 --- a/models/cloudbrain.go +++ b/models/cloudbrain.go @@ -1370,6 +1370,16 @@ func getRepoCloudBrain(cb *Cloudbrain) (*Cloudbrain, error) { return cb, nil } +func getRepoCloudBrainWithDeleted(cb *Cloudbrain) (*Cloudbrain, error) { + has, err := x.Unscoped().Get(cb) + if err != nil { + return nil, err + } else if !has { + return nil, ErrJobNotExist{} + } + return cb, nil +} + func GetRepoCloudBrainByJobID(repoID int64, jobID string) (*Cloudbrain, error) { cb := &Cloudbrain{JobID: jobID, RepoID: repoID} return getRepoCloudBrain(cb) @@ -1386,6 +1396,12 @@ func GetCloudbrainByID(id string) (*Cloudbrain, error) { return getRepoCloudBrain(cb) } +func GetCloudbrainByIDWithDeleted(id string) (*Cloudbrain, error) { + idInt64, _ := strconv.ParseInt(id, 10, 64) + cb := &Cloudbrain{ID: idInt64} + return getRepoCloudBrainWithDeleted(cb) +} + func GetCloudbrainByJobIDAndVersionName(jobID string, versionName string) (*Cloudbrain, error) { cb := &Cloudbrain{JobID: jobID, VersionName: versionName} return getRepoCloudBrain(cb) diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index 898f3844f..9b3cb05d7 100755 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -400,18 +400,22 @@ func cloudBrainShow(ctx *context.Context, tpName base.TplName, jobType models.Jo if jobType == models.JobTypeTrain { task, err = models.GetCloudbrainByJobID(ctx.Params(":jobid")) } else { - task, err = models.GetCloudbrainByID(ctx.Params(":id")) + task, err = models.GetCloudbrainByIDWithDeleted(ctx.Params(":id")) } if err != nil { log.Info("error:" + err.Error()) ctx.Data["error"] = err.Error() + return } + result, err := cloudbrain.GetJob(task.JobID) if err != nil { log.Info("error:" + err.Error()) ctx.Data["error"] = err.Error() + return } + if result != nil { jobRes, _ := models.ConvertToJobResultPayload(result.Payload) jobRes.Resource.Memory = strings.ReplaceAll(jobRes.Resource.Memory, "Mi", "MB") @@ -426,6 +430,15 @@ func cloudBrainShow(ctx *context.Context, tpName base.TplName, jobType models.Jo ctx.Data["resource_type"] = resourceType.Value } } + } else { + if gpuInfos == nil { + json.Unmarshal([]byte(setting.GpuTypes), &gpuInfos) + } + for _, resourceType := range gpuInfos.GpuInfo { + if resourceType.Queue == jobRes.Config.GpuType { + ctx.Data["resource_type"] = resourceType.Value + } + } } taskRoles := jobRes.TaskRoles if jobRes.JobStatus.State != string(models.JobFailed) { @@ -439,6 +452,7 @@ func cloudBrainShow(ctx *context.Context, tpName base.TplName, jobType models.Jo err = models.UpdateJob(task) if err != nil { ctx.Data["error"] = err.Error() + return } } else { task.Status = jobRes.JobStatus.State @@ -455,7 +469,15 @@ func cloudBrainShow(ctx *context.Context, tpName base.TplName, jobType models.Jo ctx.Data["result"] = jobRes } else { log.Info("error:" + err.Error()) + return + } + + if task.DeletedAt.IsZero() { //normal record + + } else { //restart record + } + user, err := models.GetUserByID(task.UserID) if err == nil { task.User = user From 027e512fcfb8fac170ca83721d7cf8ed4112bae1 Mon Sep 17 00:00:00 2001 From: lewis <747342561@qq.com> Date: Fri, 1 Apr 2022 20:49:54 +0800 Subject: [PATCH 13/36] test --- routers/repo/cloudbrain.go | 1 + 1 file changed, 1 insertion(+) diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index 9b3cb05d7..59d16a5d8 100755 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -983,6 +983,7 @@ func uploadCodeToMinio(codePath, jobName, parentDir string) error { destObject := setting.CBCodePathPrefix + jobName + parentDir + file.Name() sourceFile := codePath + file.Name() err = storage.Attachments.UploadObject(destObject, sourceFile) + if err != nil { log.Error("UploadObject(%s) failed: %s", file.Name(), err.Error()) return err From 114d20dca3daa989044b978a0c64ced059236365 Mon Sep 17 00:00:00 2001 From: lewis <747342561@qq.com> Date: Fri, 1 Apr 2022 21:29:05 +0800 Subject: [PATCH 14/36] fix bug --- routers/api/v1/repo/cloudbrain.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routers/api/v1/repo/cloudbrain.go b/routers/api/v1/repo/cloudbrain.go index 27086888e..a81263823 100755 --- a/routers/api/v1/repo/cloudbrain.go +++ b/routers/api/v1/repo/cloudbrain.go @@ -65,7 +65,7 @@ func GetCloudbrainTask(ctx *context.APIContext) { log.Error("GetJob failed:", err) return } - result, err := models.ConvertToJobResultPayload(jobResult.Payload) + result, _ := models.ConvertToJobResultPayload(jobResult.Payload) if err != nil { ctx.NotFound(err) log.Error("ConvertToJobResultPayload failed:", err) From fb301bc47063eec0abc861378c2d975a240005c6 Mon Sep 17 00:00:00 2001 From: chenyifan01 Date: Sat, 2 Apr 2022 10:46:36 +0800 Subject: [PATCH 15/36] #1654 fix bug --- models/cloudbrain.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/cloudbrain.go b/models/cloudbrain.go index 1662dcd96..527df5174 100755 --- a/models/cloudbrain.go +++ b/models/cloudbrain.go @@ -388,7 +388,7 @@ type JobResultPayload struct { AppProgress string `json:"appProgress"` AppTrackingURL string `json:"appTrackingUrl"` AppLaunchedTime int64 `json:"appLaunchedTime"` - AppCompletedTime int64 `json:"appCompletedTime"` + AppCompletedTime interface{} `json:"appCompletedTime"` AppExitCode int `json:"appExitCode"` AppExitDiagnostics string `json:"appExitDiagnostics"` AppExitType interface{} `json:"appExitType"` From 6979d31df0da800ecf7039c5aaa0d19fbfe0e244 Mon Sep 17 00:00:00 2001 From: zouap Date: Sat, 2 Apr 2022 11:09:02 +0800 Subject: [PATCH 16/36] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E7=9A=84=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- templates/repo/cloudbrain/show--bak.tmpl | 108 +++++ templates/repo/cloudbrain/show.tmpl | 559 +++++++++++++++++++---- 2 files changed, 569 insertions(+), 98 deletions(-) create mode 100644 templates/repo/cloudbrain/show--bak.tmpl diff --git a/templates/repo/cloudbrain/show--bak.tmpl b/templates/repo/cloudbrain/show--bak.tmpl new file mode 100644 index 000000000..1e234e094 --- /dev/null +++ b/templates/repo/cloudbrain/show--bak.tmpl @@ -0,0 +1,108 @@ +{{template "base/head" .}} +
+{{template "repo/header" .}} +
+
+ {{template "base/alert" .}} + +

+ +

+
+
+ {{with .task}} +

任务名称: {{.DisplayJobName}}

+ {{end}} +
+
+

任务结果:

+ {{with .taskRes}} + {{range .TaskStatuses}} + + + + + + + +
状态 {{.State}}
+ {{end}} + {{end}} +
+
+ {{with .result}} + + + + + + + + + + + + + + + + + + +
硬件信息
CPU {{.Resource.CPU}}
Memory {{.Resource.Memory}}
NvidiaComGpu {{.Resource.NvidiaComGpu}}
+ + + + + + + + + + + + + {{if not (eq $.task.StartTime 0)}} + + {{else}} + + + + {{if not (eq $.task.EndTime 0)}} + + {{else}} + + + + + + + + + + +
调试信息
平台 {{.Platform}}
开始时间 {{TimeSinceUnix1 $.task.StartTime}} + {{end}} +
结束时间 {{TimeSinceUnix1 $.task.EndTime}} + {{end}} +
ExitCode {{.JobStatus.AppExitCode}}
退出信息 {{.JobStatus.AppExitDiagnostics | nl2br}}
+ {{end}} +
+
+ +
+
+
+{{template "base/footer" .}} diff --git a/templates/repo/cloudbrain/show.tmpl b/templates/repo/cloudbrain/show.tmpl index 1e234e094..b6c99df85 100755 --- a/templates/repo/cloudbrain/show.tmpl +++ b/templates/repo/cloudbrain/show.tmpl @@ -1,108 +1,471 @@ {{template "base/head" .}} + +
+
+
+
+
+
+
+
+
{{template "repo/header" .}} -
-
- {{template "base/alert" .}} - +

- +

-
-
- {{with .task}} -

任务名称: {{.DisplayJobName}}

- {{end}} -
-
-

任务结果:

- {{with .taskRes}} - {{range .TaskStatuses}} - - - - - - - -
状态 {{.State}}
- {{end}} - {{end}} -
-
- {{with .result}} - - - - - - - - - - - - - - - - - - -
硬件信息
CPU {{.Resource.CPU}}
Memory {{.Resource.Memory}}
NvidiaComGpu {{.Resource.NvidiaComGpu}}
- - - - - - - - - - - - - {{if not (eq $.task.StartTime 0)}} - - {{else}} - - - - {{if not (eq $.task.EndTime 0)}} - - {{else}} - - - - - - - - - - -
调试信息
平台 {{.Platform}}
开始时间 {{TimeSinceUnix1 $.task.StartTime}} - {{end}} -
结束时间 {{TimeSinceUnix1 $.task.EndTime}} - {{end}} -
ExitCode {{.JobStatus.AppExitCode}}
退出信息 {{.JobStatus.AppExitDiagnostics | nl2br}}
- {{end}} -
+ +
+ +
+
+
+ + + +
+ + {{if not (eq .StartTime 0)}} + {{TimeSinceUnix1 .StartTime}} + {{else}} + {{TimeSinceUnix1 .CreatedUnix}} + {{end}} + + + {{$.i18n.Tr "repo.modelarts.status"}}: + {{.Status}} + + {{$.i18n.Tr "repo.modelarts.train_job.dura_time"}}: + {{$.duration}} + +
+
+
+
+
+
+
+
+ +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ {{$.i18n.Tr "repo.cloudbrain_task"}} + +
+ {{.DisplayJobName}} +
+
+ {{$.i18n.Tr "repo.modelarts.status"}} + +
+ {{.Status}} +
+
+ {{$.i18n.Tr "repo.modelarts.train_job.start_time"}} + +
+ + {{if not (eq .StartTime 0)}} + {{TimeSinceUnix1 .StartTime}} + {{else}} + {{TimeSinceUnix1 .CreatedUnix}} + {{end}} + +
+
+ {{$.i18n.Tr "repo.modelarts.train_job.dura_time"}} + +
+ {{$.duration}} +
+
+ 镜像 + +
+ {{.Image}} +
+
+ 类型 + +
+ {{$.BenchmarkTypeName}} +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ 训练程序 + +
+ train.py +
+
+ 测试程序 + +
+ test.py +
+
+ {{$.i18n.Tr "repo.modelarts.train_job.description"}} + +
+ {{.Description}} +
+
+ {{$.i18n.Tr "repo.modelarts.train_job.standard"}} + +
+ {{$.resource_spec}} +
+
+ 创建者 + +
+ {{.User.Name}} +
+
+ 子类型 + +
+ {{$.BenchmarkChildTypeName}} +
+
+
+
+
+ +
+
+
+
+ +
+ + +

+                            
+ +
+ +
+ +
+
+ + {{template "base/paginate" .}} +
+ +
+
-
+ +
{{template "base/footer" .}} + + From 347e580fec44326423be087357c5022c69a71d7d Mon Sep 17 00:00:00 2001 From: ychao_1983 Date: Sat, 2 Apr 2022 11:49:09 +0800 Subject: [PATCH 17/36] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=A1=B9=E7=9B=AE?= =?UTF-8?q?=E4=B8=8D=E8=83=BD=E6=94=B9=E4=B8=BA=E7=A7=81=E6=9C=89=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/dataset.go | 2 +- models/repo.go | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/models/dataset.go b/models/dataset.go index af47c53fe..c0d82d250 100755 --- a/models/dataset.go +++ b/models/dataset.go @@ -348,7 +348,7 @@ func GetDatasetByRepo(repo *Repository) (*Dataset, error) { if has { return dataset, nil } else { - return nil, errors.New("Not Found") + return nil, ErrNotExist{repo.ID} } } diff --git a/models/repo.go b/models/repo.go index b5d4921e4..25bfb4a74 100755 --- a/models/repo.go +++ b/models/repo.go @@ -1607,14 +1607,16 @@ func updateRepository(e Engine, repo *Repository, visibilityChanged bool) (err e } dataset, err := GetDatasetByRepo(repo) - if err != nil { + if err != nil && !IsErrNotExist(err) { return err } - _, err = e.Where("dataset_id = ?", dataset.ID).Cols("is_private").Update(&Attachment{ - IsPrivate: true, - }) - if err != nil { - return err + if dataset != nil { + _, err = e.Where("dataset_id = ?", dataset.ID).Cols("is_private").Update(&Attachment{ + IsPrivate: true, + }) + if err != nil { + return err + } } } else { From 876cb5ed4f9fa4418583558282604491a4c0c35a Mon Sep 17 00:00:00 2001 From: zouap Date: Sat, 2 Apr 2022 14:32:27 +0800 Subject: [PATCH 18/36] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E7=9A=84=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- templates/repo/cloudbrain/show.tmpl | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/templates/repo/cloudbrain/show.tmpl b/templates/repo/cloudbrain/show.tmpl index b6c99df85..109fb195f 100755 --- a/templates/repo/cloudbrain/show.tmpl +++ b/templates/repo/cloudbrain/show.tmpl @@ -186,10 +186,10 @@ td, th {
{{.displayJobName}}
- -
+ {{range $k ,$v := .version_list_task}} +
-
+
@@ -216,13 +216,13 @@ td, th {
-
+
-
+
@@ -388,7 +388,7 @@ td, th {
-
+
- - {{template "base/paginate" .}} + {{end}} {{template "base/paginate" .}}
From 5935583a2e71ac545ff130505dee98fb744d569e Mon Sep 17 00:00:00 2001 From: lewis <747342561@qq.com> Date: Sat, 2 Apr 2022 14:43:16 +0800 Subject: [PATCH 19/36] show restart record --- routers/repo/cloudbrain.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index 59d16a5d8..d1465745e 100755 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -449,10 +449,15 @@ func cloudBrainShow(ctx *context.Context, tpName base.TplName, jobType models.Jo task.ContainerID = taskRes.TaskStatuses[0].ContainerID task.ContainerIp = taskRes.TaskStatuses[0].ContainerIP models.ParseAndSetDurationFromCloudBrainOne(jobRes, task) - err = models.UpdateJob(task) - if err != nil { - ctx.Data["error"] = err.Error() - return + + if task.DeletedAt.IsZero() { //normal record + err = models.UpdateJob(task) + if err != nil { + ctx.Data["error"] = err.Error() + return + } + } else { //restart record + } } else { task.Status = jobRes.JobStatus.State @@ -472,12 +477,6 @@ func cloudBrainShow(ctx *context.Context, tpName base.TplName, jobType models.Jo return } - if task.DeletedAt.IsZero() { //normal record - - } else { //restart record - - } - user, err := models.GetUserByID(task.UserID) if err == nil { task.User = user From 85ce0687f9a9c19325878422ba359b1230967147 Mon Sep 17 00:00:00 2001 From: zouap Date: Sat, 2 Apr 2022 15:11:26 +0800 Subject: [PATCH 20/36] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E7=9A=84=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- templates/repo/cloudbrain/benchmark/show.tmpl | 13 +++++----- templates/repo/cloudbrain/show.tmpl | 26 +++++++++---------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/templates/repo/cloudbrain/benchmark/show.tmpl b/templates/repo/cloudbrain/benchmark/show.tmpl index 109fb195f..16e5a98f5 100755 --- a/templates/repo/cloudbrain/benchmark/show.tmpl +++ b/templates/repo/cloudbrain/benchmark/show.tmpl @@ -281,7 +281,7 @@ td, th { - 镜像 + {{.i18n.Tr "cloudbrain.mirror"}} @@ -292,7 +292,8 @@ td, th { - 类型 + {{.i18n.Tr "repo.cloudbrain.benchmark.evaluate_type"}} + @@ -313,7 +314,7 @@ td, th { - 训练程序 + {{.i18n.Tr "repo.cloudbrain.benchmark.evaluate_train"}} @@ -324,7 +325,7 @@ td, th { - 测试程序 + {{.i18n.Tr "repo.cloudbrain.benchmark.evaluate_test"}} @@ -360,7 +361,7 @@ td, th { - 创建者 + {{$.i18n.Tr "repo.cloudbrain_creator"}} @@ -371,7 +372,7 @@ td, th { - 子类型 + {{$.i18n.Tr "repo.cloudbrain.benchmark.evaluate_child_type"}} diff --git a/templates/repo/cloudbrain/show.tmpl b/templates/repo/cloudbrain/show.tmpl index 109fb195f..948d43e97 100755 --- a/templates/repo/cloudbrain/show.tmpl +++ b/templates/repo/cloudbrain/show.tmpl @@ -179,8 +179,8 @@ td, th { {{.i18n.Tr "repo.cloudbrain"}}
/
- - {{$.i18n.Tr "repo.modelarts.evaluate_job"}} + + {{$.i18n.Tr "repo.modelarts.notebook"}}
/
{{.displayJobName}}
@@ -281,7 +281,7 @@ td, th { - 镜像 + {{.i18n.Tr "cloudbrain.mirror"}} @@ -292,12 +292,12 @@ td, th { - 类型 + {{$.i18n.Tr "repo.modelarts.train_job.dataset"}}
- {{$.BenchmarkTypeName}} + {{.DatasetName}}
@@ -313,30 +313,30 @@ td, th { - 训练程序 + 平台
- train.py + {{$.Platform}}
- 测试程序 + ExitCode
- test.py + {{$.JobStatus.AppExitCode}}
- {{$.i18n.Tr "repo.modelarts.train_job.description"}} + {{.i18n.Tr "cloudbrain.code_storage_path"}} @@ -360,7 +360,7 @@ td, th { - 创建者 + {{$.i18n.Tr "repo.cloudbrain_creator"}} @@ -371,12 +371,12 @@ td, th { - 子类型 + {{$.i18n.Tr "repo.cloudbrain.exitinfo"}}
- {{$.BenchmarkChildTypeName}} + {{$.JobStatus.AppExitDiagnostics | nl2br}}
From 4afba2eae4d98188b6a5a4d461d977060f9f5d24 Mon Sep 17 00:00:00 2001 From: zouap Date: Sat, 2 Apr 2022 15:13:11 +0800 Subject: [PATCH 21/36] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E7=9A=84=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- templates/repo/cloudbrain/show.tmpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/repo/cloudbrain/show.tmpl b/templates/repo/cloudbrain/show.tmpl index 948d43e97..648fc0e3d 100755 --- a/templates/repo/cloudbrain/show.tmpl +++ b/templates/repo/cloudbrain/show.tmpl @@ -281,7 +281,7 @@ td, th { - {{.i18n.Tr "cloudbrain.mirror"}} + {{$.i18n.Tr "cloudbrain.mirror"}} @@ -336,7 +336,7 @@ td, th { - {{.i18n.Tr "cloudbrain.code_storage_path"}} + {{$.i18n.Tr "cloudbrain.code_storage_path"}} From c1d6231a139a89b312cfac708800b7b780aa2676 Mon Sep 17 00:00:00 2001 From: zouap Date: Sat, 2 Apr 2022 15:18:56 +0800 Subject: [PATCH 22/36] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E7=9A=84=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- templates/repo/cloudbrain/show.tmpl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/repo/cloudbrain/show.tmpl b/templates/repo/cloudbrain/show.tmpl index 648fc0e3d..082393ad0 100755 --- a/templates/repo/cloudbrain/show.tmpl +++ b/templates/repo/cloudbrain/show.tmpl @@ -329,7 +329,7 @@ td, th {
- {{$.JobStatus.AppExitCode}} + {{$.result.JobStatus.AppExitCode}}
@@ -376,7 +376,7 @@ td, th {
- {{$.JobStatus.AppExitDiagnostics | nl2br}} + {{$.result.JobStatus.AppExitDiagnostics}}
From 784c884d3922d91e3372ec30941f59668fcbdb40 Mon Sep 17 00:00:00 2001 From: zouap Date: Sat, 2 Apr 2022 15:25:44 +0800 Subject: [PATCH 23/36] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E7=9A=84=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- routers/repo/cloudbrain.go | 11 +++++++++-- templates/repo/cloudbrain/show.tmpl | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index 898f3844f..33ce5debb 100755 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -2,11 +2,9 @@ package repo import ( "bufio" - "code.gitea.io/gitea/modules/timeutil" "encoding/json" "errors" "fmt" - "github.com/unknwon/i18n" "io" "net/http" "os" @@ -16,6 +14,9 @@ import ( "strings" "time" + "code.gitea.io/gitea/modules/timeutil" + "github.com/unknwon/i18n" + "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/auth" "code.gitea.io/gitea/modules/base" @@ -510,6 +511,12 @@ func cloudBrainShow(ctx *context.Context, tpName base.TplName, jobType models.Jo } } + attachment, err := models.GetAttachmentByUUID(task.Uuid) + if err == nil { + ctx.Data["datasetname"] = attachment.Name + } else { + ctx.Data["datasetname"] = "" + } ctx.Data["task"] = task ctx.Data["jobName"] = task.JobName diff --git a/templates/repo/cloudbrain/show.tmpl b/templates/repo/cloudbrain/show.tmpl index 082393ad0..54e721b08 100755 --- a/templates/repo/cloudbrain/show.tmpl +++ b/templates/repo/cloudbrain/show.tmpl @@ -297,7 +297,7 @@ td, th {
- {{.DatasetName}} + {{$.datasetname}}
From e5ce5bfb060bba1882c6fd0e044ec6b16f846b1f Mon Sep 17 00:00:00 2001 From: zouap Date: Sat, 2 Apr 2022 15:33:15 +0800 Subject: [PATCH 24/36] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E7=9A=84=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- templates/repo/cloudbrain/show.tmpl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/repo/cloudbrain/show.tmpl b/templates/repo/cloudbrain/show.tmpl index 54e721b08..98b4e56ba 100755 --- a/templates/repo/cloudbrain/show.tmpl +++ b/templates/repo/cloudbrain/show.tmpl @@ -375,9 +375,9 @@ td, th { -
- {{$.result.JobStatus.AppExitDiagnostics}} -
+ + {{$.result.JobStatus.AppExitDiagnostics}} + From 98a47aae216073e3fca60077f79f043acf605c5e Mon Sep 17 00:00:00 2001 From: zouap Date: Sat, 2 Apr 2022 15:39:08 +0800 Subject: [PATCH 25/36] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E7=9A=84=E4=BF=A1=E6=81=AF?= 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 | 2 +- options/locale/locale_zh-CN.ini | 1 + templates/repo/cloudbrain/show.tmpl | 55 ++++++++--------------------- 3 files changed, 16 insertions(+), 42 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 09bb5015f..bed7c46e0 100755 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -911,7 +911,7 @@ language_other = Other datasets = Datasets datasets.desc = Enable Dataset cloudbrain_helper=Use GPU/NPU resources to open notebooks, model training tasks, etc. - +cloudbrain.exitinfo=Exit Information model_manager = Model model_noright=No right model_rename=Duplicate model name, please modify model name. diff --git a/options/locale/locale_zh-CN.ini b/options/locale/locale_zh-CN.ini index d26065363..7bf28aa10 100755 --- a/options/locale/locale_zh-CN.ini +++ b/options/locale/locale_zh-CN.ini @@ -958,6 +958,7 @@ cloudbrain_jobname_err=只能以小写字母或数字开头且只包含小写字 cloudbrain_query_fail=查询云脑任务失败。 cloudbrain.mirror_tag = 镜像标签 cloudbrain.mirror_description = 镜像描述 +cloudbrain.exitinfo=退出信息 record_begintime_get_err=无法获取统计开始时间。 parameter_is_wrong=输入参数错误,请检查输入参数。 diff --git a/templates/repo/cloudbrain/show.tmpl b/templates/repo/cloudbrain/show.tmpl index 98b4e56ba..789f915d1 100755 --- a/templates/repo/cloudbrain/show.tmpl +++ b/templates/repo/cloudbrain/show.tmpl @@ -290,19 +290,7 @@ td, th {
- - - {{$.i18n.Tr "repo.modelarts.train_job.dataset"}} - - - -
- {{$.datasetname}} -
- - - - +
@@ -336,12 +324,12 @@ td, th { - {{$.i18n.Tr "cloudbrain.code_storage_path"}} + {{$.i18n.Tr "repo.modelarts.train_job.dataset"}} -
- {{.Description}} +
+ {{$.datasetname}}
@@ -369,39 +357,24 @@ td, th {
- - - {{$.i18n.Tr "repo.cloudbrain.exitinfo"}} - - - - - {{$.result.JobStatus.AppExitDiagnostics}} - - - +
+
+
+ {{$.i18n.Tr "repo.cloudbrain.exitinfo"}} +
+
+ {{$.result.JobStatus.AppExitDiagnostics}} +
+
-
-
- -
- - -

-                            
- -
- -
+
From 4390d617f8a6da4f3fd00a1f67a94db5c6b480c5 Mon Sep 17 00:00:00 2001 From: zouap Date: Sat, 2 Apr 2022 15:54:56 +0800 Subject: [PATCH 26/36] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E7=9A=84=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- templates/repo/cloudbrain/show.tmpl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/templates/repo/cloudbrain/show.tmpl b/templates/repo/cloudbrain/show.tmpl index 789f915d1..b6294d280 100755 --- a/templates/repo/cloudbrain/show.tmpl +++ b/templates/repo/cloudbrain/show.tmpl @@ -220,7 +220,6 @@ td, th {
@@ -364,11 +363,12 @@ td, th {
- {{$.i18n.Tr "repo.cloudbrain.exitinfo"}} + {{$.i18n.Tr "repo.cloudbrain.exitinfo"}} +
-
- {{$.result.JobStatus.AppExitDiagnostics}} -
+
+
+ {{$.result.JobStatus.AppExitDiagnostics}}
From 05a9809f5f2e02e97deed819519510950303a0c0 Mon Sep 17 00:00:00 2001 From: zouap Date: Sat, 2 Apr 2022 16:02:27 +0800 Subject: [PATCH 27/36] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E7=9A=84=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- templates/repo/cloudbrain/show.tmpl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/templates/repo/cloudbrain/show.tmpl b/templates/repo/cloudbrain/show.tmpl index b6294d280..b5baa7df8 100755 --- a/templates/repo/cloudbrain/show.tmpl +++ b/templates/repo/cloudbrain/show.tmpl @@ -56,7 +56,7 @@ margin:10px 5px ; } .tab_2_content { - min-height: 360px; + min-height: 560px; margin-left: 10px; } .ac-grid { @@ -81,6 +81,13 @@ .ti-form>tbody, .ti-form>tbody>tr { vertical-align: inherit; } +.info_text { + padding-bottom: 20px; + padding-right: 20px; + color: #8a8e99; + font-size: 12px; +} + .ti-text-form-label { padding-bottom: 20px; @@ -368,7 +375,9 @@ td, th {
+ {{$.result.JobStatus.AppExitDiagnostics}} +
From b4182391139a7b2ccc3c6a4fdcba1cb06c41b00e Mon Sep 17 00:00:00 2001 From: zouap Date: Sat, 2 Apr 2022 16:10:43 +0800 Subject: [PATCH 28/36] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E7=9A=84=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- templates/repo/cloudbrain/show.tmpl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/templates/repo/cloudbrain/show.tmpl b/templates/repo/cloudbrain/show.tmpl index b5baa7df8..b1dd6e661 100755 --- a/templates/repo/cloudbrain/show.tmpl +++ b/templates/repo/cloudbrain/show.tmpl @@ -84,7 +84,6 @@ .info_text { padding-bottom: 20px; padding-right: 20px; - color: #8a8e99; font-size: 12px; } @@ -312,7 +311,7 @@ td, th {
- {{$.Platform}} + {{$.result.Platform}}
From 5defcd0c8145ab58509e0466fbb6277d15b9729b Mon Sep 17 00:00:00 2001 From: lewis <747342561@qq.com> Date: Sat, 2 Apr 2022 16:11:22 +0800 Subject: [PATCH 29/36] format --- routers/repo/cloudbrain.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index d1465745e..0ddb1e1fe 100755 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -456,7 +456,7 @@ func cloudBrainShow(ctx *context.Context, tpName base.TplName, jobType models.Jo ctx.Data["error"] = err.Error() return } - } else { //restart record + } else { //deleted record } } else { @@ -982,7 +982,6 @@ func uploadCodeToMinio(codePath, jobName, parentDir string) error { destObject := setting.CBCodePathPrefix + jobName + parentDir + file.Name() sourceFile := codePath + file.Name() err = storage.Attachments.UploadObject(destObject, sourceFile) - if err != nil { log.Error("UploadObject(%s) failed: %s", file.Name(), err.Error()) return err From b01f528dbd9e7bfeed68de26290a7149e3e34a07 Mon Sep 17 00:00:00 2001 From: lewis <747342561@qq.com> Date: Wed, 6 Apr 2022 10:47:49 +0800 Subject: [PATCH 30/36] fix 1820 --- templates/admin/cloudbrain/list.tmpl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) mode change 100644 => 100755 templates/admin/cloudbrain/list.tmpl diff --git a/templates/admin/cloudbrain/list.tmpl b/templates/admin/cloudbrain/list.tmpl old mode 100644 new mode 100755 index 39b2c21de..02f100e46 --- a/templates/admin/cloudbrain/list.tmpl +++ b/templates/admin/cloudbrain/list.tmpl @@ -81,7 +81,7 @@ {{.DisplayJobName}} {{else if eq .JobType "TRAIN"}} - + {{.DisplayJobName}} {{else if eq .JobType "BENCHMARK"}} @@ -155,13 +155,13 @@ {{else}} - + {{$.i18n.Tr "repo.stop"}} {{end}}
-
+ {{$.CsrfTokenHtml}} {{$.i18n.Tr "repo.delete"}} From 62f724b0183e8f60bcc47fdce88ae0664dd3b405 Mon Sep 17 00:00:00 2001 From: zouap Date: Wed, 6 Apr 2022 10:48:31 +0800 Subject: [PATCH 31/36] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- models/user_business_analysis.go | 23 +++++++++++++++++++++++ routers/api/v1/api.go | 2 ++ routers/repo/user_data_analysis.go | 24 ++++++++++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/models/user_business_analysis.go b/models/user_business_analysis.go index edfe73939..65ce642d5 100644 --- a/models/user_business_analysis.go +++ b/models/user_business_analysis.go @@ -207,6 +207,29 @@ func getLastCountDate() int64 { return pageStartTime.Unix() } +func QueryMetrics(start int64, end int64) ([]*UserMetrics, int64) { + statictisSess := xStatistic.NewSession() + defer statictisSess.Close() + userMetricsList := make([]*UserMetrics, 0) + if err := statictisSess.Table(new(UserMetrics)).Where("count_date >" + fmt.Sprint(start) + " and count_date<" + fmt.Sprint(end)).OrderBy("count_date desc"). + Find(&userMetricsList); err != nil { + return nil, 0 + } + return userMetricsList, int64(len(userMetricsList)) +} + +func QueryRankList(key string, tableName string, limit int) ([]*UserBusinessAnalysisAll, int64) { + statictisSess := xStatistic.NewSession() + defer statictisSess.Close() + + userBusinessAnalysisAllList := make([]*UserBusinessAnalysisAll, 0) + if err := statictisSess.Table(tableName).OrderBy(key+" desc,id desc").Limit(limit, 0). + Find(&userBusinessAnalysisAllList); err != nil { + return nil, 0 + } + return userBusinessAnalysisAllList, int64(len(userBusinessAnalysisAllList)) +} + func QueryUserStaticDataByTableName(start int, pageSize int, tableName string, queryObj interface{}, userName string) ([]*UserBusinessAnalysisAll, int64) { statictisSess := xStatistic.NewSession() defer statictisSess.Close() diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 1868edcb5..9de65662f 100755 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -547,6 +547,8 @@ func RegisterRoutes(m *macaron.Macaron) { }) }, operationReq) + m.Get("/query_user_metrics", operationReq, repo_ext.QueryMetrics) + m.Get("/query_user_rank_list", operationReq, repo_ext.QueryRankingList) m.Get("/query_user_static_page", operationReq, repo_ext.QueryUserStaticDataPage) m.Get("/query_user_current_month", operationReq, repo_ext.QueryUserStaticCurrentMonth) m.Get("/query_user_current_week", operationReq, repo_ext.QueryUserStaticCurrentWeek) diff --git a/routers/repo/user_data_analysis.go b/routers/repo/user_data_analysis.go index 96503e5c9..9d906270f 100755 --- a/routers/repo/user_data_analysis.go +++ b/routers/repo/user_data_analysis.go @@ -126,6 +126,30 @@ func queryUserDataPage(ctx *context.Context, tableName string, queryObj interfac } } +func QueryMetrics(ctx *context.Context) { + startDate := ctx.Query("startDate") + endDate := ctx.Query("endDate") + startTime, _ := time.ParseInLocation("2006-01-02", startDate, time.Local) + endTime, _ := time.ParseInLocation("2006-01-02", endDate, time.Local) + result, count := models.QueryMetrics(startTime.Unix(), endTime.Unix()) + mapInterface := make(map[string]interface{}) + mapInterface["data"] = result + mapInterface["count"] = count + ctx.JSON(http.StatusOK, mapInterface) +} + +func QueryRankingList(ctx *context.Context) { + key := ctx.Query("key") + tableName := ctx.Query("tableName") + limit := ctx.QueryInt("limit") + + result, count := models.QueryRankList(key, tableName, limit) + mapInterface := make(map[string]interface{}) + mapInterface["data"] = result + mapInterface["count"] = count + ctx.JSON(http.StatusOK, mapInterface) +} + func QueryUserStaticCurrentMonth(ctx *context.Context) { queryUserDataPage(ctx, "public.user_business_analysis_current_month", new(models.UserBusinessAnalysisCurrentMonth)) } From c9b78df4dac3c12e980947402455a72176982045 Mon Sep 17 00:00:00 2001 From: zouap Date: Wed, 6 Apr 2022 11:06:15 +0800 Subject: [PATCH 32/36] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8E=A5=E5=8F=A3?= 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 | 1 + options/locale/locale_zh-CN.ini | 1 + routers/repo/cloudbrain.go | 3 +++ templates/repo/cloudbrain/show.tmpl | 38 +++++++++++++++++++++++++++-- 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index bed7c46e0..7c6e50892 100755 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -912,6 +912,7 @@ datasets = Datasets datasets.desc = Enable Dataset cloudbrain_helper=Use GPU/NPU resources to open notebooks, model training tasks, etc. cloudbrain.exitinfo=Exit Information +cloudbrain.platform=Platform model_manager = Model model_noright=No right model_rename=Duplicate model name, please modify model name. diff --git a/options/locale/locale_zh-CN.ini b/options/locale/locale_zh-CN.ini index 7bf28aa10..5a70a0e6f 100755 --- a/options/locale/locale_zh-CN.ini +++ b/options/locale/locale_zh-CN.ini @@ -959,6 +959,7 @@ cloudbrain_query_fail=查询云脑任务失败。 cloudbrain.mirror_tag = 镜像标签 cloudbrain.mirror_description = 镜像描述 cloudbrain.exitinfo=退出信息 +cloudbrain.platform=平台 record_begintime_get_err=无法获取统计开始时间。 parameter_is_wrong=输入参数错误,请检查输入参数。 diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index 33ce5debb..de6f97fc9 100755 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -525,6 +525,9 @@ func cloudBrainShow(ctx *context.Context, tpName base.TplName, jobType models.Jo version_list_task = append(version_list_task, task) ctx.Data["version_list_task"] = version_list_task ctx.Data["debugListType"] = debugListType + ctx.Data["code_path"] = cloudbrain.CodeMountPath + ctx.Data["dataset_path"] = cloudbrain.DataSetMountPath + ctx.Data["model_path"] = cloudbrain.ModelMountPath ctx.Data["canDownload"] = cloudbrain.CanDeleteJob(ctx, task) ctx.HTML(200, tpName) } diff --git a/templates/repo/cloudbrain/show.tmpl b/templates/repo/cloudbrain/show.tmpl index b1dd6e661..1eaede8fd 100755 --- a/templates/repo/cloudbrain/show.tmpl +++ b/templates/repo/cloudbrain/show.tmpl @@ -295,6 +295,30 @@ td, th {
+ + + + {{$.i18n.Tr "cloudbrain.dataset_storage_path"}} + + + +
+ {{$.dataset_path}} +
+ + + + + + {{$.i18n.Tr ""cloudbrain.code_storage_path"}} + + + +
+ {{$.code_path}} +
+ + @@ -306,7 +330,7 @@ td, th { - 平台 + {{$.i18n.Tr "repo.cloudbrain.platform"}} @@ -362,7 +386,17 @@ td, th { - + + + {{$.i18n.Tr "cloudbrain.model_storage_path"}} + + + +
+ {{$.model_path}} +
+ + From 19508fdf0ac84fc5e873e51c04251eb3d70cf79c Mon Sep 17 00:00:00 2001 From: zouap Date: Wed, 6 Apr 2022 11:08:16 +0800 Subject: [PATCH 33/36] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- templates/repo/cloudbrain/show.tmpl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/repo/cloudbrain/show.tmpl b/templates/repo/cloudbrain/show.tmpl index 1eaede8fd..fb885562e 100755 --- a/templates/repo/cloudbrain/show.tmpl +++ b/templates/repo/cloudbrain/show.tmpl @@ -310,7 +310,7 @@ td, th { - {{$.i18n.Tr ""cloudbrain.code_storage_path"}} + {{$.i18n.Tr "cloudbrain.code_storage_path"}} From 73a5392fb492bd94abab2bec2d32b4d4230274d7 Mon Sep 17 00:00:00 2001 From: ychao_1983 Date: Wed, 6 Apr 2022 11:23:50 +0800 Subject: [PATCH 34/36] fix-1802 --- models/dataset.go | 48 +++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/models/dataset.go b/models/dataset.go index c0d82d250..7cac6c468 100755 --- a/models/dataset.go +++ b/models/dataset.go @@ -139,20 +139,7 @@ func SearchDatasetCondition(opts *SearchDatasetOptions) builder.Cond { var cond = builder.NewCond() cond = cond.And(builder.Neq{"dataset.status": DatasetStatusDeleted}) - if len(opts.Keyword) > 0 { - cond = cond.And(builder.Or(builder.Like{"dataset.title", opts.Keyword}, builder.Like{"dataset.description", opts.Keyword})) - } - - if len(opts.Category) > 0 { - cond = cond.And(builder.Eq{"dataset.category": opts.Category}) - } - - if len(opts.Task) > 0 { - cond = cond.And(builder.Eq{"dataset.task": opts.Task}) - } - if len(opts.License) > 0 { - cond = cond.And(builder.Eq{"dataset.license": opts.License}) - } + cond = generateFilterCond(opts, cond) if opts.RepoID > 0 { cond = cond.And(builder.Eq{"dataset.repo_id": opts.RepoID}) @@ -162,14 +149,12 @@ func SearchDatasetCondition(opts *SearchDatasetOptions) builder.Cond { 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) - - } + + subCon := builder.NewCond() + subCon = subCon.And(builder.Eq{"repository.owner_id": opts.OwnerID}) + subCon = generateFilterCond(opts, subCon) + cond = cond.Or(subCon) + } } else if opts.OwnerID > 0 { cond = cond.And(builder.Eq{"repository.owner_id": opts.OwnerID}) @@ -182,6 +167,25 @@ func SearchDatasetCondition(opts *SearchDatasetOptions) builder.Cond { return cond } +func generateFilterCond(opts *SearchDatasetOptions, cond builder.Cond) builder.Cond { + if len(opts.Keyword) > 0 { + cond = cond.And(builder.Or(builder.Like{"dataset.title", opts.Keyword}, builder.Like{"dataset.description", opts.Keyword})) + } + + if len(opts.Category) > 0 { + cond = cond.And(builder.Eq{"dataset.category": opts.Category}) + } + + if len(opts.Task) > 0 { + cond = cond.And(builder.Eq{"dataset.task": opts.Task}) + } + if len(opts.License) > 0 { + cond = cond.And(builder.Eq{"dataset.license": opts.License}) + } + + return cond +} + func SearchDatasetByCondition(opts *SearchDatasetOptions, cond builder.Cond) (DatasetList, int64, error) { if opts.Page <= 0 { opts.Page = 1 From 4c8de8891d3bdd89ec6fb55f2a19055230f0b2cb Mon Sep 17 00:00:00 2001 From: zouap Date: Wed, 6 Apr 2022 14:45:13 +0800 Subject: [PATCH 35/36] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=8E=A5=E5=8F=A3?= 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 | 1 + options/locale/locale_zh-CN.ini | 2 +- templates/repo/cloudbrain/show.tmpl | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 7c6e50892..94214a25c 100755 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -913,6 +913,7 @@ datasets.desc = Enable Dataset cloudbrain_helper=Use GPU/NPU resources to open notebooks, model training tasks, etc. cloudbrain.exitinfo=Exit Information cloudbrain.platform=Platform +cloudbrain.endtime=End Time model_manager = Model model_noright=No right model_rename=Duplicate model name, please modify model name. diff --git a/options/locale/locale_zh-CN.ini b/options/locale/locale_zh-CN.ini index 5a70a0e6f..e93b05ffb 100755 --- a/options/locale/locale_zh-CN.ini +++ b/options/locale/locale_zh-CN.ini @@ -960,7 +960,7 @@ cloudbrain.mirror_tag = 镜像标签 cloudbrain.mirror_description = 镜像描述 cloudbrain.exitinfo=退出信息 cloudbrain.platform=平台 - +cloudbrain.endtime=结束时间 record_begintime_get_err=无法获取统计开始时间。 parameter_is_wrong=输入参数错误,请检查输入参数。 total_count_get_error=查询总页数失败。 diff --git a/templates/repo/cloudbrain/show.tmpl b/templates/repo/cloudbrain/show.tmpl index fb885562e..d7aeb36d7 100755 --- a/templates/repo/cloudbrain/show.tmpl +++ b/templates/repo/cloudbrain/show.tmpl @@ -363,6 +363,22 @@ td, th { + + + {{$.i18n.Tr "repo.cloudbrain.endtime"}} + + + +
+ {{if not (eq .StartTime 0)}} + {{TimeSinceUnix1 .EndTime}} + {{else}} + -- + {{end}} +
+ + + {{$.i18n.Tr "repo.modelarts.train_job.standard"}} From 842f60734497349649ee8b9015af7b9e4ace5fb2 Mon Sep 17 00:00:00 2001 From: zouap Date: Wed, 6 Apr 2022 14:52:37 +0800 Subject: [PATCH 36/36] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=97=A0=E7=94=A8?= =?UTF-8?q?=E7=9A=84=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zouap --- templates/repo/cloudbrain/show--bak.tmpl | 108 ----------------------- templates/repo/cloudbrain/show.tmpl | 20 ++--- 2 files changed, 10 insertions(+), 118 deletions(-) delete mode 100644 templates/repo/cloudbrain/show--bak.tmpl diff --git a/templates/repo/cloudbrain/show--bak.tmpl b/templates/repo/cloudbrain/show--bak.tmpl deleted file mode 100644 index 1e234e094..000000000 --- a/templates/repo/cloudbrain/show--bak.tmpl +++ /dev/null @@ -1,108 +0,0 @@ -{{template "base/head" .}} -
-{{template "repo/header" .}} -
-
- {{template "base/alert" .}} - -

- -

-
-
- {{with .task}} -

任务名称: {{.DisplayJobName}}

- {{end}} -
-
-

任务结果:

- {{with .taskRes}} - {{range .TaskStatuses}} - - - - - - - -
状态 {{.State}}
- {{end}} - {{end}} -
-
- {{with .result}} - - - - - - - - - - - - - - - - - - -
硬件信息
CPU {{.Resource.CPU}}
Memory {{.Resource.Memory}}
NvidiaComGpu {{.Resource.NvidiaComGpu}}
- - - - - - - - - - - - - {{if not (eq $.task.StartTime 0)}} - - {{else}} - - - - {{if not (eq $.task.EndTime 0)}} - - {{else}} - - - - - - - - - - -
调试信息
平台 {{.Platform}}
开始时间 {{TimeSinceUnix1 $.task.StartTime}} - {{end}} -
结束时间 {{TimeSinceUnix1 $.task.EndTime}} - {{end}} -
ExitCode {{.JobStatus.AppExitCode}}
退出信息 {{.JobStatus.AppExitDiagnostics | nl2br}}
- {{end}} -
-
- -
-
-
-{{template "base/footer" .}} diff --git a/templates/repo/cloudbrain/show.tmpl b/templates/repo/cloudbrain/show.tmpl index d7aeb36d7..895a5c14f 100755 --- a/templates/repo/cloudbrain/show.tmpl +++ b/templates/repo/cloudbrain/show.tmpl @@ -350,35 +350,35 @@ td, th { - - {{$.i18n.Tr "repo.modelarts.train_job.dataset"}} + {{$.i18n.Tr "repo.cloudbrain.endtime"}}
- {{$.datasetname}} + {{if not (eq .StartTime 0)}} + {{TimeSinceUnix1 .EndTime}} + {{else}} + -- + {{end}}
- - {{$.i18n.Tr "repo.cloudbrain.endtime"}} + {{$.i18n.Tr "repo.modelarts.train_job.dataset"}}
- {{if not (eq .StartTime 0)}} - {{TimeSinceUnix1 .EndTime}} - {{else}} - -- - {{end}} + {{$.datasetname}}
+ + {{$.i18n.Tr "repo.modelarts.train_job.standard"}}