Skip to content
Snippets Groups Projects
Commit ab943be6 authored by Jonas Leder's avatar Jonas Leder
Browse files

fix dhw values not stored in db

parent 7ebf5bf8
No related branches found
No related tags found
No related merge requests found
Pipeline #54615 passed
package helper
func FlattenJSON(prefix string, input map[string]interface{}, output map[string]interface{}) {
for key, value := range input {
// Build the new key
newKey := key
if prefix != "" {
newKey = prefix + "_" + key
}
// Check the type of value
switch v := value.(type) {
case map[string]interface{}:
// If it's a nested JSON object, recursively flatten it
FlattenJSON(newKey, v, output)
default:
// Otherwise, add it to the output map
output[newKey] = v
}
}
}
......@@ -18,7 +18,7 @@ func main() {
log.Init()
queue.Init()
if os.Getenv("OUTPUT_DATABSE") != "" && os.Getenv("CLIENT_USE_SERVER") != "true" {
if (os.Getenv("OUTPUT_DATABSE") != "" && os.Getenv("CLIENT_USE_SERVER") != "true") || os.Getenv("LOGGER_SERVER") == "true" {
database.Init()
if os.Getenv("LOGGER_SERVER") != "true" {
database.CreateInstance()
......
......@@ -98,6 +98,8 @@ func runDbClient() {
var jsonData map[string]interface{}
err = json.Unmarshal([]byte(task.Data), &jsonData)
flattenedData := make(map[string]interface{})
helper.FlattenJSON("", jsonData, flattenedData)
if err != nil {
log.Log.Error("Failed decoding boiler JSON: ", err.Error())
queue.MainQueue.Enqueue(taskData, 60)
......@@ -105,7 +107,7 @@ func runDbClient() {
continue
}
valuesToInsert := []tables.Value{}
for key, value := range jsonData {
for key, value := range flattenedData {
valueType := database.GetOrCreateValueType(key)
dbValue := tables.Value{
Date: task.Date,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment