diff --git a/analytics/classes/local/time_splitting/accumulative_parts.php b/analytics/classes/local/time_splitting/accumulative_parts.php index f1b06b37cd6..45fd2a876e2 100644 --- a/analytics/classes/local/time_splitting/accumulative_parts.php +++ b/analytics/classes/local/time_splitting/accumulative_parts.php @@ -51,11 +51,11 @@ abstract class accumulative_parts extends base { $nparts = $this->get_number_parts(); - $rangeduration = intval(floor(($this->analysable->get_end() - $this->analysable->get_start()) / $nparts)); + $rangeduration = ($this->analysable->get_end() - $this->analysable->get_start()) / $nparts; $ranges = array(); for ($i = 0; $i < $nparts; $i++) { - $end = $this->analysable->get_start() + ($rangeduration * ($i + 1)); + $end = $this->analysable->get_start() + intval($rangeduration * ($i + 1)); if ($i === ($nparts - 1)) { // Better to use the end for the last one as we are using floor above. $end = $this->analysable->get_end(); diff --git a/analytics/classes/local/time_splitting/equal_parts.php b/analytics/classes/local/time_splitting/equal_parts.php index 14e88346d95..7d4885813e2 100644 --- a/analytics/classes/local/time_splitting/equal_parts.php +++ b/analytics/classes/local/time_splitting/equal_parts.php @@ -51,15 +51,23 @@ abstract class equal_parts extends base { $nparts = $this->get_number_parts(); - $rangeduration = intval(floor(($this->analysable->get_end() - $this->analysable->get_start()) / $nparts)); + $rangeduration = ($this->analysable->get_end() - $this->analysable->get_start()) / $nparts; + + if ($rangeduration < $nparts) { + // It is interesting to avoid having a single timestamp belonging to multiple time ranges + // because of things like community of inquiry indicators, where activities have a due date + // that, ideally, would fall only into 1 time range. If the analysable duration is very short + // it is because the model doesn't contain indicators that depend so heavily on time and therefore + // we don't need to worry about timestamps being present in multiple time ranges. + $allowmultipleranges = true; + } $ranges = array(); for ($i = 0; $i < $nparts; $i++) { - $start = $this->analysable->get_start() + ($rangeduration * $i); - $end = $this->analysable->get_start() + ($rangeduration * ($i + 1)); + $start = $this->analysable->get_start() + intval($rangeduration * $i); + $end = $this->analysable->get_start() + intval($rangeduration * ($i + 1)); - // Check the end of the previous time range. - if ($i > 0 && $start === $ranges[$i - 1]['end']) { + if (empty($allowmultipleranges) && $i > 0 && $start === $ranges[$i - 1]['end']) { // We add 1 second so each timestamp only belongs to 1 range. $start = $start + 1; } diff --git a/analytics/classes/site.php b/analytics/classes/site.php index 8e9a634d078..d616d4bce04 100644 --- a/analytics/classes/site.php +++ b/analytics/classes/site.php @@ -83,7 +83,7 @@ class site implements \core_analytics\analysable { if ($events) { // There should be just 1 event. $event = reset($events); - $this->start = $event->timecreated; + $this->start = intval($event->timecreated); } else { $this->start = 0; } @@ -111,7 +111,7 @@ class site implements \core_analytics\analysable { if ($events) { // There should be just 1 event. $event = reset($events); - $this->end = $event->timecreated; + $this->end = intval($event->timecreated); } else { $this->end = time(); }