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