This commit is contained in:
Gowtham M 2025-02-18 12:17:07 +05:30
parent 37f69801a2
commit 32d8f958ed
2 changed files with 3 additions and 40 deletions

Binary file not shown.

View File

@ -18,6 +18,7 @@ type Observation struct {
} `json:"ObsValue"`
}
// ------------------------------------------------------------ card calculation---------------------------------------------------
type CardCalculationRequest struct {
Formula string `json:"formula"`
RecordCount string `json:"record_count"`
@ -150,34 +151,6 @@ func difference(data []Observation) float64 {
return ((latest - previous) / previous) * 100
}
// func applyConversion(value float64, conversion string, numberFormat string) string {
// if numberFormat == "T" {
// value *= 1000000000000
// } else if numberFormat == "B" {
// value *= 1000000000
// } else if numberFormat == "M" {
// value *= 1000000
// } else if numberFormat == "K" {
// value *= 1000
// }
// switch conversion {
// case "T":
// return fmt.Sprintf("%.2fT", value/1000000000000)
// case "B":
// return fmt.Sprintf("%.2fB", value/1000000000)
// case "M":
// return fmt.Sprintf("%.2fM", value/1000000)
// case "K":
// return fmt.Sprintf("%.2fK", value/1000)
// case "%":
// return fmt.Sprintf("%.2f%%", value)
// default:
// return fmt.Sprintf("%.2f", value)
// }
// }
// Function to add commas to a number string
func addCommas(num string) string {
n := len(num)
@ -208,17 +181,9 @@ func applyConversion(value float64, conversion string, numberFormat string) stri
value *= 1000
}
// Helper function to format the number properly
// formatNumber := func(v float64, suffix string) string {
// if v == float64(int(v)) { // Check if v has no decimal part
// return fmt.Sprintf("%d%s", int(v), suffix)
// }
// return fmt.Sprintf("%.2f%s", v, suffix)
// }
// Helper function to format numbers with a thousands separator only in the default case
formatNumber := func(v float64, suffix string) string {
if suffix == "" { // Apply comma formatting only in default case
if suffix == "" || suffix == "K" {
if v == float64(int(v)) { // No decimal part
return addCommas(strconv.Itoa(int(v)))
}
@ -272,9 +237,7 @@ func extractRecordKeyValue(data []Observation, key string, formula string, targe
return ""
}
//------------------------------------------------------------
// ChartCalculationRequest struct for request parameters
// ------------------------------------------------------------ chart calculation---------------------------------------------------
type ChartCalculationRequest struct {
GroupByAndSum string `json:"groupby_and_sum"`
GetTop string `json:"get_top"`