Browse Source

Merge pull request 'point-v2' (#2900) from point-v2 into V20220926

Reviewed-on: https://git.openi.org.cn/OpenI/aiforge/pulls/2900
Reviewed-by: chenyifan01 <cyf_uestc@outlook.com>
tags/v1.22.9.2^2
chenyifan01 3 years ago
parent
commit
b6d8ac5150
8 changed files with 169 additions and 51 deletions
  1. +1
    -0
      models/cloudbrain_static.go
  2. +13
    -0
      models/task_config.go
  3. +2
    -0
      routers/api/v1/repo/cloudbrain_dashboard.go
  4. +12
    -0
      routers/reward/point/point.go
  5. +1
    -0
      routers/routes/routes.go
  6. +45
    -0
      services/task/task_config.go
  7. +86
    -45
      templates/reward/point/rule.tmpl
  8. +9
    -6
      web_src/vuepages/pages/reward/point/vp-point.vue

+ 1
- 0
models/cloudbrain_static.go View File

@@ -34,6 +34,7 @@ type TaskDetail struct {
CardDuration string `json:"CardDuration"`
AiCenter string `json:"AiCenter"`
FlavorName string `json:"FlavorName"`
Spec *Specification `json:"Spec"`
}

func GetTodayCreatorCount(beginTime time.Time, endTime time.Time) (int64, error) {


+ 13
- 0
models/task_config.go View File

@@ -65,6 +65,19 @@ type TaskAndLimiterConfig struct {
LimitConfig LimitConfig `xorm:"extends"`
}

type PointRule struct {
UserDailyLimit int64
TaskRules []TaskRule
}

type TaskRule struct {
TaskCode string
AwardType string
AwardAmount int64
RefreshRate string
LimitNum int64
}

func (TaskAndLimiterConfig) TableName() string {
return "task_config"
}


+ 2
- 0
routers/api/v1/repo/cloudbrain_dashboard.go View File

@@ -733,6 +733,7 @@ func GetCloudbrainsDetailData(ctx *context.Context) {
ctx.ServerError("Get job failed:", err)
return
}
models.LoadSpecs4CloudbrainInfo(ciTasks)
nilTime := time.Time{}
tasks := []models.TaskDetail{}
for i, task := range ciTasks {
@@ -769,6 +770,7 @@ func GetCloudbrainsDetailData(ctx *context.Context) {
} else {
taskDetail.IsDelete = false
}
taskDetail.Spec = ciTasks[i].Spec
tasks = append(tasks, taskDetail)
}



+ 12
- 0
routers/reward/point/point.go View File

@@ -8,6 +8,7 @@ import (
"code.gitea.io/gitea/routers/response"
"code.gitea.io/gitea/services/reward"
"code.gitea.io/gitea/services/reward/point/account"
"code.gitea.io/gitea/services/task"
"errors"
"net/http"
)
@@ -92,6 +93,17 @@ func GetRulePage(ctx *context.Context) {
ctx.HTML(200, tplPointRule)
}

func GetRuleConfig(ctx *context.Context) {
r, err := task.GetPointRule()
if err != nil {
log.Error("GetRuleConfig error.%v", err)
ctx.JSON(http.StatusOK, response.ServerError(err.Error()))
return
}

ctx.JSON(http.StatusOK, response.SuccessWithData(r))
}

func GetAdminRewardList(ctx *context.Context) {
opts, err := buildAdminRewardRecordListOpts(ctx)
if err != nil {


+ 1
- 0
routers/routes/routes.go View File

@@ -1432,6 +1432,7 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Group("/reward/point", func() {
m.Get("", point.GetPointPage)
m.Get("/rule", point.GetRulePage)
m.Get("/rule/config", point.GetRuleConfig)
m.Get("/account", point.GetPointAccount)
m.Get("/record/list", point.GetPointRecordList)
}, reqSignIn)


+ 45
- 0
services/task/task_config.go View File

@@ -6,8 +6,10 @@ import (
"code.gitea.io/gitea/modules/redis/redis_client"
"code.gitea.io/gitea/modules/redis/redis_key"
"code.gitea.io/gitea/modules/redis/redis_lock"
"code.gitea.io/gitea/services/reward/limiter"
"encoding/json"
"errors"
"fmt"
"time"
)

@@ -181,3 +183,46 @@ func DelTaskConfig(id int64, doer *models.User) error {
redis_client.Del(redis_key.TaskConfigList())
return nil
}

func GetPointRule() (*models.PointRule, error) {
r, err := limiter.GetSingleDailyPointLimitConfig()
if err != nil {
return nil, err
}
limiters, err := limiter.GetLimitersByLimitType(models.LimitTypeTask)
if err != nil {
return nil, err
}
limiterMap := make(map[string]*models.LimitConfig, 0)
for i := 0; i < len(limiters); i++ {
limiterMap[limiters[i].LimitCode] = &limiters[i]
}

taskConfigs, err := GetTaskConfigList()
if err != nil {
return nil, err
}
taskRules := make([]models.TaskRule, len(taskConfigs))

for i, taskConfig := range taskConfigs {
rule := models.TaskRule{
TaskCode: taskConfig.TaskCode,
AwardType: taskConfig.AwardType,
AwardAmount: taskConfig.AwardAmount,
}
limiter := limiterMap[fmt.Sprint(taskConfig.TaskCode)]
if limiter != nil {
rule.RefreshRate = limiter.RefreshRate
rule.LimitNum = limiter.LimitNum
}
taskRules[i] = rule
}

pointRule := &models.PointRule{
TaskRules: taskRules,
}
if r != nil {
pointRule.UserDailyLimit = r.LimitNum
}
return pointRule, nil
}

+ 86
- 45
templates/reward/point/rule.tmpl View File

@@ -16,10 +16,10 @@
text-align: center;
}
</style>
<div class="ui container">
<div class="ui container rule-container" style="display:none;">
<h1 class="ui center am-pt-30 am-pb-20">个人算力积分奖励规则</h1>
<div class="ui divider am-pb-10"></div>
<p>说明:单日用户积分的获取上限为50分。</p>
<p>说明:单日用户积分的获取上限为<span class="daily-limit"> - </span>分。该积分仅用于算力资源使用,打榜活动积分将另行计算。</p>
<table class="m-table">
<tr>
<th style="width:200px;">奖励名称</th>
@@ -27,85 +27,126 @@
<th style="width:200px;">上限值</th>
<th>奖励细节澄清</th>
</tr>
<tr>
<tr key="34">
<td class="t-center">完成微信扫码验证</td>
<td class="t-center">50</td>
<td class="t-center">累计积分获取上限50</td>
<td>1、首次完成微信扫码验证,即获取50积分。<br>2、同个账号,更换微信号码再验证不重复给积分。<br>3、同一个微信,绑定第一个账号时奖励50分,下次绑定其他账号时不再奖励。</td>
<td class="t-center point">-</td>
<td class="t-center"><span class="typ">累计</span>积分获取上限<span class="limit"> - </span></td>
<td>1、首次完成微信扫码验证,即获取积分。<br>2、同个账号,更换微信号码再验证不重复给积分。<br>3、同一个微信,绑定第一个账号时奖励分,下次绑定其他账号时不再奖励。</td>
</tr>
<tr>
<tr key="1">
<td class="t-center">创建或Fork公开项目</td>
<td class="t-center">1</td>
<td class="t-center">每日积分获取上限3</td>
<td class="t-center point">-</td>
<td class="t-center"><span class="typ">每日</span>积分获取上限<span class="limit"> - </span></td>
<td>请注意项目质量,请勿复制粘贴或者重复公开项目,任何非常规的以公开项目去获取积分的行为将被认定为积分舞弊,将扣除所有积分。</td>
</tr>
<tr>
<tr key="7">
<td class="t-center">每日提出PR</td>
<td class="t-center">1</td>
<td class="t-center">每日积分获取上限3</td>
<td class="t-center point">-</td>
<td class="t-center"><span class="typ">每日</span>积分获取上限<span class="limit"> - </span></td>
<td></td>
</tr>
<tr>
<tr key="40">
<td class="t-center">每日commit</td>
<td class="t-center">1</td>
<td class="t-center">每日积分获取上限3</td>
<td class="t-center point">-</td>
<td class="t-center"><span class="typ">每日</span>积分获取上限<span class="limit"> - </span></td>
<td>通过前台界面和后台命令行方式commit,都可获得奖励积分。</td>
</tr>
<tr>
<tr key="6">
<td class="t-center">每日提出任务</td>
<td class="t-center">1</td>
<td class="t-center">每日积分获取上限3</td>
<td class="t-center point">-</td>
<td class="t-center"><span class="typ">每日</span>积分获取上限<span class="limit"> - </span></td>
<td></td>
</tr>
<tr>
<tr key="10">
<td class="t-center">发表评论</td>
<td class="t-center">1</td>
<td class="t-center">每日积分获取上限2</td>
<td class="t-center point">-</td>
<td class="t-center"><span class="typ">每日</span>积分获取上限<span class="limit"> - </span></td>
<td>禁止空评论或评论后马上删除等非正常获取积分的方式,一经发现将扣除所有积分。</td>
</tr>
<tr>
<tr key="24">
<td class="t-center">上传数据集文件</td>
<td class="t-center">1</td>
<td class="t-center">每日积分获取上限1</td>
<td class="t-center point">-</td>
<td class="t-center"><span class="typ">每日</span>积分获取上限<span class="limit"> - </span></td>
<td>请注意数据集质量,请勿复制粘贴或者重复公开数据集,任何非常规的以公开数据集去获取积分的行为将被认定为积分舞弊,将扣除所有积分。</td>
</tr>
<tr>
<tr key="36">
<td class="t-center">数据集被平台推荐</td>
<td class="t-center">5</td>
<td class="t-center">每日积分获取上限15</td>
<td class="t-center point">-</td>
<td class="t-center"><span class="typ">每日</span>积分获取上限<span class="limit"> - </span></td>
<td>仅统计属于个人的数据集,属于组织的数据集暂不统计。</td>
</tr>
<tr>
<tr key="30">
<td class="t-center">导入新模型</td>
<td class="t-center">1</td>
<td class="t-center">每日积分获取上限3</td>
<td class="t-center point">-</td>
<td class="t-center"><span class="typ">每日</span>积分获取上限<span class="limit"> - </span></td>
<td>请注意模型质量,请勿重复导入相同模型,任何非常规的以导入新模型去获取 积分的行为将被认定为积分舞弊,将扣除所有积分。</td>
</tr>
<tr>
<tr key="35">
<td class="t-center">每日运行云脑任务</td>
<td class="t-center">10</td>
<td class="t-center">每日积分获取上限10</td>
<td class="t-center point">-</td>
<td class="t-center"><span class="typ">每日</span>积分获取上限<span class="limit"> - </span></td>
<td> 每日运行调试、训练、推理、评测中任何一种任务,即可获得。</td>
</tr>
<tr>
<tr key="37">
<td class="t-center">提交新公开镜像</td>
<td class="t-center">1</td>
<td class="t-center">每日积分获取上限3</td>
<td class="t-center point">-</td>
<td class="t-center"><span class="typ">每日</span>积分获取上限<span class="limit"> - </span></td>
<td></td>
</tr>
<tr>
<tr key="38">
<td class="t-center">镜像被平台推荐</td>
<td class="t-center">5</td>
<td class="t-center">每日积分获取上限15</td>
<td class="t-center point">-</td>
<td class="t-center"><span class="typ">每日</span>积分获取上限<span class="limit"> - </span></td>
<td></td>
</tr>
<tr>
<tr key="39">
<td class="t-center">首次更换头像</td>
<td class="t-center">2</td>
<td class="t-center">累计积分获取上限2</td>
<td>首次更换头像,积分+2。</td>
<td class="t-center point">-</td>
<td class="t-center"><span class="typ">累计</span>积分获取上限<span class="limit"> - </span></td>
<td>首次更换头像,获得积分。</td>
</tr>
</table>

</div>
{{template "base/footer" .}}

{{template "base/footer" .}}
<script>
;(function() {
var ruleContainer = $('.rule-container');
var dailyLimitEl = ruleContainer.find('.daily-limit');
var ruleTrs = ruleContainer.find('tr[key]');
$.ajax({
url: '/reward/point/rule/config',
type: "get",
data: {},
contentType: "application/json; charset=utf-8",
success(res) {
if (res && res.Code === 0) {
var data = res.Data;
dailyLimitEl.text(data.UserDailyLimit);
var taskRules = data.TaskRules;
for (var i = 0, iLen = ruleTrs.length; i < iLen; i++) {
var ruleTr = ruleTrs.eq(i);
var key = ruleTr.attr('key');
var findOr = false;
for (var j = 0, jLen = taskRules.length; j < jLen; j++) {
var taskRule = taskRules[j];
if (taskRule.TaskCode == key) {
ruleTr.find('.point').text(taskRule.AwardAmount);
ruleTr.find('.typ').text(taskRule.RefreshRate == 'DAILY' ? '每日' : taskRule.RefreshRate == 'NOT_CYCLE' ? '累计' : taskRule.RefreshRate);
ruleTr.find('.limit').text(taskRule.LimitNum);
findOr = true;
break;
}
}
if (!findOr) ruleTr.hide();
}
}
ruleContainer.show();
},
error(err) {
console.log(err);
ruleContainer.show();
},
});
})();
</script>

+ 9
- 6
web_src/vuepages/pages/reward/point/vp-point.vue View File

@@ -16,11 +16,11 @@
</div>
</div>
<div class="__r_p_summary">
<div class="__r_p_summary_item-c __flex-1">
<div class="__r_p_summary_item-c __flex-1" style="position:relative;">
<div class="__val">{{ summaryInfo.available }}</div>
<div class="__exp">{{ $t('CurrAvailableCalcPoints') }}</div>
</div>
<div class="__r_p_summary_line"></div>
<div class="__r_p_summary_line"></div>
</div>
<div class="__r_p_summary_item-c __flex-1">
<div class="__val">{{ summaryInfo.gain }}</div>
<div class="__exp">{{ $t('totalGainCalcPoints') }}</div>
@@ -28,7 +28,7 @@
<div class="__r_p_summary_item-c __flex-1">
<div class="__val">{{ summaryInfo.used }}</div>
<div class="__exp">{{ $t('totalConsumeCalcPoints') }}</div>
</div>
</div>
</div>
<div class="__r_p_tab">
<div class="__r_p_tab-item" :class="tabIndex === 0 ? '__focus' : ''" style="border-radius: 5px 0px 0px 5px"
@@ -267,9 +267,12 @@ export default {
}

.__r_p_summary_line {
position: absolute;
top: 0;
right: 1px;
width: 1px;
height: 80%;
background-color: rgb(212, 212, 213);
height: 100%;
border-right: 1px solid rgb(212, 212, 213);
}

.__r_p_tab {


Loading…
Cancel
Save