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 9.8 kB

3 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
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
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
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
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
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
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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 workServerNum = spec.workServerNumber;
  57. var workServerNumStr = showPoint && workServerNum != 1 && spec.UnitPrice != 0 ? '*' + workServerNum + i18n.t('resourcesManagement.node') : '';
  58. var pointStr = showPoint ? `, ${spec.UnitPrice == 0 ? i18n.t('resourcesManagement.free') : spec.UnitPrice + i18n.t('resourcesManagement.point_hr') + workServerNumStr}` : '';
  59. var specStr = `${ngpu}, CPU: ${spec.CpuCores}, ${gpuMemStr}${i18n.t('resourcesManagement.mem')}: ${spec.MemGiB}GB${sharedMemStr}${pointStr}`;
  60. return specStr;
  61. };
  62. export const getRewardPointRecordInfo = (record) => {
  63. const out = {
  64. sn: record.SerialNo,
  65. date: formatDate(new Date(record.LastOperateDate * 1000), 'yyyy-MM-dd HH:mm:ss'),
  66. _status: record.Status,
  67. status: getConsumeStatus(record.Status) || '--',
  68. statusColor: record.Status === 'OPERATING' ? 'rgb(33, 186, 69)' : '',
  69. _sourceType: record.SourceType,
  70. sourceType: getSourceType(record.SourceType),
  71. duration: record?.Cloudbrain?.Duration || '--',
  72. taskName: record?.Cloudbrain?.DisplayJobName || '--',
  73. taskId: record?.Cloudbrain?.ID,
  74. action: record?.Action?.TaskType ? getPointAction(record.Action.TaskType) : '--',
  75. remark: record.Remark,
  76. amount: record.Amount,
  77. };
  78. if (record.OperateType === 'INCREASE') {
  79. if (record.SourceType === 'ADMIN_OPERATE') {
  80. out.remark = record.Remark;
  81. } else if (record.SourceType === 'ACCOMPLISH_TASK') {
  82. switch (record?.Action?.TaskType) {
  83. case 'CreatePublicRepo': // 创建公开项目 - 创建了项目OpenI/aiforge
  84. out.remark = `${i18n.t('createdRepository')}<a href="${record.Action.RepoLink}" rel="nofollow">${record.Action.ShortRepoFullDisplayName}</a>`;
  85. break;
  86. case 'CreateIssue': // 每日提出任务 - 创建了任务PCL-Platform.Intelligence/AISynergy#19
  87. 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>`;
  88. break;
  89. case 'CreatePullRequest': // 每日提出PR - 创建了合并请求OpenI/aiforge#1
  90. 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>`;
  91. break;
  92. case 'CommentIssue': // 发表评论 - 评论了任务PCL-Platform.Intelligence/AISynergy#19
  93. out.remark = `${i18n.t('commentedOnIssue')}<a href="${record.Action.CommentLink}" rel="nofollow">${record.Action.ShortRepoFullDisplayName}#${record.Action.IssueInfos[0]}</a>`;
  94. break;
  95. case 'UploadAttachment': // 上传数据集文件 - 上传了数据集文件MMISTData.zip
  96. out.remark = `${i18n.t('uploadDataset')}<a href="${record.Action.RepoLink}/datasets" rel="nofollow">${record.Action.RefName}</a>`;
  97. break;
  98. case 'CreateNewModelTask': // 导入新模型 - 导入了新模型resnet50_qx7l
  99. out.remark = `${i18n.t('createdNewModel')}<a href="${record.Action.RepoLink}/modelmanage/show_model_info?name=${record.Action.RefName}" rel="nofollow">${record.Action.RefName}</a>`;
  100. break;
  101. case 'BindWechat': // 完成微信扫码验证 - 首次绑定微信奖励
  102. out.remark = `${i18n.t('firstBindingWechatRewards')}`;
  103. break;
  104. case 'CreateCloudbrainTask': // 每日运行云脑任务 - 创建了(CPU/GPU/NPU)类型(调试/训练/推理/评测)任务tangl202204131431995
  105. 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>`;
  106. break;
  107. case 'DatasetRecommended': // 数据集被平台推荐 - 数据集XXX被设置为推荐数据集
  108. 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')}`;
  109. break;
  110. case 'CreateImage': // 提交新公开镜像 - 提交了镜像jiangxiang_ceshi_tang03
  111. out.remark = `${i18n.t('committedImage')}<span style="font-weight:bold;">${record.Action.Content && record.Action.Content.split('|')[1]}</span>`;
  112. break;
  113. case 'ImageRecommend': // 镜像被平台推荐 - 镜像XXX被设置为推荐镜像
  114. out.remark = `${i18n.t('image')}<span style="font-weight:bold;">${record.Action.Content && record.Action.Content.split('|')[1]}</span>${i18n.t('setAsRecommendedImage')}`;
  115. break;
  116. case 'ChangeUserAvatar': // 首次更换头像 - 更新了头像
  117. out.remark = `${i18n.t('updatedAvatar')}`;
  118. break;
  119. case 'PushCommits': // 每日commit - 推送了xxxx分支的代码到OpenI/aiforge
  120. const opType = record.Action.OpType;
  121. if (opType == 5) {
  122. const words = record.Action.RefName.split('/');
  123. const branch = words[words.length - 1];
  124. out.remark = `${i18n.t('pushedBranch', {
  125. branch: `<a href="${record.Action.RepoLink}/src/branch/${branch}" rel="nofollow">${branch}</a>`
  126. })}<a href="${record.Action.RepoLink}" rel="nofollow">${record.Action.ShortRepoFullDisplayName}</a>`;
  127. } else if (opType == 9) {
  128. const words = record.Action.RefName.split('/');
  129. const tag = words[words.length - 1];
  130. out.remark = `${i18n.t('pushedTag', {
  131. tag: `<a href="${record.Action.RepoLink}/src/tag/${tag}" rel="nofollow">${tag}</a>`
  132. })}<a href="${record.Action.RepoLink}" rel="nofollow">${record.Action.ShortRepoFullDisplayName}</a>`;
  133. } else if (opType == 16) {
  134. const words = record.Action.RefName.split('/');
  135. const tag = words[words.length - 1];
  136. out.remark = `${i18n.t('deleteTag', {
  137. repo: `<a href="${record.Action.RepoLink}" rel="nofollow">${record.Action.ShortRepoFullDisplayName}</a>`,
  138. tag: tag,
  139. })}`;
  140. } else if (opType == 17) {
  141. const words = record.Action.RefName.split('/');
  142. const branch = words[words.length - 1];
  143. out.remark = `${i18n.t('deleteBranch', {
  144. repo: `<a href="${record.Action.RepoLink}" rel="nofollow">${record.Action.ShortRepoFullDisplayName}</a>`,
  145. branch: branch,
  146. })}`;
  147. }
  148. break;
  149. default:
  150. break;
  151. }
  152. } else if (record.SourceType === 'RUN_CLOUDBRAIN_TASK') {
  153. //
  154. }
  155. if (record.LossAmount !== 0) {
  156. out.amount = record.Amount;
  157. out.remark += `${out.remark ? i18n.t(';') : ''}${i18n.t('dailyMaxTips')}`;
  158. }
  159. } else if (record.OperateType === 'DECREASE') {
  160. if (record.SourceType === 'ADMIN_OPERATE') {
  161. out.remark = record.Remark;
  162. } else if (record.SourceType === 'ACCOMPLISH_TASK') {
  163. //
  164. } else if (record.SourceType === 'RUN_CLOUDBRAIN_TASK') {
  165. out.taskName = `<a href="${getJobTypeLink(record, 'DECREASE')}" rel="nofollow">${record?.Cloudbrain?.DisplayJobName}</a>`;
  166. const resourceSpec = record?.Cloudbrain?.ResourceSpec;
  167. if (resourceSpec) {
  168. resourceSpec.workServerNumber = record?.Cloudbrain?.WorkServerNumber || 1;
  169. out.remark = `【${getJobType(record?.Cloudbrain?.JobType)}】【${renderSpecStr(resourceSpec, true)}】`;
  170. }
  171. }
  172. }
  173. return out;
  174. };