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.8 kB

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