Skip to content

Instantly share code, notes, and snippets.

@alroniks
Created March 23, 2018 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alroniks/c74b3627837623ea317c17eedffcc91b to your computer and use it in GitHub Desktop.
Save alroniks/c74b3627837623ea317c17eedffcc91b to your computer and use it in GitHub Desktop.
$get = $modx->sanitize($_GET);
if (!$get['day']) {
$now = time();
$day = date('Y-m-d', $now);
}
$day = $get['day'];
$step = 15; // minutes
$limit = 60; // 1 hour
$q = array(
'user' => 1,
'occurred:>=' => strftime('%Y-%m-%d %H:%M:%S', strtotime($day . ' 00:00:00')),
'occurred:<=' => strftime('%Y-%m-%d %H:%M:%S', strtotime($day . ' 23:59:59'))
);
$c = $modx->newQuery('modManagerLog');
$c->where($q);
$c->sortby('occurred');
$entries = array();
$log = $modx->getCollection('modManagerLog', $c);
foreach($log as $entry) {
$entries[] = $entry->occurred;
}
unset($log);
$total = count($entries);
$line = array_fill(0, 96, 0);
$work = array(0);
for ($i=0;$i<$total-1;$i++) {
$point1 = new DateTime($entries[$i]);
$point2 = new DateTime($entries[$i+1]);
$interval = $point1->diff($point2);
$interval = $interval->d * 24 * 60 + $interval->h * 60 + $interval->i;
$fromMN1 = $point1->diff(new DateTime($day . ' 00:00:00'));
$bananas1 = round(($fromMN1->h*60 + $fromMN1->i) / $step);
$fromMN2 = $point2->diff(new DateTime($day . ' 00:00:00'));
$bananas2 = round(($fromMN2->h*60 + $fromMN2->i) / $step);
// if the interval in minutes is more than the threshold, then we finish the segment, otherwise we start a new one or continue
if ($interval < $limit) {
$tmp = array_fill($bananas1, $bananas2 - $bananas1 + 1, 1);
$work = array_replace($work, $tmp);
} else {
$tmp = array_fill($bananas1, $bananas2 - $bananas1 + 1, 0);
$work = array_replace($work, $tmp);
}
}
$line = array_replace($line, $work);
for($i=0;$i<96;$i++) {
if ($line[$i]) {
echo '<span class="fill"><em>'.(($i+1)/4).'</em></span>';
} else {
echo '<span><em>'.(($i+1)/4).'</em></span>';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment