Skip to content

Commit

Permalink
Merge branch 'MDL-59638_master-fix' of git://github.com/dmonllao/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Aug 9, 2017
2 parents 2defbef + 42d67f9 commit ba07a8e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
4 changes: 2 additions & 2 deletions analytics/classes/local/time_splitting/accumulative_parts.php
Expand Up @@ -51,11 +51,11 @@ protected function define_ranges() {

$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();
Expand Down
18 changes: 13 additions & 5 deletions analytics/classes/local/time_splitting/equal_parts.php
Expand Up @@ -51,15 +51,23 @@ protected function define_ranges() {

$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;
}
Expand Down
4 changes: 2 additions & 2 deletions analytics/classes/site.php
Expand Up @@ -83,7 +83,7 @@ public function get_start() {
if ($events) {
// There should be just 1 event.
$event = reset($events);
$this->start = $event->timecreated;
$this->start = intval($event->timecreated);
} else {
$this->start = 0;
}
Expand Down Expand Up @@ -111,7 +111,7 @@ public function get_end() {
if ($events) {
// There should be just 1 event.
$event = reset($events);
$this->end = $event->timecreated;
$this->end = intval($event->timecreated);
} else {
$this->end = time();
}
Expand Down

0 comments on commit ba07a8e

Please sign in to comment.