diff --git a/models/reward_operate_record.go b/models/reward_operate_record.go index da1b6a589..f201be646 100644 --- a/models/reward_operate_record.go +++ b/models/reward_operate_record.go @@ -3,6 +3,7 @@ package models import ( "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/timeutil" + "fmt" "strconv" "strings" "xorm.io/builder" @@ -130,21 +131,27 @@ func (l RewardRecordShowList) loadAction() error { return nil } actionIds := make([]int64, 0) - actionIdMap := make(map[int64]*RewardOperateRecordShow, 0) for _, r := range l { if r.SourceType != SourceTypeAccomplishTask.Name() { continue } i, _ := strconv.ParseInt(r.SourceId, 10, 64) actionIds = append(actionIds, i) - actionIdMap[i] = r } actions, err := GetActionByIds(actionIds) if err != nil { return err } + actionIdMap := make(map[string]*Action, 0) for _, v := range actions { - actionIdMap[v.ID].Action = v.ToShow() + actionIdMap[fmt.Sprint(v.ID)] = v + } + + for i, r := range l { + act := actionIdMap[r.SourceId] + if act != nil { + l[i].Action = act.ToShow() + } } return nil } diff --git a/models/user_invitation.go b/models/user_invitation.go index 7b0ca1cf9..2d37bcb23 100644 --- a/models/user_invitation.go +++ b/models/user_invitation.go @@ -64,6 +64,18 @@ func QueryInvitaionPage(start int, pageSize int) ([]*Invitation, int64) { return invitationList, allCount } +func QueryInvitaionByTime(startTime int64, endTime int64) []*Invitation { + statictisSess := xStatistic.NewSession() + defer statictisSess.Close() + cond := "created_unix >=" + fmt.Sprint(startTime) + " and created_unix <=" + fmt.Sprint(endTime) + invitationList := make([]*Invitation, 0) + if err := statictisSess.Table(new(Invitation)).Where(cond).OrderBy("created_unix desc"). + Find(&invitationList); err != nil { + return nil + } + return invitationList +} + func InsertInvitaion(invitationUser *Invitation) error { statictisSess := xStatistic.NewSession() defer statictisSess.Close() diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 34973abcd..19d604062 100755 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1058,6 +1058,7 @@ modify_image=Modify Image image_exist=Image name has been used, please use a new one. image_committing=Image is submitting, please try again later. image_commit_fail=Failed to submit image, please try again later. +image_over_20g=Failed to submit image, the size of image can not be over 20GB. image_not_exist=Image does not exits. image_edit_fail=Failed to edit image, please try again later. image_delete_fail=Failed to delete image, please try again later. @@ -1373,7 +1374,9 @@ fork_guest_user = Sign in to fork this repository. copy_link = Copy copy_link_success = Link has been copied copy_link_error = Use ⌘C or Ctrl-C to copy +copy = Copy copied = Copied OK +copied_error = Copied error unwatch = Unwatch watch = Watch unstar = Unstar @@ -3245,6 +3248,7 @@ load_code_failed=Fail to load code, please check if the right branch is selected error.dataset_select = dataset select error:the count exceed the limit or has same name new_train_gpu_tooltips = The code is storaged in %s, the dataset is storaged in %s, the pre-trained model is storaged in the environment %s, and please put your model into %s then you can download it online +new_train_npu_tooltips = The code is storaged in %s, the pre-trained model is storaged in the environment %s, and please put your model into %s then you can download it online new_infer_gpu_tooltips = The dataset is stored in %s, the model file is stored in %s, please store the inference output in %s for subsequent downloads. [points] diff --git a/options/locale/locale_zh-CN.ini b/options/locale/locale_zh-CN.ini index 2d75c2d05..9fa7f5595 100755 --- a/options/locale/locale_zh-CN.ini +++ b/options/locale/locale_zh-CN.ini @@ -72,7 +72,7 @@ your_starred=已点赞 your_settings=设置 invite_friends=邀请好友 your_friend=您的好友 -invite_you_to_join_the_OpenI_AI_Collaboration_Platform_and_enjoy_abundant_free_computing_resources=邀请你加入启智社区AI协作平台,畅享充沛的免费算力资源! +invite_you_to_join_the_OpenI_AI_Collaboration_Platform_and_enjoy_abundant_free_computing_resources=邀请您加入启智社区AI协作平台,畅享充沛的免费算力资源! recommender=推荐人 all=所有 @@ -1059,6 +1059,7 @@ modify_image=修改镜像 image_exist=镜像Tag已被使用,请修改镜像Tag。 image_committing=镜像正在提交中,请稍后再试。 image_commit_fail=提交镜像失败,请稍后再试。 +image_over_20g=提交镜像失败,镜像大小不能超过20GB。 image_not_exist=镜像不存在。 image_edit_fail=编辑镜像失败,请稍后再试。 image_delete_fail=删除镜像失败,请稍后再试。 @@ -1389,7 +1390,9 @@ fork_guest_user=登录并 派生 这个项目。 copy_link=复制链接 copy_link_success=已复制链接 copy_link_error=请按下 ⌘-C 或 Ctrl-C 复制 +copy=复制 copied=复制成功 +copied_error=复制失败 unwatch=取消关注 watch=关注 unstar=取消点赞 @@ -2022,7 +2025,7 @@ settings.githooks=管理 Git 钩子 settings.basic_settings=基本设置 settings.mirror_settings=镜像设置 settings.sync_mirror=同步 -settings.mirror_sync_in_progress=镜像同步正在进行中,请稍后后再试。 +settings.mirror_sync_in_progress=镜像同步正在进行中,请稍后再试。 settings.email_notifications.enable=启用邮件通知 settings.email_notifications.onmention=只在被提到时邮件通知 settings.email_notifications.disable=停用邮件通知 @@ -3101,9 +3104,9 @@ task_gputrainjob=`创建了CPU/GPU类型训练任务 %s` task_c2netgputrainjob=`创建了CPU/GPU类型训练任务 %s` binded_wechat=绑定微信 -dataset_recommended=`创建的数据集%s被设置为推荐数据集` -create_image=`提交了镜像%s` -image_recommended=`提交的镜像%s被设置为推荐镜像` +dataset_recommended=`创建的数据集 %s 被设置为推荐数据集` +create_image=`提交了镜像 %s` +image_recommended=`提交的镜像 %s 被设置为推荐镜像` update_user_avatar=更新了头像 [tool] @@ -3264,6 +3267,7 @@ load_code_failed=代码加载失败,请确认选择了正确的分支。 error.dataset_select = 数据集选择错误:数量超过限制或者有同名数据集 new_train_gpu_tooltips =训练脚本存储在%s中,数据集存储在%s中,预训练模型存放在环境变量%s中,训练输出请存储在%s中以供后续下载。 +new_train_npu_tooltips =训练脚本存储在%s中,预训练模型存放在环境变量%s中,训练输出请存储在%s中以供后续下载。 new_infer_gpu_tooltips = 数据集存储在%s中,模型文件存储在%s中,推理输出请存储在%s中以供后续下载。 [points] diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index f430460f6..6dd1cb32f 100755 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -581,6 +581,8 @@ func RegisterRoutes(m *macaron.Macaron) { m.Get("/query_invitation_last_month", operationReq, repo_ext.QueryInvitationLastMonth) m.Get("/query_invitation_yesterday", operationReq, repo_ext.QueryInvitationYesterday) m.Get("/query_invitation_all", operationReq, repo_ext.QueryInvitationAll) + m.Get("/query_invitation_userdefine", operationReq, repo_ext.QueryUserDefineInvitationPage) + m.Get("/download_invitation_detail", operationReq, repo_ext.DownloadInvitationDetail) //cloudbrain board diff --git a/routers/repo/cloudbrain.go b/routers/repo/cloudbrain.go index 73aa9b791..9311ddeac 100755 --- a/routers/repo/cloudbrain.go +++ b/routers/repo/cloudbrain.go @@ -1147,6 +1147,8 @@ func CloudBrainCommitImage(ctx *context.Context, form auth.CommitImageCloudBrain } else if models.IsErrorImageCommitting(err) { ctx.JSON(200, models.BaseErrorMessage(ctx.Tr("repo.image_committing"))) + } else if isOver20GError(err) { + ctx.JSON(200, models.BaseErrorMessage(ctx.Tr("repo.image_over_20g"))) } else { ctx.JSON(200, models.BaseErrorMessage(ctx.Tr("repo.image_commit_fail"))) } @@ -1156,6 +1158,10 @@ func CloudBrainCommitImage(ctx *context.Context, form auth.CommitImageCloudBrain ctx.JSON(200, models.BaseOKMessage) } +func isOver20GError(err error) bool { + return strings.Contains(err.Error(), "over max image size 20GB") +} + func checkTopics(Topics string) ([]string, string) { var topics = make([]string, 0) var topicsStr = strings.TrimSpace(Topics) diff --git a/routers/repo/user_invitation.go b/routers/repo/user_invitation.go index b0aac4eed..a2752a481 100644 --- a/routers/repo/user_invitation.go +++ b/routers/repo/user_invitation.go @@ -4,6 +4,8 @@ import ( "fmt" "net/http" "net/url" + "sort" + "time" "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/context" @@ -123,6 +125,9 @@ func DownloadInvitationDetail(ctx *context.Context) { for _, userRecord := range re { row++ userRecord.Name = userNameMap[userRecord.UserID] + if userRecord.Name == "" { + userRecord.Name = "已注销" + } writeInvitationDetailExcel(row, xlsx, sheetName, userRecord) } indexTotal += PAGE_SIZE @@ -271,14 +276,156 @@ func QueryInvitationAll(ctx *context.Context) { queryDataFromStaticTable(ctx, "public.user_business_analysis_all", new(models.UserBusinessAnalysisAll)) } -// func queryData(ctx *context.Context, startTime int64, endTime int64) { -// page, pageSize := getPageInfo(ctx) -// result, count := models.QueryInvitaionPage(startTime, endTime, (page-1)*pageSize, pageSize) -// mapInterface := make(map[string]interface{}) -// mapInterface["data"] = result -// mapInterface["count"] = count -// ctx.JSON(http.StatusOK, mapInterface) -// } +func QueryUserDefineInvitationPage(ctx *context.Context) { + startDate := ctx.Query("startDate") + endDate := ctx.Query("endDate") + startTime, _ := time.ParseInLocation("2006-01-02", startDate, time.Local) + //startTime = startTime.UTC() + endTime, _ := time.ParseInLocation("2006-01-02", endDate, time.Local) + + queryData(ctx, startTime, endTime) +} + +func queryData(ctx *context.Context, startTime time.Time, endTime time.Time) { + page, pageSize := getPageInfo(ctx) + IsReturnFile := ctx.QueryBool("IsReturnFile") + + dbResult := models.QueryInvitaionByTime(startTime.Unix(), endTime.Unix()) + + invitaionNumMap := make(map[int64]int, 0) + allUserIds := make([]int64, 0) + for _, record := range dbResult { + if _, ok := invitaionNumMap[record.SrcUserID]; !ok { + invitaionNumMap[record.SrcUserID] = 1 + } else { + invitaionNumMap[record.SrcUserID] = invitaionNumMap[record.SrcUserID] + 1 + } + } + invitaionNumList := make([]models.Invitation, 0) + for key, value := range invitaionNumMap { + invi := models.Invitation{ + SrcUserID: key, + InvitationUserNum: value, + } + invitaionNumList = append(invitaionNumList, invi) + allUserIds = append(allUserIds, key) + } + sort.Slice(invitaionNumList, func(i, j int) bool { + return invitaionNumList[i].InvitationUserNum > invitaionNumList[j].InvitationUserNum + }) + if IsReturnFile { + xlsx := excelize.NewFile() + sheetName := ctx.Tr("user.static.invitationsheetname") + index := xlsx.NewSheet(sheetName) + xlsx.DeleteSheet("Sheet1") + excelHeader := getInvitationExcelHeader(ctx) + for k, v := range excelHeader { + //设置单元格的值 + xlsx.SetCellValue(sheetName, k, v) + } + end := 100 + userMap := make(map[int64]*models.User, 0) + log.Info("len(allUserIds)=" + fmt.Sprint(len(allUserIds))) + for i := 0; i < len(allUserIds); i += 100 { + if end >= len(allUserIds) { + end = len(allUserIds) + } + log.Info("i=" + fmt.Sprint(i) + " end=" + fmt.Sprint(end)) + if i == end { + break + } + userList, err := models.GetUsersByIDs(allUserIds[i:end]) + if err == nil { + for _, tmp := range userList { + userMap[tmp.ID] = tmp + } + } else { + + } + end = end + 100 + } + row := 1 + log.Info("len(userMap)=" + fmt.Sprint(len(userMap))) + for _, userRecord := range invitaionNumList { + row++ + rows := fmt.Sprint(row) + var tmp byte + tmp = 0 + + xlsx.SetCellValue(sheetName, getColumn(tmp)+rows, userRecord.SrcUserID) + tmp = tmp + 1 + name := "已注销" + if userMap[userRecord.SrcUserID] != nil { + name = userMap[userRecord.SrcUserID].Name + } + xlsx.SetCellValue(sheetName, getColumn(tmp)+rows, name) + tmp = tmp + 1 + + xlsx.SetCellValue(sheetName, getColumn(tmp)+rows, userRecord.InvitationUserNum) + tmp = tmp + 1 + Phone := "" + if userMap[userRecord.SrcUserID] != nil { + Phone = userMap[userRecord.SrcUserID].PhoneNumber + } + xlsx.SetCellValue(sheetName, getColumn(tmp)+rows, Phone) + tmp = tmp + 1 + + formatTime := "" + if userMap[userRecord.SrcUserID] != nil { + formatTime = userMap[userRecord.SrcUserID].CreatedUnix.Format("2006-01-02 15:04:05") + formatTime = formatTime[0 : len(formatTime)-3] + } + xlsx.SetCellValue(sheetName, getColumn(tmp)+rows, formatTime) + } + //设置默认打开的表单 + xlsx.SetActiveSheet(index) + filename := sheetName + "_" + getTimeFileName(startTime) + "_" + getTimeFileName(endTime) + ".xlsx" + //filename := sheetName + "_" + ctx.Tr("user.static."+tableName) + ".xlsx" + ctx.Resp.Header().Set("Content-Disposition", "attachment; filename="+url.QueryEscape(filename)) + ctx.Resp.Header().Set("Content-Type", "application/octet-stream") + if _, err := xlsx.WriteTo(ctx.Resp); err != nil { + log.Info("writer exel error." + err.Error()) + } + } else { + result := make([]*models.Invitation, 0) + userIds := make([]int64, 0) + end := len(invitaionNumList) - 1 + for start := (page - 1) * pageSize; start <= end; start++ { + invi := invitaionNumList[start] + //todo name phone,createunix + result = append(result, &invi) + userIds = append(userIds, invi.SrcUserID) + if len(result) == pageSize { + break + } + } + userList, err := models.GetUsersByIDs(userIds) + if err == nil { + for _, invi := range result { + tmpUser := userList[0] + for _, tmp := range userList { + if tmp.ID == invi.SrcUserID { + tmpUser = tmp + break + } + } + if invi.SrcUserID == tmpUser.ID { + invi.Name = tmpUser.Name + invi.Phone = tmpUser.PhoneNumber + invi.CreatedUnix = tmpUser.CreatedUnix + } else { + invi.Name = "已注销" + } + } + } else { + log.Info("query user error." + err.Error()) + } + mapInterface := make(map[string]interface{}) + mapInterface["data"] = result + mapInterface["count"] = len(invitaionNumList) + ctx.JSON(http.StatusOK, mapInterface) + } +} func getPageInfo(ctx *context.Context) (int, int) { page := ctx.QueryInt("page") diff --git a/services/task/task.go b/services/task/task.go index 194a43649..f9a6d0c0c 100644 --- a/services/task/task.go +++ b/services/task/task.go @@ -61,7 +61,7 @@ func Accomplish(action models.Action) { actions = append(actions, models.Action{ ID: action.ID, OpType: models.ActionDatasetRecommended, - ActUserID: action.UserID, + ActUserID: action.ActUserID, UserID: user.ID, RepoID: action.RepoID, Content: action.Content, @@ -85,7 +85,11 @@ func accomplish(action models.Action, taskType models.TaskType) error { log.Error("PANIC:%v", combinedErr) } }() + log.Info("accomplish start. actionId=%d userId= %d", action.ID, action.UserID) userId := action.UserID + if !isUserAvailable(userId) { + return nil + } //get task config config, err := GetTaskConfig(string(taskType)) @@ -127,7 +131,7 @@ func accomplish(action models.Action, taskType models.TaskType) error { Type: models.GetRewardTypeInstance(config.AwardType), }, TargetUserId: userId, - RequestId: fmt.Sprint(action.ID), + RequestId: fmt.Sprintf("%d_%d", action.ID, userId), OperateType: models.OperateTypeIncrease, RejectPolicy: models.FillUp, }) @@ -143,3 +147,17 @@ func isLimited(userId int64, config *models.TaskConfig, rejectPolicy models.Limi return false } + +func isUserAvailable(userId int64) bool { + if userId < 1 { + return false + } + user, err := models.GetUserByID(userId) + if err != nil || user == nil { + return false + } + if user.IsOrganization() { + return false + } + return true +} diff --git a/templates/admin/cloudbrain/list.tmpl b/templates/admin/cloudbrain/list.tmpl index 14951dd69..89649a307 100755 --- a/templates/admin/cloudbrain/list.tmpl +++ b/templates/admin/cloudbrain/list.tmpl @@ -205,11 +205,12 @@
- {{.JobName}} diff --git a/templates/repo/grampus/trainjob/npu/new.tmpl b/templates/repo/grampus/trainjob/npu/new.tmpl index 92dca5bae..51a561d3d 100755 --- a/templates/repo/grampus/trainjob/npu/new.tmpl +++ b/templates/repo/grampus/trainjob/npu/new.tmpl @@ -106,7 +106,7 @@ {{template "custom/task_wait_count" .}}
- {{.i18n.Tr "cloudbrain.new_train_gpu_tooltips" "/cache/code" "/cache/dataset" "ckpt_url" "/cache/output" | Safe}} + {{.i18n.Tr "cloudbrain.new_train_npu_tooltips" "/cache/code" "ckpt_url" "/cache/output" | Safe}}
diff --git a/templates/reward/point/rule.tmpl b/templates/reward/point/rule.tmpl index 6e7a0a8cc..9b9a354f2 100644 --- a/templates/reward/point/rule.tmpl +++ b/templates/reward/point/rule.tmpl @@ -73,7 +73,7 @@ 数据集被平台推荐 - 每日积分获取上限 - - 仅统计属于个人的数据集,属于组织的数据集暂不统计。 + 数据集被推荐时,所有文件上传者都可获得奖励积分。 导入新模型 diff --git a/templates/user/dashboard/cloudbrains.tmpl b/templates/user/dashboard/cloudbrains.tmpl index 17b40315c..defed27bc 100755 --- a/templates/user/dashboard/cloudbrains.tmpl +++ b/templates/user/dashboard/cloudbrains.tmpl @@ -15,11 +15,11 @@ data-all-compute="{{.i18n.Tr "admin.cloudbrain.all_computing_resources"}}" data-all-status="{{.i18n.Tr "admin.cloudbrain.all_status"}}">
{{template "admin/cloudbrain/search_dashboard" .}} -
+
{{template "base/alert" .}} -
+
-
+
@@ -377,19 +377,18 @@
{{end}} - {{end}} -
-
- - -
-
+ {{end}}
-
+
+
+
+
+ +
diff --git a/web_src/vuepages/langs/config/zh-CN.js b/web_src/vuepages/langs/config/zh-CN.js index e48e61e3a..2b451e2db 100644 --- a/web_src/vuepages/langs/config/zh-CN.js +++ b/web_src/vuepages/langs/config/zh-CN.js @@ -164,9 +164,9 @@ const zh = { }, user: { inviteFriends: '邀请好友', - inviteFriendsTips: '复制二维码或者邀请注册链接分享给好友', + inviteFriendsTips: '复制二维码或者注册邀请链接分享给好友', clickToViewTheEventDetails: '点击查看活动详情', - copyRegistrationInvitationLink: '复制邀请注册链接', + copyRegistrationInvitationLink: '复制注册邀请链接', registrationAdress: '注册地址:', recommender: '推荐人:', invitedFriends: '已邀请好友', diff --git a/web_src/vuepages/pages/resources/specification/index.vue b/web_src/vuepages/pages/resources/specification/index.vue index 58d95d74f..17ca4870c 100644 --- a/web_src/vuepages/pages/resources/specification/index.vue +++ b/web_src/vuepages/pages/resources/specification/index.vue @@ -21,8 +21,8 @@
-
- +
+ diff --git a/web_src/vuepages/pages/user/invite/index.vue b/web_src/vuepages/pages/user/invite/index.vue index 37a39b8fe..c48cc75ef 100644 --- a/web_src/vuepages/pages/user/invite/index.vue +++ b/web_src/vuepages/pages/user/invite/index.vue @@ -22,7 +22,7 @@
{{ $t('user.registrationAdress') }}{{ invitationLink + invitationCode }}
{{ $t('user.recommender') }}{{ invitationCode }}
- {{ $t('user.copyRegistrationInvitationLink') }} + {{ $t('user.copyRegistrationInvitationLink') }}
@@ -31,7 +31,7 @@
- +