From 7ca3c286ffd902b364a5f3236882e2c505c609ed Mon Sep 17 00:00:00 2001 From: "david.2.cassidy" Date: Thu, 3 Jun 2021 14:38:20 +0100 Subject: [PATCH] ISSUE-22 Added a new output method to write the data and clear the buffer. Its invoked every 102400 data points --- common.php | 21 ++++++++++++++++++++- processes/batterysimulator.php | 6 +++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/common.php b/common.php index 9c1ed75..d1bd410 100644 --- a/common.php +++ b/common.php @@ -200,7 +200,26 @@ public function set_output_meta($start_time,$interval) { if ($this->meta[$key]->end_time==0) $this->meta[$key]->end_time = $start_time; } } - + + public function output_all() { + $total_size = 0; + foreach (array_keys($this->buffer) as $key) { + $size = strlen($this->buffer[$key]); + if ($size>0) { + $feedid = $this->params->$key; + // Write meta data + createmeta($this->dir,$feedid,$this->meta[$key]); + // Write data + fwrite($this->fh[$key],$this->buffer[$key]); + $this->buffer[$key]=""; + $total_size += $size; + // Update feed last time and value + updatetimevalue($feedid,time(),$this->value[$key]); + } + } + return $total_size; + } + public function save_all() { $total_size = 0; foreach (array_keys($this->buffer) as $key) { diff --git a/processes/batterysimulator.php b/processes/batterysimulator.php index fc79198..662df2f 100644 --- a/processes/batterysimulator.php +++ b/processes/batterysimulator.php @@ -174,7 +174,11 @@ function batterysimulator($dir,$p) $model->write('solar_direct_kwh',$solar_direct_kwh); $i++; - if ($i%102400==0) echo "."; + if ($i%102400==0) { + echo "."; + $model->output_all(); + usleep(250); // sleep to give the feedwriter a chance + } } echo "\n";