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.

specsuse.js 2.3 kB

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
12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. window.ACC_CARD_TYPE = [{ k: 'T4', v: 'T4' }, { k: 'A100', v: 'A100' }, { k: 'V100', v: 'V100' }, { k: 'ASCEND910', v: 'Ascend 910' }, { k: 'MLU270', v: 'MLU270' }, { k: 'RTX3080', v: 'RTX3080' }, { k: 'ENFLAME-T20', v: 'ENFLAME-T20' }];
  2. window.getListValueWithKey = (list, key, k = 'k', v = 'v', defaultV = '') => {
  3. for (let i = 0, iLen = list.length; i < iLen; i++) {
  4. const listI = list[i];
  5. if (listI[k] === key) return listI[v];
  6. }
  7. return defaultV || key;
  8. };
  9. window.renderSpecStr = (spec, showPoint, langObj) => {
  10. if (!spec) return '';
  11. var ngpu = `${spec.ComputeResource}: ${spec.AccCardsNum + '*' + getListValueWithKey(ACC_CARD_TYPE, spec.AccCardType)}`;
  12. var gpuMemStr = spec.GPUMemGiB != 0 ? `${langObj.gpu_memory}: ${spec.GPUMemGiB}GB, ` : '';
  13. var sharedMemStr = spec.ShareMemGiB != 0 ? `, ${langObj.shared_memory}: ${spec.ShareMemGiB}GB` : '';
  14. var pointStr = showPoint ? `, ${spec.UnitPrice == 0 ? langObj.free : spec.UnitPrice + langObj.point_hr}` : '';
  15. var specStr = `${ngpu}, CPU: ${spec.CpuCores}, ${gpuMemStr}${langObj.memory}: ${spec.MemGiB}GB${sharedMemStr}${pointStr}`;
  16. return specStr;
  17. };
  18. window.renderSpecsSelect = (specsSel, data, showPoint, langObj) => {
  19. specsSel.empty();
  20. data = data || [];
  21. showPoint = specsSel.attr('blance') ? true : false;
  22. var oValue = specsSel.attr('ovalue');
  23. for (var i = 0, iLen = data.length; i < iLen; i++) {
  24. var spec = data[i];
  25. var specStr = window.renderSpecStr(spec, showPoint, langObj);
  26. specsSel.append(`<option name="spec_id" value="${spec.ID}" queueCode="${spec.QueueCode}" unitprice="${spec.UnitPrice}">${specStr}</option>`);
  27. }
  28. oValue && specsSel.val(oValue);
  29. if (showPoint) {
  30. specsSel.on('change', function (e) {
  31. var cloudbrain_resource_spec_blance_tip_el = $('.cloudbrain_resource_spec_blance_tip');
  32. var blance = $(this).attr('blance');
  33. var unitPrice = $(this).find('option:selected').attr('unitprice');
  34. if (!blance || !unitPrice) return;
  35. if (unitPrice == 0) {
  36. cloudbrain_resource_spec_blance_tip_el.find('.can-use-time').parent().hide();
  37. } else {
  38. var canUseTime = Number(blance) / Number(unitPrice);
  39. cloudbrain_resource_spec_blance_tip_el.find('.can-use-time').text(canUseTime.toFixed(2)).parent().show();
  40. }
  41. }).trigger('change');
  42. }
  43. }