From c9a5b30d4b6b4f1b2e9e25d0e37e5e83c063f324 Mon Sep 17 00:00:00 2001
From: Ryan Frantz
Date: Wed, 2 Sep 2015 14:29:40 +0000
Subject: [PATCH] Adding support for a new sleep retrospective feature.
- Via the global config option 'oncall_sleep_retrospective_count', users can view the past few rotations' impact on their sleep.
- The retrospective provides the same information that's available in the on-call report visible to all users.
- The goal of this update is to help measure (on the dimension of sleep, at least) just how good/bad past rotations have been.
- Made some minor updates so that other values in the report provide data at the same precision (2 decimal points), for consistency.
- Updated the README with information on configuring the sleep retrospective option.
---
README.md | 2 ++
profile.php | 63 +++++++++++++++++++++++++++++++++++++++++++++++++----
2 files changed, 61 insertions(+), 4 deletions(-)
diff --git a/README.md b/README.md
index ea5064c..731b8d8 100644
--- a/README.md
+++ b/README.md
@@ -26,6 +26,8 @@ Alert classification is a complicated task, but with Opsweekly a few simple ques
* How have their on calls affected them?
* How much sleep do they lose on average?
* How does this compare to others?
+ * Optionally, one can view a sleep retrospective that compares the last several on-call rotations' impact on sleep loss.
+ * In `phplib/config.php`, define `oncall_sleep_retrospective_count` with a numeric value (such as 3). Users viewing their profile will then see how past weeks affected their sleep.
* **Meeting Mode**: Make running a weekly meeting simple with all the data you need in one page, and a facility for people to take notes.
* Meeting mode hides all UI displaying only information required for the meeting.
* The on call report for the previous week is included, along with key stats and elements from report
diff --git a/profile.php b/profile.php
index c679be1..48af56b 100644
--- a/profile.php
+++ b/profile.php
@@ -48,6 +48,8 @@
$mtts_total = 0;
$top_wakeup_cause = array();
$tag_graph_data[] = array("Week", "Action Taken", "No Action Taken");
+ // Let's get the last few on-call rotations for a sleep retrospective.
+ $oncall_sleep_retrospective_details = array();
// Create summary metrics about this person's on call
foreach ($oncall_ranges as $week) {
@@ -121,6 +123,45 @@
$sleep_name = $sleep_providers[$profile['sleeptracking_provider']]['display_name'];
$sleep_logo = $sleep_providers[$profile['sleeptracking_provider']]['logo'];
}
+
+ // Build up sleep-related metrics for the last few on-call rotations, for a simple retrospective.
+ $oncall_sleep_retrospective_count = getTeamConfig('oncall_sleep_retrospective_count');
+ if ($oncall_sleep_retrospective_count) {
+ // Get the last few on-call rotations, in descending order.
+ $oncall_sleep_retrospective_weeks = array_slice(array_reverse($oncall_ranges), 0, $oncall_sleep_retrospective_count);
+ foreach ($oncall_sleep_retrospective_weeks as $week) {
+ $results = getOnCallReportForWeek($week['range_start'], $week['range_end']);
+ $week_wake_ups = 0;
+ $week_sleep_loss = 0; // Seconds.
+ $week_sleep_abandoned = 0;
+ foreach ($results as $n) {
+ // Count the number of wake ups.
+ if ($n['sleep_state'] > 0) {
+ $week_wake_ups++;
+ }
+ // If we have non-zero MTTS data and the operator was asleep (1), sum the sleep loss.
+ if ($n['mtts'] > -1 && $n['sleep_state'] > 0) {
+ $week_sleep_loss = $week_sleep_loss + $n['mtts'];
+ }
+ // If MTTS is 0 and the operator was asleep when notified, the operator abandoned sleep.
+ if ($n['mtts'] == 0 && $n['sleep_state'] > 0) {
+ $week_sleep_abandoned++;
+ }
+ }
+ $week_sleep_loss_in_hours = round(($week_sleep_loss / 60 / 60), 2);
+ $week_mtts_in_minutes = round( (($week_sleep_loss / 60) / $week_wake_ups), 2);
+ // Append the retrospective data to our array.
+ $oncall_sleep_retrospective_details[] = array(
+ 'range_start' => $week['range_start'],
+ 'range_end' => $week['range_end'],
+ 'week_wake_ups' => $week_wake_ups,
+ 'week_sleep_loss_in_hours' => $week_sleep_loss_in_hours,
+ 'week_mtts_in_minutes' => $week_mtts_in_minutes,
+ 'week_sleep_abandoned' => $week_sleep_abandoned
+ );
+ }
+ }
+
}
?>
@@ -136,12 +177,12 @@
and on call reports
On Call
- Sleep
+ Sleep Summary
- You're using sleep tracking from
- You've been woken up an average of times per week
- and have lost a total of hours of sleep to notifications
- - That's an average of hours sleep lost per week
+ and have lost a total of hours of sleep to notifications
+ - That's an average of hours sleep lost per week
due to notifications ( hours globally)
- % of notifications have woken you up,
compared to the average of %
@@ -150,11 +191,25 @@
- Your Mean Time To Sleep is minutes compared to an average from all users of
minutes
+
+
+ Sleep Retrospective
+ The impact on your sleep, for the last on-call rotations breaks down as follows:
+
+ On-call Period:
+
+ - You were woken times.
+ - You were awake for a total of hours.
+ - Your mean time to sleep (MTTS) was minutes.
+ - You abandoned sleep times.
+
+
+
Notifications
- - You've had a total of notifications across weeks, giving an
+
- You've had a total of notifications across weeks, giving an
average of alerts per week.
- This compares to an average of per week in total in the last year,
leaving you