|
-
- import { formatDate } from 'element-ui/lib/utils/date-util';
- import { SOURCE_TYPE, CONSUME_STATUS, POINT_ACTIONS, JOB_TYPE } from '~/const';
- import { i18n } from '~/langs';
-
- const getSourceType = (key) => {
- const find = SOURCE_TYPE.filter(item => item.k === key);
- return find.length ? find[0].v : key;
- };
-
- const getConsumeStatus = (key) => {
- const find = CONSUME_STATUS.filter(item => item.k === key);
- return find.length ? find[0].v : key;
- };
-
- const getPointAction = (key) => {
- const find = POINT_ACTIONS.filter(item => item.k === key);
- return find.length ? find[0].v : key;
- };
-
- const getJobType = (key) => {
- const find = JOB_TYPE.filter(item => item.k === key);
- return find.length ? find[0].v : key;
- };
-
- const getJobTypeLink = (record, type) => {
- let link = type === 'INCREASE' ? record.Action.RepoLink : '/' + record.Cloudbrain.RepoFullName;
- const cloudbrain = type === 'INCREASE' ? record.Action?.Cloudbrain : record.Cloudbrain;
- switch (cloudbrain?.JobType) {
- case 'DEBUG':
- if (cloudbrain.ComputeResource === 'CPU/GPU') {
- link += `/cloudbrain/${cloudbrain.ID}`;
- } else {
- link += `/modelarts/notebook/${cloudbrain.ID}`;
- }
- break;
- case 'TRAIN':
- if (cloudbrain.Type === 1) {
- link += `/modelarts/train-job/${cloudbrain.JobID}`;
- } else if (cloudbrain.Type === 0) {
- link += `/cloudbrain/train-job/${cloudbrain.JobID}`;
- } else if (cloudbrain.Type === 2) {
- link += `/grampus/train-job/${cloudbrain.JobID}`;
- }
- break;
- case 'INFERENCE':
- link += `/modelarts/inference-job/${cloudbrain.JobID}`;
- break;
- case 'BENCHMARK':
- link += `/cloudbrain/benchmark/${cloudbrain.ID}`;
- break;
- default:
- break;
- };
- return link;
- };
-
- export const getRewardPointRecordInfo = (record) => {
- const out = {
- sn: record.SerialNo,
- date: formatDate(new Date(record.LastOperateDate * 1000), 'yyyy-MM-dd HH:mm:ss'),
- _status: record.Status,
- status: getConsumeStatus(record.Status) || '--',
- statusColor: record.Status === 'OPERATING' ? 'rgb(33, 186, 69)' : '',
- _sourceType: record.SourceType,
- sourceType: getSourceType(record.SourceType),
- duration: record?.Cloudbrain?.Duration || '--',
- taskName: record?.Cloudbrain?.DisplayJobName || '--',
- taskId: record?.Cloudbrain?.ID,
- action: record?.Action?.OpType ? getPointAction(record.Action.OpType) : '--',
- remark: record.Remark,
- amount: record.Amount,
- };
- if (record.OperateType === 'INCREASE') {
- if (record.SourceType === 'ADMIN_OPERATE') {
- out.remark = record.Remark;
- } else if (record.SourceType === 'ACCOMPLISH_TASK') {
- switch (record?.Action?.OpType) {
- case 1: // 创建公开项目 - 创建了项目OpenI/aiforge
- out.remark = `${i18n.t('createdRepository')}<a href="${record.Action.RepoLink}" rel="nofollow">${record.Action.ShortRepoFullDisplayName}</a>`;
- break;
- case 6: // 每日提出任务 - 创建了任务PCL-Platform.Intelligence/AISynergy#19
- out.remark = `${i18n.t('openedIssue')}<a href="${record.Action.RepoLink}/issues/${record.Action.IssueInfos[0]}" rel="nofollow">${record.Action.ShortRepoFullDisplayName}#${record.Action.IssueInfos[0]}</a>`;
- break;
- case 7: // 每日提出PR - 创建了合并请求OpenI/aiforge#1
- out.remark = `${i18n.t('createdPullRequest')}<a href="${record.Action.RepoLink}/pulls/${record.Action.IssueInfos[0]}" rel="nofollow">${record.Action.ShortRepoFullDisplayName}#${record.Action.IssueInfos[0]}</a>`;
- break;
- case 10: // 发表评论 - 评论了任务PCL-Platform.Intelligence/AISynergy#19
- out.remark = `${i18n.t('commentedOnIssue')}<a href="${record.Action.CommentLink}" rel="nofollow">${record.Action.ShortRepoFullDisplayName}#${record.Action.IssueInfos[0]}</a>`;
- break;
- case 24: // 上传数据集文件 - 上传了数据集文件MMISTData.zip
- out.remark = `${i18n.t('uploadDataset')}<a href="${record.Action.RepoLink}/datasets" rel="nofollow">${record.Action.RefName}</a>`;
- break;
- case 30: // 导入新模型 - 导入了新模型resnet50_qx7l
- out.remark = `${i18n.t('createdNewModel')}<a href="${record.Action.RepoLink}/modelmanage/show_model_info?name=${record.Action.RefName}" rel="nofollow">${record.Action.RefName}</a>`;
- break;
- case 34: // 完成微信扫码验证 - 首次绑定微信奖励
- out.remark = `${i18n.t('firstBindingWechatRewards')}`;
- break;
- case 35: // 每日运行云脑任务 - 创建了(CPU/GPU/NPU)类型(调试/训练/推理/评测)任务tangl202204131431995
- out.remark = `${i18n.t('created')}${record.Action?.Cloudbrain?.ComputeResource}${i18n.t('type')}${getJobType(record.Action?.Cloudbrain?.JobType)} <a href="${getJobTypeLink(record, 'INCREASE')}" rel="nofollow">${record.Action.RefName}</a>`;
- break;
- case 36: // 数据集被平台推荐 - 数据集XXX被设置为推荐数据集
- out.remark = `${i18n.t('dataset')}<a href="${record.Action.RepoLink}/datasets" rel="nofollow">${record.Action.Content && record.Action.Content.split('|')[1]}</a>${i18n.t('setAsRecommendedDataset')}`;
- break;
- case 37: // 提交新公开镜像 - 提交了镜像jiangxiang_ceshi_tang03
- out.remark = `${i18n.t('committedImage')}<span style="font-weight:bold;">${record.Action.Content && record.Action.Content.split('|')[1]}</span>`;
- break;
- case 38: // 镜像被平台推荐 - 镜像XXX被设置为推荐镜像
- out.remark = `${i18n.t('image')}<span style="font-weight:bold;">${record.Action.Content && record.Action.Content.split('|')[1]}</span>${i18n.t('setAsRecommendedImage')}`;
- break;
- case 39: // 首次更换头像 - 更新了头像
- out.remark = `${i18n.t('updatedAvatar')}`;
- break;
- case 40: // 每日commit - 推送了xxxx分支的代码到OpenI/aiforge
- const words = record.Action.RefName.split('/');
- const branch = words[words.length - 1];
- out.remark = `${i18n.t('pushedBranch', {
- branch: `<a href="${record.Action.RepoLink}/src/branch/${branch}" rel="nofollow">${branch}</a>`
- })}<a href="${record.Action.RepoLink}" rel="nofollow">${record.Action.ShortRepoFullDisplayName}</a>`;
- break;
- default:
- break;
- }
- } else if (record.SourceType === 'RUN_CLOUDBRAIN_TASK') {
- //
- }
- if (record.LossAmount !== 0) {
- out.amount = record.Amount;
- out.remark += `${out.remark ? i18n.t(';') : ''}${i18n.t('dailyMaxTips')}`;
- }
- } else if (record.OperateType === 'DECREASE') {
- if (record.SourceType === 'ADMIN_OPERATE') {
- out.remark = record.Remark;
- } else if (record.SourceType === 'ACCOMPLISH_TASK') {
- //
- } else if (record.SourceType === 'RUN_CLOUDBRAIN_TASK') {
- out.taskName = `<a href="${getJobTypeLink(record, 'DECREASE')}" rel="nofollow">${record?.Cloudbrain?.DisplayJobName}</a>`;
- if (record?.Cloudbrain?.ComputeResource === 'CPU/GPU') {
- const resourceSpec = record?.Cloudbrain?.ResourceSpec?.ResourceSpec;
- out.remark = `【${getJobType(record?.Cloudbrain?.JobType)}】【${record?.Cloudbrain?.ComputeResource}】【GPU: ${resourceSpec?.gpu}, CPU: ${resourceSpec?.cpu}, ${i18n.t('memory')}: ${(resourceSpec?.memMiB / 1024).toFixed(2)}GB, ${i18n.t('sharedMemory')}: ${(resourceSpec?.shareMemMiB / 1024).toFixed(2)}GB】`;
- } else {
- out.remark = `【${getJobType(record?.Cloudbrain?.JobType)}】【${record?.Cloudbrain?.ComputeResource}】【${record?.Cloudbrain?.ResourceSpec.FlavorInfo.desc}】`;
- }
- }
- }
- return out;
- };
|