Hello.
Maybe you can help me with this. I am collecting my PV data.
In the query (manually) all is correct, all fields exist, including the “panel” field:
import “timezone”
import “date”
option location = timezone.location(name: “Europe/Berlin”)
from(bucket: “s13mppt”)
|> range(
start: date.add(d: -1d, to: date.truncate(t: now(), unit: 1d)),
stop: date.truncate(t: now(), unit: 1d),
)
|> filter(fn: (r) => r[“_measurement”] == “Leistung”)
|> filter(fn: (r) => r[“MPPT”] == “MPPT1”)
|> filter(fn: (r) => r[“_field”] == “mppt1total”)
|> aggregateWindow(every: 1d, fn: max, createEmpty: false, timeSrc: “_start”)
|> map(fn: (r) => ({r with panel: r._value/2.58}))
|> drop(columns: [“_start”, “_stop”])
> yield(name: “test”) |
![image |
When I do an export in a table with a scheduled task with the identical query including at the end:
|> to(bucket: “s13test”, org: “synology”)
in the resulting data in bucket s13test there is no field “panel”.
Up to now I always had correct exports, but this time I added a field and maybe I overlook something. Thank you for any hint.
Here is the first screenshot with correct query:
The issue is essentially that the new column panel
is a float/double, so your row now has two fields in rather than one.
to()
expects long (i.e. one field per row) rather than wide tables, so each of the rows can only contain one field value - everything else needs to be a string. panel
gets ignored because it’s the wrong type.
As you’re calculating the value from the the existing value, I assume that you don’t want it to be treated as a tag but as a new field?
If so, give this a try
import “timezone”
import “date”
option location = timezone.location(name: “Europe/Berlin”)
// Query the data out
data = from(bucket: “s13mppt”)
|> range(
start: date.add(d: -1d, to: date.truncate(t: now(), unit: 1d)),
stop: date.truncate(t: now(), unit: 1d),
)
|> filter(fn: (r) => r[“_measurement”] == “Leistung”)
|> filter(fn: (r) => r[“MPPT”] == “MPPT1”)
|> filter(fn: (r) => r[“_field”] == “mppt1total”)
|> aggregateWindow(every: 1d, fn: max, createEmpty: false, timeSrc: “_start”)
|> drop(columns: [“_start”, “_stop”])
// Create the new field/value and write into the dest bucket
data
|> map(fn: (r) => ({r with
_field: "panel",
_value: r._value/2.58
}))
|> to(bucket: “s13test”, org: “synology”)
// Assuming you wanted a copy of the original data in there too
data
|> to(bucket: “s13test”, org: “synology”)
Just for completeness, if you did want it to be a tag rather than a field value, converting it to a string should do the job:
|> map(fn: (r) => ({r with panel: string(v: r._value/2.58)}))