Map into one query

I’m trying to decode status and warnings from a jk bms, the question is how i get this into one query. I need to add fields based on one of the queried fields.

import "experimental/bitwise"

status = from(bucket: "ad")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "SolarHalle")
  |> filter(fn: (r) => r["Device"] == "bms")
  |> filter(fn: (r) => r["_field"] == "status")
    |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
  |> map(fn: (r) => ({ r with 
    lowCapacity: int(v: bool(v: bitwise.sand(a: bitwise.srshift(a: int(v: r._value), b: 0), b:1))),
    mosOvertemp: int(v: bool(v: bitwise.sand(a: bitwise.srshift(a: int(v: r._value), b: 1), b:1)))
    }))
  |> drop(columns: ["_field", "_value", "Device", "_start", "_stop"])
  
  
  info = from(bucket: "ad")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "SolarHalle")
  |> filter(fn: (r) => r["Device"] == "bms")
  |> filter(fn: (r) => r["_field"] == "info")
    |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
  |> map(fn: (r) => ({ r with 
    chargeOff: int (v: not bool(v: bitwise.sand(a: bitwise.srshift(a: int(v: r._value), b: 0), b:1))),
    dischargeOff: int(v: not bool(v: bitwise.sand(a: bitwise.srshift(a: int(v: r._value), b: 1), b:1)))
  }))
  |> drop(columns: ["_field", "_value", "Device", "_start", "_stop"])
  
  join(tables: {s: status, i: info}, on: ["_time"], method: "inner")
  |> drop(columns: ["_measurement_i","_measurement_s"])
  
  |> yield(name: "mean")

Hello @ardiehl,
I’m sorry I’m not sure I understand.
Could you share your output and what you’d like your output to be? What do you mean by one query?

It seems like you could do:

import "experimental/bitwise"

status = from(bucket: "ad")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "SolarHalle")
  |> filter(fn: (r) => r["Device"] == "bms")
  |> filter(fn: (r) => r["_field"] == "status" or r["_field"] == "info")
    |> aggregateWindow(every: v.windowPeriod, fn: mean, createEmpty: false)
  |> map(fn: (r) => ({ r with 
    lowCapacity/chargeOff: int(v: bool(v: bitwise.sand(a: bitwise.srshift(a: int(v: r._value), b: 0), b:1))),
    mosOvertemp/dischargOff: int(v: bool(v: bitwise.sand(a: bitwise.srshift(a: int(v: r._value), b: 1), b:1)))
    }))

is that what you mean?