Emoncms V7 Daily Average Function (Arithmetic Mean)

Emoncms V7 doesn't seem to have a daily average function.  I recently upgraded to V7 and found my Heating Degree Day feed was not working.  This used the daily average feature (V5) to calculate the average outside temperature below a certain value (ie equivalent to the HDD).

I know there have been posts about average temperature calculation here before, but I can't see a solution.

I have tried the slightly contrived method of using kWh to KWh/d, but this doesn't seem to be a daily average of the data.  At least the result is not correct.

Does anyone have a solution to calculating a daily average?

Any help would be much appreciated.

john.b's picture

Re: Emoncms V7 Daily Average Function (Arithmetic Mean)

Would the solution to this be as simple as copying the relevant php function from the V5 process_model.php file and placing in the V7 process_model.php file?

john.b's picture

Re: Emoncms V7 Daily Average Function (Arithmetic Mean)

I have no experience of php so I'm a little lost here, but I modified the process_model.php file by adding the following from my V5 file:

// Calculates a daily average of a value
    public function average($feedid, $time_now, $value)
    {
      $feedname = "feed_" . trim($feedid) . "";
      $feedtime = mktime(0, 0, 0, date("m",$time_now), date("d",$time_now), date("Y",$time_now));

      $result = $this->mysqli->query("SELECT * FROM $feedname WHERE time = '$feedtime'");
      if (!$result)  return $value;
      $row = $result->fetch_array();

      $average = $row['data'];
      $size = $row['data2'];

      $new_average = (($average * $size) + $value) / ($size + 1);
      $size = $size + 1;

      if ($row)
      {
        $this->mysqli->query("UPDATE $feedname SET data = '$new_average', data2 = '$size' WHERE time = '$feedtime'");
      }
      else
      {
        $this->mysqli->query("INSERT INTO $feedname (`time`,`data`,`data2`) VALUES ('$feedtime','$value','1')");
      }

      $updatetime = date("Y-n-j H:i:s", $time_now);
      $this->mysqli->query("UPDATE feeds SET value = '$new_average', time = '$updatetime' WHERE id='$feedid'");

      return $value;
    }
 

also changing the list to

     $list[17] = array(_("Daily Average"),ProcessArg::FEEDID,"average",2,DataType::HISTOGRAM,"Misc");

I now have the daily average function in the process list, which is one step forward, but unfortunately the feed does not update.  Also the datatype keeps reverting to daily after it has been changed to a histogram?

any suggestions?

 

TrystanLea's picture

Re: Emoncms V7 Daily Average Function (Arithmetic Mean)

john.b, do you mean v8 instead of v7? The v8 PHPFIWA (fixed interval with averaging) feed engine has daily averaging built in. It replaces the average input processor. You can also request averages on any other base period: hourly, monthly and so on.

john.b's picture

Re: Emoncms V7 Daily Average Function (Arithmetic Mean)

Hello Trystan,

Thanks for the help.  I'm using V7 as per the hard drive image.  I'm also using mysql database, which I prefer to stick with as I don't have fixed intervals.

Further to my post above I just found my database is actually updating with my modified code, but the feed in emoncms says it is NOT.

I have run admin update and check with the appropriate line ($updatelogin = TRUE;) in setting.php

I've also deleted the browser cache and refreshed the page, but the feed does not show its updating.

Any clues as to why the feed does not show its updating?

rbreuss's picture

Re: Emoncms V7 Daily Average Function (Arithmetic Mean)

Trystan, I need daily averaging function as well. But looking into PHPFIWA options, there is at maximum 1 hour of averaging interval. How do you process correct calculation of daily average value (lets say average temperature) with PHPFIWA?

lassetobiasen's picture

Re: Emoncms V7 Daily Average Function (Arithmetic Mean)

Hi everyone,

I'm not sure if you'll still be reading this post, given the last entry was a year ago.

Anyway, I was wondering if there was a solution to the issue of making daily averages (or averages based on other - user defined - intervals) ? It seems the above thread did not come to a resolution.

I'm using the emoncms software as it is on the homepage (http://emoncms.org) which is currently at version 8.3.5. However, the PHPFIWA interval option is at maximum one hour. I therefore cannot see how to calculate a feed as a daily average.

Although it seems possible to adjust the PHP code with a V5 file (process_model.php as described above) this is a little tricky for me, since I'm using the standard software on the emoncms.org server. 

Thanks in advance.

Lasse

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.