MCPcopy Create free account
hub / github.com/Thunder-Compute/thunder-cli / computePreviewPrice

Method computePreviewPrice

tui/create.go:1087–1146  ·  view source on GitHub ↗

computePreviewPrice calculates the price based on current config state, using the hovered option for the current step to preview pricing.

()

Source from the content-addressed store, hash-verified

1085// computePreviewPrice calculates the price based on current config state,
1086// using the hovered option for the current step to preview pricing.
1087func (m createModel) computePreviewPrice() float64 {
1088 gpuType := m.config.GPUType
1089 numGPUs := m.config.NumGPUs
1090 vcpus := m.config.VCPUs
1091 diskSizeGB := m.config.DiskSizeGB
1092
1093 // Apply defaults for unfilled fields
1094 if gpuType == "" {
1095 gpuOpts := m.specs.GPUOptions()
1096 if len(gpuOpts) > 0 {
1097 gpuType = gpuOpts[0]
1098 }
1099 }
1100 if numGPUs == 0 {
1101 numGPUs = 1
1102 }
1103 if vcpus == 0 {
1104 vcpus = m.specs.IncludedVCPUs(gpuType, numGPUs)
1105 }
1106 if diskSizeGB == 0 {
1107 diskSizeGB = defaultCreateDiskSizeForGPUCount(numGPUs)
1108 }
1109
1110 // Override with hovered option for current step
1111 switch m.step {
1112 case stepGPU:
1113 gpus := m.getGPUOptions()
1114 if m.cursor < len(gpus) {
1115 gpuType = gpus[m.cursor]
1116 }
1117 if numGPUs == 0 {
1118 numGPUs = 1
1119 }
1120 vcpus = m.specs.IncludedVCPUs(gpuType, numGPUs)
1121 case stepCompute:
1122 if m.gpuCountPhase {
1123 gpuCounts := m.specs.GPUCounts(gpuType)
1124 if m.cursor < len(gpuCounts) {
1125 numGPUs = gpuCounts[m.cursor]
1126 }
1127 vcpus = m.specs.IncludedVCPUs(gpuType, numGPUs)
1128 } else {
1129 vcpuOpts := m.specs.VCPUOptions(m.config.GPUType, m.config.NumGPUs)
1130 if m.cursor < len(vcpuOpts) {
1131 vcpus = vcpuOpts[m.cursor]
1132 }
1133 }
1134 case stepDiskSize:
1135 if v, err := strconv.Atoi(m.diskInput.Value()); err == nil && v >= 10 {
1136 diskSizeGB = v
1137 }
1138 }
1139
1140 if (m.presets == nil || m.presets.DiskSizeGB == nil) && m.step != stepDiskSize && m.step != stepConfirmation {
1141 diskSizeGB = max(diskSizeGB, defaultCreateDiskSizeForGPUCount(numGPUs))
1142 }
1143
1144 included := m.specs.IncludedVCPUs(gpuType, numGPUs)

Callers 1

ViewMethod · 0.95

Calls 7

getGPUOptionsMethod · 0.95
CalculateHourlyPriceFunction · 0.92
GPUOptionsMethod · 0.80
IncludedVCPUsMethod · 0.80
GPUCountsMethod · 0.80
VCPUOptionsMethod · 0.80

Tested by

no test coverage detected