Skip to content
This repository has been archived by the owner on Jan 3, 2023. It is now read-only.

Commit

Permalink
Adding support for a new sleep retrospective feature.
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
Ryan Frantz committed Sep 2, 2015
1 parent c87e44a commit c9a5b30
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -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
Expand Down
63 changes: 59 additions & 4 deletions profile.php
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
);
}
}

}

?>
Expand All @@ -136,12 +177,12 @@
and <?php echo $num_oncall; ?> on call reports</p>
<h3>On Call</h3>
<?php if ($sleep_tracking) { ?>
<h4>Sleep</h4>
<h4>Sleep Summary</h4>
<ul class='stats lead'>
<li>You're using sleep tracking from <img src="<?php echo $sleep_logo; ?>"> <strong><?php echo $sleep_name; ?></strong></li>
<li>You've been woken up an average of <strong><?php echo round($sleep_status_agg[1] / $num_oncall, 1); ?> times per week</strong>
and have lost a total of <strong><?php echo round( $mtts_total / 60 / 60, 1); ?> hours of sleep</strong> to notifications</li>
<li>That's an average of <strong><?php echo round ( ($mtts_total / $num_oncall) / 60 / 60, 1); ?> hours sleep lost per week</strong>
and have lost a total of <strong><?php echo round( $mtts_total / 60 / 60, 2); ?> hours of sleep</strong> to notifications</li>
<li>That's an average of <strong><?php echo round ( ($mtts_total / $num_oncall) / 60 / 60, 2); ?> hours sleep lost per week</strong>
due to notifications (<?php echo round ( ($all_mtts_total / $total_weeks) / 60 / 60, 1); ?> hours globally)</li>
<li><strong><?php echo round($my_wake_ups_pct, 1); ?>%</strong> of notifications have woken you up,
compared to the average of <?php echo round($all_wake_ups_pct, 1); ?>%</li>
Expand All @@ -150,11 +191,25 @@
<li>Your <strong>Mean Time To Sleep is <?php echo $mtts; ?> minutes</strong> compared to an average from all users of
<?php echo $all_mtts; ?> minutes</li>
</ul>

<?php if ($oncall_sleep_retrospective_count) { ?>
<h4>Sleep Retrospective</h4>
<p class='lead'>The impact on your sleep, for the last <?php echo $oncall_sleep_retrospective_count; ?> on-call rotations breaks down as follows:</p>
<?php foreach ($oncall_sleep_retrospective_details as $retrospective) { ?>
<h5>On-call Period: <?php echo date("l jS F Y", $retrospective['range_start']) . ' - ' . date("l jS F Y", $retrospective['range_end']); ?></h5>
<ul>
<li>You were woken <b><?php echo $retrospective['week_wake_ups']; ?> times</b>.</li>
<li>You were awake for a total of <b><?php echo $retrospective['week_sleep_loss_in_hours']; ?> hours</b>.</li>
<li>Your mean time to sleep (MTTS) was <b><?php echo $retrospective['week_mtts_in_minutes']; ?> minutes</b>.</li>
<li>You abandoned sleep <b><?php echo $retrospective['week_sleep_abandoned']; ?> times</b>.</li>
</ul>
<?php } ?>
<?php } ?>
<?php } ?>

<h4>Notifications</h4>
<ul class='stats lead'>
<li>You've had a total of <?php $personal_notifications; ?> notifications across <?php echo $num_oncall; ?> weeks, giving an
<li>You've had a total of <?php echo $personal_notifications; ?> notifications across <?php echo $num_oncall; ?> weeks, giving an
average of <strong><?php echo $personal_per_week; ?> alerts per week</strong>. </li>
<li>This compares to an average of <?php echo $total_per_week; ?> per week in total in the last year,
leaving you <strong><?php echo $per_week_diff; ?></strong></li>
Expand Down

0 comments on commit c9a5b30

Please sign in to comment.