Skip to content

Commit

Permalink
changes as proposed by @hagai-shatz in pull request #617
Browse files Browse the repository at this point in the history
  • Loading branch information
TrystanLea committed Aug 21, 2017
1 parent ced61c6 commit c116b96
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions Modules/feed/engine/PHPTimeSeries.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function create($feedid,$options)
}

if (!flock($fh, LOCK_EX)) {
$msg = "data file '".$this->dir.$feedname."' is locked by another process";
$msg = "data file '".$this->dir."feed_$feedid.MYD"."' is locked by another process";
$this->log->error("create() ".$msg);
fclose($fh);
return $msg;
Expand Down Expand Up @@ -290,14 +290,15 @@ public function get_data_DMY($id,$start,$end,$mode,$timezone)
$date->setTimezone(new DateTimeZone($timezone));
$date->setTimestamp($start);
$date->modify("midnight");
$date->modify("+1 day");
if ($mode=="weekly") $date->modify("this monday");
if ($mode=="monthly") $date->modify("first day of this month");

$fh = fopen($this->dir."feed_$id.MYD", 'rb');
$filesize = filesize($this->dir."feed_$id.MYD");

$n = 0;
$array = array("time"=>0, "value"=>0);
while($n<10000) // max itterations
while($n<10000) // max iterations
{
$time = $date->getTimestamp();
if ($time>$end) break;
Expand All @@ -312,7 +313,9 @@ public function get_data_DMY($id,$start,$end,$mode,$timezone)
if ($array['time']!=$lastarray['time']) {
$data[] = array($array['time']*1000,$array['value']);
}
$date->modify("+1 day");
if ($mode=="daily") $date->modify("+1 day");
if ($mode=="weekly") $date->modify("+1 week");
if ($mode=="monthly") $date->modify("+1 month");
$n++;
}

Expand Down Expand Up @@ -391,8 +394,6 @@ public function csv_export($feedid,$start,$end,$outinterval,$usertimezone)
$fh = fopen($this->dir."feed_$feedid.MYD", 'rb');
$filesize = filesize($this->dir."feed_$feedid.MYD");

$pos = $this->binarysearch($fh,$start,$filesize);

$interval = ($end - $start) / $dp;

// Ensure that interval request is less than 1
Expand All @@ -402,8 +403,6 @@ public function csv_export($feedid,$start,$end,$outinterval,$usertimezone)
$dp = ($end - $start) / $interval;
}

$data = array();

$time = 0;

// There is no need for the browser to cache the output
Expand Down

0 comments on commit c116b96

Please sign in to comment.