GWM : filter issue

This commit is contained in:
Gowtham M 2025-03-01 11:17:34 +05:30
parent 50ba99ecf1
commit 130a7f17c8
3 changed files with 16 additions and 11 deletions

View File

@ -599,7 +599,7 @@ func main() {
keyToFilter := record.GetString("unset_key") keyToFilter := record.GetString("unset_key")
valueToExclude := record.GetString("unset_value") valueToExclude := record.GetString("unset_value")
if keyToFilter == "" || valueToExclude == "" { if keyToFilter == "" || valueToExclude == "" {
fmt.Println("unset_key or unset_value is empty. Skipping processing.") // fmt.Println("unset_key or unset_value is empty. Skipping processing.")
} else { } else {
// Filter the data dynamically and update chartData // Filter the data dynamically and update chartData
chartData = filterDynamicChartData(chartData, keyToFilter, valueToExclude) chartData = filterDynamicChartData(chartData, keyToFilter, valueToExclude)
@ -651,6 +651,7 @@ func main() {
"tab_order": record.GetString("tab_order"), "tab_order": record.GetString("tab_order"),
"chart_type_json": record.Get("chart_type_json"), "chart_type_json": record.Get("chart_type_json"),
"card_full_length": record.Get("card_full_length"), "card_full_length": record.Get("card_full_length"),
"chart_bar_color": record.Get("chart_bar_color"),
} }
var cRes []utils.Observation var cRes []utils.Observation
@ -1678,8 +1679,8 @@ func main() {
}() }()
// Start your custom HTTP server on port 8091 // Start your custom HTTP server on port 8091
log.Println("Starting custom HTTP server on :8091") log.Println("Starting custom HTTP server on :9091")
if err := http.ListenAndServe(":8091", nil); err != nil { if err := http.ListenAndServe(":9091", nil); err != nil {
log.Fatal("Failed to start server: ", err) log.Fatal("Failed to start server: ", err)
} }
} }

Binary file not shown.

View File

@ -46,16 +46,17 @@ func CardCalculation(data []Observation, req CardCalculationRequest) (map[string
// Convert RecodeIndex to an integer // Convert RecodeIndex to an integer
index, err := strconv.Atoi(req.RecodeIndex) index, err := strconv.Atoi(req.RecodeIndex)
if err != nil || index < 0 || index >= len(data) { if err != nil || index < 0 || index >= len(data) {
return nil, errors.New("invalid record index") // return nil, errors.New("invalid record index")
selectedData = []Observation{}
} else {
selectedData = []Observation{data[index]}
} }
// Select only the requested index record
selectedData = []Observation{data[index]}
} else { } else {
// Determine the number of records to use // Determine the number of records to use
if req.RecordCount == "all" { if req.RecordCount == "all" {
if len(data) >= 0 { if len(data) > 0 {
selectedData = data selectedData = data
} else { } else {
selectedData = []Observation{} selectedData = []Observation{}
@ -68,7 +69,7 @@ func CardCalculation(data []Observation, req CardCalculationRequest) (map[string
} }
} else if req.RecordCount == "second_pair" { } else if req.RecordCount == "second_pair" {
if len(data) >= 3 { if len(data) >= 3 {
selectedData = data[:2] selectedData = data[1:3]
} else { } else {
selectedData = []Observation{} selectedData = []Observation{}
} }
@ -76,10 +77,13 @@ func CardCalculation(data []Observation, req CardCalculationRequest) (map[string
n := len(data) // array leangth n := len(data) // array leangth
var err error var err error
n, err = strconv.Atoi(req.RecordCount) n, err = strconv.Atoi(req.RecordCount)
if err != nil || n > len(data) { if err != nil || n >= len(data) {
return nil, errors.New("invalid record count") // return nil, errors.New("invalid record count");
selectedData = []Observation{}
} else {
selectedData = data[:n]
} }
selectedData = data[:n]
} }
} }