Duplicating persistence when executing tasks

When a task that retrieves data from a bucket (a) summarizes it and persists it in another bucket (b).

This is because the persistence in bucket (b) is duplicating the persistence four or five times the zeroed summarized value and the calculated value

option task = {name: "summary_hour", cron: "0 * * * *"}

    from(bucket: "aggregator")
        |> range(start: -1h)
        |> filter(fn: (r) => r._measurement == "streamer_collect")
        |> map(
            fn: (r) =>
                ({
                    _time: r._time,
                    _account_id: r._account_id,
                    _edge_server: r._edge_server,
                    _edge_bytes_transmitted: float(v: r._edge_bytes_transmitted),
                }),
        )
        |> group(columns: ["_account_id", "_edge_server"])
        |> sum(column: "_edge_bytes_transmitted")
        |> map(
            fn: (r) =>
                ({
                    _time: now(),
                    _measurement: "summary_hour",
                    _field: "bytes_transmitted",
                    _value: r._edge_bytes_transmitted,
                    _account_id: r._account_id,
                    _edge_server: r._edge_server,
                    _edge_bytes_transmitted: string(v: r._edge_bytes_transmitted),
                }),
        )
        |> to(bucket: "summary_hour")

Hello @Marcelo_Bezerra,
Welcome!
I’m sorry I’m having trouble understanding what is being duplicated time what?
Could you please include some more details?

Duplicated values could stem from the use of the now() function in the second map() operation. This creates new timestamps on each execution of the task. This can cause multiple records with the same values if the task is being triggered frequently due to overlapping data. Is this what you mean?

hi @Anaisdg,

when this task is triggered it is persisted in the summary_hour bucket as follows :

| _time | _edge_bytes_transmitted|

|17:00:00 | 0
|17:00:00 | 0
|17:00:00 | 0
|17:00:00 | 0
|17:00:00 | 5635689

Where only the record with the value 5635689 is valid. I have already changed

                    _time: now(),

to

                    _time: r._time,,

But the problem persists.