Query to count occurrences of specific values

Hello,
I use the ping input to monitor disconnects of my ISP. Every minute I do 10 pings to an external IP-address. As a result a get “percent_packes_loss”.
For a long time range, I use the following query to get the information, if there was a disconnect:

import "date"
import "experimental/date/boundaries"

yday = boundaries.yesterday()
yday2 = date.sub(d: 3h, from: yday.stop)

from(bucket: "SmartHome")
  |> range(start: v.timeRangeStart, stop:yday2)
  |> filter(fn: (r) =>
    r._measurement == "ping" and
    r._field == "percent_packet_loss"
  )
    |> aggregateWindow(fn: max, every: 1d, offset: -3h)

In Grafana I had a dashboard to show me if the value was 100%.

Now I want to get a step further and get displayed how often per day a disconnect happens. (sad, I know) Additionally I want to get a “single value” how many days without disconnect passed.

kind regards