Skip to content

Commit

Permalink
Merge pull request #154 from kaytu-io/fix-approved-plugins
Browse files Browse the repository at this point in the history
fix: fix FormatFloat function
  • Loading branch information
artaasadi authored May 23, 2024
2 parents 2773b9a + 8537ae6 commit 4f205b7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
6 changes: 3 additions & 3 deletions pkg/utils/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func SizeByteToGB(v *int32) string {
return fmt.Sprintf("%d GB", vv)
}

func FormatFloat(number float64) string {
func FormatPriceFloat(number float64) string {
isNegative := false
if number < 0 {
isNegative = true
Expand All @@ -99,8 +99,8 @@ func FormatFloat(number float64) string {
result = append(result, rune(digit))
}
if isNegative {
return fmt.Sprintf("-%s.%s", string(result), decimalPart)
return fmt.Sprintf("-$%s.%s", string(result), decimalPart)
} else {
return fmt.Sprintf("%s.%s", string(result), decimalPart)
return fmt.Sprintf("$%s.%s", string(result), decimalPart)
}
}
8 changes: 4 additions & 4 deletions view/non_interactive_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func getItemString(item *golang.OptimizationItem) string {
totalSaving += dev.CurrentCost - dev.RightSizedCost
}
}
row = append(row, item.Id, item.ResourceType, item.Region, item.Platform, fmt.Sprintf("$%s", utils.FormatFloat(totalSaving)))
row = append(row, item.Id, item.ResourceType, item.Region, item.Platform, fmt.Sprintf("%s", utils.FormatPriceFloat(totalSaving)))
t.AppendRow(row)
itemString += t.Render()
itemString += "\n " + bold.Sprint("Devices") + ":"
Expand Down Expand Up @@ -197,7 +197,7 @@ func getDeviceString(dev *golang.Device) string {
t.AppendHeader(headers)
var row table.Row
var itemString string
row = append(row, "└─ "+dev.DeviceId, dev.ResourceType, dev.Runtime, dev.CurrentCost, dev.RightSizedCost, fmt.Sprintf("$%s", utils.FormatFloat(dev.CurrentCost-dev.RightSizedCost)))
row = append(row, "└─ "+dev.DeviceId, dev.ResourceType, dev.Runtime, dev.CurrentCost, dev.RightSizedCost, fmt.Sprintf("%s", utils.FormatPriceFloat(dev.CurrentCost-dev.RightSizedCost)))
t.AppendRow(row)
itemString += t.Render()
itemString += "\n " + bold.Sprint("Properties") + ":\n" + getPropertiesString(dev.Properties)
Expand Down Expand Up @@ -425,8 +425,8 @@ func exportCsv(items []*golang.OptimizationItem) ([]string, [][]string) {
for _, d := range i.Devices {
for _, p := range d.Properties {
rows = append(rows, []string{
i.Id, i.ResourceType, i.Region, i.Platform, fmt.Sprintf("$%s", utils.FormatFloat(totalSaving)),
d.DeviceId, d.ResourceType, d.Runtime, fmt.Sprintf("$%s", utils.FormatFloat(d.CurrentCost)), fmt.Sprintf("$%s", utils.FormatFloat(d.RightSizedCost)), fmt.Sprintf("$%s", utils.FormatFloat(d.CurrentCost-d.RightSizedCost)),
i.Id, i.ResourceType, i.Region, i.Platform, fmt.Sprintf("%s", utils.FormatPriceFloat(totalSaving)),
d.DeviceId, d.ResourceType, d.Runtime, fmt.Sprintf("%s", utils.FormatPriceFloat(d.CurrentCost)), fmt.Sprintf("%s", utils.FormatPriceFloat(d.RightSizedCost)), fmt.Sprintf("%s", utils.FormatPriceFloat(d.CurrentCost-d.RightSizedCost)),
p.Key, p.Current, p.Average, p.Max, p.Recommended,
})
}
Expand Down
4 changes: 2 additions & 2 deletions view/page_overview.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (m OverviewPage) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
i.ResourceType,
i.Region,
i.Platform,
fmt.Sprintf("$%s (%.2f%%)", utils.FormatFloat(totalSaving), (totalSaving/totalCurrentCost)*100),
fmt.Sprintf("%s (%.2f%%)", utils.FormatPriceFloat(totalSaving), (totalSaving/totalCurrentCost)*100),
}
if i.Skipped {
row[5] = "skipped"
Expand Down Expand Up @@ -210,7 +210,7 @@ func (m OverviewPage) View() string {
}

return fmt.Sprintf("Current runtime cost: %s, Savings: %s\n%s\n%s",
style.CostStyle.Render(fmt.Sprintf("$%s", utils.FormatFloat(totalCost))), style.SavingStyle.Render(fmt.Sprintf("$%s", utils.FormatFloat(savings))),
style.CostStyle.Render(fmt.Sprintf("%s", utils.FormatPriceFloat(totalCost))), style.SavingStyle.Render(fmt.Sprintf("%s", utils.FormatPriceFloat(savings))),
m.table.View(),
m.statusBar.View(),
)
Expand Down
6 changes: 3 additions & 3 deletions view/page_resource_details.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ func (m ResourceDetailsPage) OnOpen() Page {
item.Name,
dev.ResourceType,
dev.Runtime,
fmt.Sprintf("$%s", utils.FormatFloat(dev.CurrentCost)),
fmt.Sprintf("%s", utils.FormatPriceFloat(dev.CurrentCost)),
ifRecommendationExists(func() string {
return fmt.Sprintf("$%s", utils.FormatFloat(dev.RightSizedCost))
return fmt.Sprintf("%s", utils.FormatPriceFloat(dev.RightSizedCost))
}),
ifRecommendationExists(func() string {
return fmt.Sprintf("$%s", utils.FormatFloat(dev.CurrentCost-dev.RightSizedCost))
return fmt.Sprintf("%s", utils.FormatPriceFloat(dev.CurrentCost-dev.RightSizedCost))
}),
})
}
Expand Down

0 comments on commit 4f205b7

Please sign in to comment.