computePreviewPrice calculates the price for the resulting configuration, using current instance values as base and overriding with selections/hovered option.
()
| 598 | // computePreviewPrice calculates the price for the resulting configuration, |
| 599 | // using current instance values as base and overriding with selections/hovered option. |
| 600 | func (m modifyModel) computePreviewPrice() float64 { |
| 601 | // Start with current instance values |
| 602 | gpuType := strings.ToLower(m.currentInstance.GPUType) |
| 603 | numGPUs := 1 |
| 604 | if n, err := strconv.Atoi(m.currentInstance.NumGPUs); err == nil { |
| 605 | numGPUs = n |
| 606 | } |
| 607 | vcpus := 4 |
| 608 | if n, err := strconv.Atoi(m.currentInstance.CPUCores); err == nil { |
| 609 | vcpus = n |
| 610 | } |
| 611 | diskSizeGB := m.currentInstance.Storage |
| 612 | |
| 613 | // Override with already-confirmed selections |
| 614 | if m.config.GPUChanged { |
| 615 | gpuType = m.config.GPUType |
| 616 | } |
| 617 | if m.config.ComputeChanged { |
| 618 | if m.config.NumGPUs > 0 { |
| 619 | numGPUs = m.config.NumGPUs |
| 620 | } |
| 621 | if m.config.VCPUs > 0 { |
| 622 | vcpus = m.config.VCPUs |
| 623 | } |
| 624 | } |
| 625 | if m.config.DiskChanged { |
| 626 | diskSizeGB = m.config.DiskSizeGB |
| 627 | } |
| 628 | |
| 629 | // Override with hovered option for the current step |
| 630 | switch m.step { |
| 631 | case modifyStepGPU: |
| 632 | gpuValues := m.specs.GPUOptions() |
| 633 | gpuType = gpuValues[m.cursor] |
| 634 | gpuCounts := m.specs.GPUCounts(gpuType) |
| 635 | if !slices.Contains(gpuCounts, numGPUs) && len(gpuCounts) > 0 { |
| 636 | numGPUs = gpuCounts[0] |
| 637 | vcpus = m.specs.IncludedVCPUs(gpuType, numGPUs) |
| 638 | } |
| 639 | case modifyStepCompute: |
| 640 | if m.gpuCountPhase { |
| 641 | gpuCounts := m.specs.GPUCounts(m.config.GPUType) |
| 642 | numGPUs = gpuCounts[m.cursor] |
| 643 | vcpus = m.specs.IncludedVCPUs(gpuType, numGPUs) |
| 644 | } else { |
| 645 | vcpuOptions := m.specs.VCPUOptions(m.config.GPUType, m.config.NumGPUs) |
| 646 | vcpus = vcpuOptions[m.cursor] |
| 647 | } |
| 648 | case modifyStepDiskSize: |
| 649 | if v, err := strconv.Atoi(m.diskInput.Value()); err == nil && v >= 100 { |
| 650 | diskSizeGB = v |
| 651 | } |
| 652 | } |
| 653 | |
| 654 | included := m.specs.IncludedVCPUs(gpuType, numGPUs) |
| 655 | return utils.CalculateHourlyPrice(m.pricing, gpuType, numGPUs, vcpus, diskSizeGB, included) |
| 656 | } |
| 657 |
no test coverage detected