You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

utils.js 8.3 kB

3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
3 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
3 years ago
2 years ago
2 years ago
2 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. import { formatDate } from 'element-ui/lib/utils/date-util';
  2. import { SOURCE_TYPE, CONSUME_STATUS, POINT_ACTIONS, JOB_TYPE } from '~/const';
  3. import { i18n } from '~/langs';
  4. const getSourceType = (key) => {
  5. const find = SOURCE_TYPE.filter(item => item.k === key);
  6. return find.length ? find[0].v : key;
  7. };
  8. const getConsumeStatus = (key) => {
  9. const find = CONSUME_STATUS.filter(item => item.k === key);
  10. return find.length ? find[0].v : key;
  11. };
  12. const getPointAction = (key) => {
  13. const find = POINT_ACTIONS.filter(item => item.k === key);
  14. return find.length ? find[0].v : key;
  15. };
  16. const getJobType = (key) => {
  17. const find = JOB_TYPE.filter(item => item.k === key);
  18. return find.length ? find[0].v : key;
  19. };
  20. const getJobTypeLink = (record, type) => {
  21. let link = type === 'INCREASE' ? record.Action.RepoLink : '/' + record.Cloudbrain.RepoFullName;
  22. const cloudbrain = type === 'INCREASE' ? record.Action?.Cloudbrain : record.Cloudbrain;
  23. switch (cloudbrain?.JobType) {
  24. case 'DEBUG':
  25. if (cloudbrain.ComputeResource === 'CPU/GPU') {
  26. link += `/cloudbrain/${cloudbrain.ID}`;
  27. } else {
  28. link += `/modelarts/notebook/${cloudbrain.ID}`;
  29. }
  30. break;
  31. case 'TRAIN':
  32. if (cloudbrain.Type === 1) {
  33. link += `/modelarts/train-job/${cloudbrain.JobID}`;
  34. } else if (cloudbrain.Type === 0) {
  35. link += `/cloudbrain/train-job/${cloudbrain.JobID}`;
  36. } else if (cloudbrain.Type === 2) {
  37. link += `/grampus/train-job/${cloudbrain.JobID}`;
  38. }
  39. break;
  40. case 'INFERENCE':
  41. link += `/modelarts/inference-job/${cloudbrain.JobID}`;
  42. break;
  43. case 'BENCHMARK':
  44. link += `/cloudbrain/benchmark/${cloudbrain.ID}`;
  45. break;
  46. default:
  47. break;
  48. };
  49. return link;
  50. };
  51. export const getRewardPointRecordInfo = (record) => {
  52. const out = {
  53. sn: record.SerialNo,
  54. date: formatDate(new Date(record.LastOperateDate * 1000), 'yyyy-MM-dd HH:mm:ss'),
  55. _status: record.Status,
  56. status: getConsumeStatus(record.Status) || '--',
  57. statusColor: record.Status === 'OPERATING' ? 'rgb(33, 186, 69)' : '',
  58. _sourceType: record.SourceType,
  59. sourceType: getSourceType(record.SourceType),
  60. duration: record?.Cloudbrain?.Duration || '--',
  61. taskName: record?.Cloudbrain?.DisplayJobName || '--',
  62. taskId: record?.Cloudbrain?.ID,
  63. action: record?.Action?.OpType ? getPointAction(record.Action.OpType) : '--',
  64. remark: record.Remark,
  65. amount: record.Amount,
  66. };
  67. if (record.OperateType === 'INCREASE') {
  68. if (record.SourceType === 'ADMIN_OPERATE') {
  69. out.remark = record.Remark;
  70. } else if (record.SourceType === 'ACCOMPLISH_TASK') {
  71. switch (record?.Action?.OpType) {
  72. case 1: // 创建公开项目 - 创建了项目OpenI/aiforge
  73. out.remark = `${i18n.t('createdRepository')}<a href="${record.Action.RepoLink}" rel="nofollow">${record.Action.ShortRepoFullDisplayName}</a>`;
  74. break;
  75. case 6: // 每日提出任务 - 创建了任务PCL-Platform.Intelligence/AISynergy#19
  76. 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>`;
  77. break;
  78. case 7: // 每日提出PR - 创建了合并请求OpenI/aiforge#1
  79. 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>`;
  80. break;
  81. case 10: // 发表评论 - 评论了任务PCL-Platform.Intelligence/AISynergy#19
  82. out.remark = `${i18n.t('commentedOnIssue')}<a href="${record.Action.CommentLink}" rel="nofollow">${record.Action.ShortRepoFullDisplayName}#${record.Action.IssueInfos[0]}</a>`;
  83. break;
  84. case 24: // 上传数据集文件 - 上传了数据集文件MMISTData.zip
  85. out.remark = `${i18n.t('uploadDataset')}<a href="${record.Action.RepoLink}/datasets" rel="nofollow">${record.Action.RefName}</a>`;
  86. break;
  87. case 30: // 导入新模型 - 导入了新模型resnet50_qx7l
  88. out.remark = `${i18n.t('createdNewModel')}<a href="${record.Action.RepoLink}/modelmanage/show_model_info?name=${record.Action.RefName}" rel="nofollow">${record.Action.RefName}</a>`;
  89. break;
  90. case 34: // 完成微信扫码验证 - 首次绑定微信奖励
  91. out.remark = `${i18n.t('firstBindingWechatRewards')}`;
  92. break;
  93. case 35: // 每日运行云脑任务 - 创建了(CPU/GPU/NPU)类型(调试/训练/推理/评测)任务tangl202204131431995
  94. 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>`;
  95. break;
  96. case 36: // 数据集被平台推荐 - 数据集XXX被设置为推荐数据集
  97. 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')}`;
  98. break;
  99. case 37: // 提交新公开镜像 - 提交了镜像jiangxiang_ceshi_tang03
  100. out.remark = `${i18n.t('committedImage')}<span style="font-weight:bold;">${record.Action.Content && record.Action.Content.split('|')[1]}</span>`;
  101. break;
  102. case 38: // 镜像被平台推荐 - 镜像XXX被设置为推荐镜像
  103. out.remark = `${i18n.t('image')}<span style="font-weight:bold;">${record.Action.Content && record.Action.Content.split('|')[1]}</span>${i18n.t('setAsRecommendedImage')}`;
  104. break;
  105. case 39: // 首次更换头像 - 更新了头像
  106. out.remark = `${i18n.t('updatedAvatar')}`;
  107. break;
  108. case 40: // 每日commit - 推送了xxxx分支的代码到OpenI/aiforge
  109. const words = record.Action.RefName.split('/');
  110. const branch = words[words.length - 1];
  111. // out.remark = `推送了<a href="${record.Action.RepoLink}/src/branch/${branch}" rel="nofollow">${branch}</a>分支的代码到<a href="${record.Action.RepoLink}" rel="nofollow">${record.Action.ShortRepoFullDisplayName}</a>`;
  112. out.remark = `${i18n.t('pushedBranch', {
  113. branch: `<a href="${record.Action.RepoLink}/src/branch/${branch}" rel="nofollow">${branch}</a>`
  114. })}<a href="${record.Action.RepoLink}" rel="nofollow">${record.Action.ShortRepoFullDisplayName}</a>`;
  115. break;
  116. case 41: // 每日首次Fork项目 - 创建了项目OpenI/fork_aiforge
  117. out.remark = `${i18n.t('createdRepository')}<a href="${record.Action.RepoLink}" rel="nofollow">${record.Action.ShortRepoFullDisplayName}</a>`;
  118. break;
  119. default:
  120. break;
  121. }
  122. } else if (record.SourceType === 'RUN_CLOUDBRAIN_TASK') {
  123. //
  124. }
  125. if (record.LossAmount !== 0) {
  126. out.amount = record.Amount - record.LossAmount;
  127. out.remark += `${out.remark ? i18n.t(';') : ''}${i18n.t('dailyMaxTips')}`
  128. }
  129. } else if (record.OperateType === 'DECREASE') {
  130. if (record.SourceType === 'ADMIN_OPERATE') {
  131. out.remark = record.Remark;
  132. } else if (record.SourceType === 'ACCOMPLISH_TASK') {
  133. //
  134. } else if (record.SourceType === 'RUN_CLOUDBRAIN_TASK') {
  135. out.taskName = `<a href="${getJobTypeLink(record, 'DECREASE')}" rel="nofollow">${record?.Cloudbrain?.DisplayJobName}</a>`;
  136. if (record?.Cloudbrain?.ComputeResource === 'CPU/GPU') {
  137. const resourceSpec = record?.Cloudbrain?.ResourceSpec?.ResourceSpec;
  138. 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】`;
  139. } else {
  140. out.remark = `【${getJobType(record?.Cloudbrain?.JobType)}】【${record?.Cloudbrain?.ComputeResource}】【${record?.Cloudbrain?.ResourceSpec.FlavorInfo.desc}】`;
  141. }
  142. }
  143. }
  144. return out;
  145. };