Connecting Tech Pros Worldwide Forums | Help | Site Map

Calculate Moving Average

Newbie
 
Join Date: Dec 2007
Posts: 11
#1: Dec 11 '07
hello..can anyone help me. I am beginner in programming. I need to make a system that can calculate moving average.

my system process will be executed according to certain schedule such as daily, weekly or monthly based on the data in the database. The moving average will then be recorded for further process.

I want to know what is the software should be use to develop it? and can anyone show me a simple coding to calculate moving average.

please..I need help..:(

Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,949
#2: Dec 11 '07

re: Calculate Moving Average


What is 'moving average'?
Newbie
 
Join Date: Dec 2007
Posts: 11
#3: Dec 12 '07

re: Calculate Moving Average


moving average is the process that will be executed according to certain schedule such as daily, weekly or monthly based on the data in the database. For your information, I plan to use MySQL database server. It can be produce by graph,chart or table.

Actually, I want to develop web based communicable disease reporting system
(Surveillance system for Flu and Entrovirus).

I don't know what kind of software to develop it. can I use PHP?
Newbie
 
Join Date: Feb 2008
Posts: 1
#4: Feb 18 '08

re: Calculate Moving Average


Quote:

Originally Posted by paeh

moving average is the process that will be executed according to certain schedule such as daily, weekly or monthly based on the data in the database. For your information, I plan to use MySQL database server. It can be produce by graph,chart or table.

Actually, I want to develop web based communicable disease reporting system
(Surveillance system for Flu and Entrovirus).

I don't know what kind of software to develop it. can I use PHP?

hello Paeh.

The easiest way is to retrieve the data from MySQL into, say, PHP, then use Array formulae to operate on it.


So if for example the series you want to average is in table datatable and is called dataseries and is stored by indexseries, then do the following:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. include('[name of database include]');
  4.  
  5. $MALength=13; //assumes the length of the MA you want is 13
  6.  
  7. $sql1=mysql_query("select dataseries from datatable order by indexseries desc") or die ('data retrieval broke - '.mysql_error());
  8. $data=Array();
  9. while ($row=mysql_fetch_row($sql1))
  10. {
  11. $data[]=$row[0];
  12. }
  13. for ($i=0;$i<count($data);$i++)
  14. {
  15. $MovAverage[$i]=round(array_sum(array_slice($data,max($i-$MALength+1,0),$MALength))/count(array_slice($data,max($i-$MALength+1,0),$MALength)),4);
  16. }
  17.  
  18. mysql_free_result($sql);
  19.  
  20. ?>
While this might not be the most elegant method (I am sure there are purists who would be horrified), the end result ought to be a vector variable $MovAverage which contains the moving average you desire.

Given that I am on my fourth glass of a rather cheeky Rosé, there are no doubt some typos in the code... but nothing too drastic. The first thing to look for is missing line ends... I am diabolical at those.

Hope this helps...



GT
France
http://marketrant.blogspot.com
Reply