KPI name change : GWM
This commit is contained in:
parent
285d3f548b
commit
4ecc7d0ba2
BIN
pb_data/data.db
BIN
pb_data/data.db
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
pb_data/logs.db
BIN
pb_data/logs.db
Binary file not shown.
Binary file not shown.
Binary file not shown.
48
utils/process_chart_data.go
Normal file
48
utils/process_chart_data.go
Normal file
@ -0,0 +1,48 @@
|
||||
package utils
|
||||
|
||||
// ProcessChartData processes chart data with language source data to produce the result based on the language key.
|
||||
func ProcessChartData(chartData []map[string]interface{}, languageSource []map[string]interface{}, langKey string) []map[string]interface{} {
|
||||
// Helper function to find translation
|
||||
findTranslation := func(key string, value string) string {
|
||||
for _, langEntry := range languageSource {
|
||||
if langEntry["key"] == key && langEntry["value"] == value {
|
||||
if translatedValue, ok := langEntry[langKey]; ok {
|
||||
return translatedValue.(string)
|
||||
}
|
||||
}
|
||||
}
|
||||
return value // Return the original value if no translation is found
|
||||
}
|
||||
|
||||
// Extract unique translation keys from languageSource
|
||||
translationKeys := map[string]bool{}
|
||||
for _, langEntry := range languageSource {
|
||||
if key, ok := langEntry["key"].(string); ok {
|
||||
translationKeys[key] = true
|
||||
}
|
||||
}
|
||||
|
||||
// Process each chart data entry
|
||||
result := []map[string]interface{}{}
|
||||
for _, entry := range chartData {
|
||||
obsKey := entry["ObsKey"].(map[string]interface{})
|
||||
translatedObsKey := map[string]interface{}{}
|
||||
|
||||
// Translate fields in ObsKey dynamically based on extracted translation keys
|
||||
for key, value := range obsKey {
|
||||
if translationKeys[key] {
|
||||
translatedObsKey[key] = findTranslation(key, value.(string))
|
||||
} else {
|
||||
translatedObsKey[key] = value
|
||||
}
|
||||
}
|
||||
|
||||
// Append the translated entry to the result
|
||||
result = append(result, map[string]interface{}{
|
||||
"ObsKey": translatedObsKey,
|
||||
"ObsValue": entry["ObsValue"],
|
||||
})
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user