Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change get_data_DMY() to return all requested values #773

Merged
merged 3 commits into from
Feb 9, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Change get_data_DMY() to return all requested values
Changed the logic in PHPFina.php for get_data_DMY() to:
1. When storing the value in the array, remove the "$time<$end" as this was preventing the return of the last value and is also not required as the 'break' will prevent going past the end. This was clso ausing disparity with get_data() for the same date ranges
2. 'streamlined' the loop by making $increment a value which is defined once outside of the loop
  • Loading branch information
CDuffers committed Jan 10, 2018
commit eabd806201f574fb2dc0163e533e54c804f39a73
15 changes: 8 additions & 7 deletions Modules/feed/engine/PHPFina.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,10 @@ public function get_data($name,$start,$end,$interval,$skipmissing,$limitinterval
public function get_data_DMY($id,$start,$end,$mode,$timezone)
{
if ($mode!="daily" && $mode!="weekly" && $mode!="monthly") return false;


$increment="+1 day";
if ($mode=="weekly") $increment="+1 week";
if ($mode=="monthly") $increment="+1 month";
$start = intval($start/1000);
$end = intval($end/1000);

Expand All @@ -371,7 +374,7 @@ public function get_data_DMY($id,$start,$end,$mode,$timezone)
if ($mode=="monthly") $date->modify("first day of this month");

$n = 0;
while($n<10000) // max itterations
while($n<10000) // max iterations
{
$time = $date->getTimestamp();
if ($time>$end) break;
Expand All @@ -392,13 +395,11 @@ public function get_data_DMY($id,$start,$end,$mode,$timezone)
$value = null;
}
}
if ($time>=$start && $time<$end) {
if ($time>=$start) {
$data[] = array($time*1000,$value);
}

if ($mode=="daily") $date->modify("+1 day");
if ($mode=="weekly") $date->modify("+1 week");
if ($mode=="monthly") $date->modify("+1 month");

$date->modify($increment);
$n++;
}

Expand Down