469,616 Members | 1,676 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,616 developers. It's quick & easy.

Calculate Moving Average

11
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..:(
Dec 11 '07 #1
3 10060
Markus
6,050 Expert 4TB
What is 'moving average'?
Dec 11 '07 #2
paeh
11
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?
Dec 12 '07 #3
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
Feb 18 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Steve | last post: by
4 posts views Thread by gaga | last post: by
1 post views Thread by Michel | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.