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

+ + +

Sleep Retrospective

+

The impact on your sleep, for the last on-call rotations breaks down as follows:

+ +
On-call Period:
+ + +

Notifications