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 10 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
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. if (record.Action?.Cloudbrain?.JobType === 'MODELSAFETY') {
  83. record.Action.Cloudbrain.oJobType = 'MODELSAFETY';
  84. record.Action.Cloudbrain.JobType = 'BENCHMARK';
  85. }
  86. switch (record?.Action?.TaskType) {
  87. case 'CreatePublicRepo': // 创建公开项目 - 创建了项目OpenI/aiforge
  88. out.remark = `${i18n.t('createdRepository')}<a href="${record.Action.RepoLink}" rel="nofollow">${record.Action.ShortRepoFullDisplayName}</a>`;
  89. break;
  90. case 'CreateIssue': // 每日提出任务 - 创建了任务PCL-Platform.Intelligence/AISynergy#19
  91. 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>`;
  92. break;
  93. case 'CreatePullRequest': // 每日提出PR - 创建了合并请求OpenI/aiforge#1
  94. 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>`;
  95. break;
  96. case 'CommentIssue': // 发表评论 - 评论了任务PCL-Platform.Intelligence/AISynergy#19
  97. out.remark = `${i18n.t('commentedOnIssue')}<a href="${record.Action.CommentLink}" rel="nofollow">${record.Action.ShortRepoFullDisplayName}#${record.Action.IssueInfos[0]}</a>`;
  98. break;
  99. case 'UploadAttachment': // 上传数据集文件 - 上传了数据集文件MMISTData.zip
  100. out.remark = `${i18n.t('uploadDataset')}<a href="${record.Action.RepoLink}/datasets" rel="nofollow">${record.Action.RefName}</a>`;
  101. break;
  102. case 'CreateNewModelTask': // 导入新模型 - 导入了新模型resnet50_qx7l
  103. out.remark = `${i18n.t('createdNewModel')}<a href="${record.Action.RepoLink}/modelmanage/show_model_info?name=${record.Action.RefName}" rel="nofollow">${record.Action.RefName}</a>`;
  104. break;
  105. case 'BindWechat': // 完成微信扫码验证 - 首次绑定微信奖励
  106. out.remark = `${i18n.t('firstBindingWechatRewards')}`;
  107. break;
  108. case 'CreateCloudbrainTask': // 每日运行云脑任务 - 创建了(CPU/GPU/NPU)类型(调试/训练/推理/评测)任务tangl202204131431995
  109. 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>`;
  110. break;
  111. case 'DatasetRecommended': // 数据集被平台推荐 - 数据集XXX被设置为推荐数据集
  112. 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')}`;
  113. break;
  114. case 'CreateImage': // 提交新公开镜像 - 提交了镜像jiangxiang_ceshi_tang03
  115. out.remark = `${i18n.t('committedImage')}<span style="font-weight:bold;">${record.Action.Content && record.Action.Content.split('|')[1]}</span>`;
  116. break;
  117. case 'ImageRecommend': // 镜像被平台推荐 - 镜像XXX被设置为推荐镜像
  118. out.remark = `${i18n.t('image')}<span style="font-weight:bold;">${record.Action.Content && record.Action.Content.split('|')[1]}</span>${i18n.t('setAsRecommendedImage')}`;
  119. break;
  120. case 'ChangeUserAvatar': // 首次更换头像 - 更新了头像
  121. out.remark = `${i18n.t('updatedAvatar')}`;
  122. break;
  123. case 'PushCommits': // 每日commit - 推送了xxxx分支的代码到OpenI/aiforge
  124. const opType = record.Action.OpType;
  125. if (opType == 5) {
  126. const words = record.Action.RefName.split('/');
  127. const branch = words[words.length - 1];
  128. out.remark = `${i18n.t('pushedBranch', {
  129. branch: `<a href="${record.Action.RepoLink}/src/branch/${branch}" rel="nofollow">${branch}</a>`
  130. })}<a href="${record.Action.RepoLink}" rel="nofollow">${record.Action.ShortRepoFullDisplayName}</a>`;
  131. } else if (opType == 9) {
  132. const words = record.Action.RefName.split('/');
  133. const tag = words[words.length - 1];
  134. out.remark = `${i18n.t('pushedTag', {
  135. tag: `<a href="${record.Action.RepoLink}/src/tag/${tag}" rel="nofollow">${tag}</a>`
  136. })}<a href="${record.Action.RepoLink}" rel="nofollow">${record.Action.ShortRepoFullDisplayName}</a>`;
  137. } else if (opType == 16) {
  138. const words = record.Action.RefName.split('/');
  139. const tag = words[words.length - 1];
  140. out.remark = `${i18n.t('deleteTag', {
  141. repo: `<a href="${record.Action.RepoLink}" rel="nofollow">${record.Action.ShortRepoFullDisplayName}</a>`,
  142. tag: tag,
  143. })}`;
  144. } else if (opType == 17) {
  145. const words = record.Action.RefName.split('/');
  146. const branch = words[words.length - 1];
  147. out.remark = `${i18n.t('deleteBranch', {
  148. repo: `<a href="${record.Action.RepoLink}" rel="nofollow">${record.Action.ShortRepoFullDisplayName}</a>`,
  149. branch: branch,
  150. })}`;
  151. }
  152. break;
  153. default:
  154. break;
  155. }
  156. } else if (record.SourceType === 'RUN_CLOUDBRAIN_TASK') {
  157. //
  158. }
  159. if (record.LossAmount !== 0) {
  160. out.amount = record.Amount;
  161. out.remark += `${out.remark ? i18n.t(';') : ''}${i18n.t('dailyMaxTips')}`;
  162. }
  163. } else if (record.OperateType === 'DECREASE') {
  164. if (record.SourceType === 'ADMIN_OPERATE') {
  165. out.remark = record.Remark;
  166. } else if (record.SourceType === 'ACCOMPLISH_TASK') {
  167. //
  168. } else if (record.SourceType === 'RUN_CLOUDBRAIN_TASK') {
  169. out.taskName = `<a href="${getJobTypeLink(record, 'DECREASE')}" rel="nofollow">${record?.Cloudbrain?.DisplayJobName}</a>`;
  170. const resourceSpec = record?.Cloudbrain?.ResourceSpec;
  171. if (resourceSpec) {
  172. resourceSpec.workServerNumber = record?.Cloudbrain?.WorkServerNumber || 1;
  173. out.remark = `【${getJobType(record?.Cloudbrain?.JobType)}】【${renderSpecStr(resourceSpec, true)}】`;
  174. }
  175. }
  176. }
  177. return out;
  178. };