Grafana query modification

Hello Grafana community,

I have an instance of grafana running on windows. I am pretty new to grafana and would appreciate some help with a query.

At the moment the situation is a machine with 10 run signals for 10 different heads on the machine, these signals are received through a PLC and then we use nodered to pull in the boolean signals every 10 seconds through modbus TCP, These are then sent to influxdb as 10 different fields within a measurement. This is then displayed as a ‘state timeline’ panel in grafana simply showing green for true and red for false, and showing the time range for each change in state. The query is as follows
from(bucket: “Carding”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r[“_measurement”] == “Carding Production”)
|> filter(fn: (r) => r[“_field”] == “Card 1 Running” )
|> aggregateWindow(every: v.windowPeriod, fn: last, createEmpty: false)
|> yield(name: “last”)

Here the query happens ten times with the field increasing by one each time to iterate through each card.
What I am wanting to do is look at the signals and have grafana automatically calculate the time the signal is true and the time it is false over two twelve hour shifts, and display that in a panel, can i do this within my query? Any help is massively appreciated. Thank you