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