Can someone please help urgently -i have x and y columns. i need to round them to 2 decimal places and then group by rounded x and y values and count their occurences. this would give me a weight value. I am trying floowing but its not working - import “math”
start_date = 2024-09-10T00:00:00Z // Adjust as needed
end_date = 2024-09-11T23:59:59Z // Adjust as needed
data = from(bucket: “output”)
|> range(start: start_date, stop: end_date) // Define the time range
|> filter(fn: (r) => r._measurement == “test”)
|> filter(fn: (r) => r._field == “x” or r._field == “y”) // Focus on “x” and “y” fields
// Map to round x and y, and keep the _field and _value
rounded = data
|> map(fn: (r) => ({
r with
x_rounded: if r._field == “x” then math.round(x: r._value * 100.0) / 100.0 else 0.0,
y_rounded: if r._field == “y” then math.round(x: r._value * 100.0) / 100.0 else 0.0,
_value: r._value // Keep the original value for counting
}))
// Filter out rows where both rounded values are zero
filtered = rounded
|> filter(fn: (r) => r.x_rounded != 0.0 or r.y_rounded != 0.0)
// Group by rounded values of x and y, then count occurrences
result = filtered
|> group(columns: [“x_rounded”, “y_rounded”])
|> count(column: “_value”) // Count occurrences of each unique pair
result
|> yield(name: “weights”)