I have a list of incidents/downtime as follows that can span (or not) over multiple days for which I'd like to calculate the daily uptime (per device) using PySpark. Example dataset:
+--------+-----------------------+-----------------------+
|deviceId|startDate |endDate |
+--------+-----------------------+-----------------------+
|11615 |2022-06-11 13:48:11.6 |2022-06-13 18:05:44.2 |
|11618 |2022-07-11 22:17:24.401|2022-07-11 23:33:05.307|
|11618 |2022-07-28 02:29:14.6 |2022-08-08 23:33:05.103|
+--------+-----------------------+-----------------------+
I would like to compute daily availability rates/uptime, per device, for an arbitrary number of days, to end up with something like:
+───────────+─────────────+─────────+
| deviceId | day | uptime |
+───────────+─────────────+─────────+
...
| 11615 | 2022-06-10 | 100% |
| 11615 | 2022-06-11 | 88.3% |
| 11615 | 2022-06-12 | 0% |
| 11615 | 2022-06-13 | 76% |
| 11618 | 2022-06-10 | 100% |
...
+───────────+─────────────+─────────+
(Numbers are approximations here)
I'm not sure if this is doable without user-defined functions - any recommendation?