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.2 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
1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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' }];
  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;
  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. for (var i = 0, iLen = data.length; i < iLen; i++) {
  23. var spec = data[i];
  24. var specStr = window.renderSpecStr(spec, showPoint, langObj);
  25. specsSel.append(`<option name="spec_id" value="${spec.ID}" queueCode="${spec.QueueCode}" unitprice="${spec.UnitPrice}">${specStr}</option>`);
  26. }
  27. if (showPoint) {
  28. specsSel.on('change', function (e) {
  29. var cloudbrain_resource_spec_blance_tip_el = $('.cloudbrain_resource_spec_blance_tip');
  30. var blance = $(this).attr('blance');
  31. var unitPrice = $(this).find('option:selected').attr('unitprice');
  32. if (!blance || !unitPrice) return;
  33. if (unitPrice == 0) {
  34. cloudbrain_resource_spec_blance_tip_el.find('.can-use-time').parent().hide();
  35. } else {
  36. var canUseTime = Number(blance) / Number(unitPrice);
  37. cloudbrain_resource_spec_blance_tip_el.find('.can-use-time').text(canUseTime.toFixed(2)).parent().show();
  38. }
  39. }).trigger('change');
  40. }
  41. }