By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,591 Members | 650 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,591 IT Pros & Developers. It's quick & easy.

Calculate Moving Average

P: 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
Share this Question
Share on Google+
3 Replies


Markus
Expert 5K+
P: 6,050
What is 'moving average'?
Dec 11 '07 #2

P: 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

P: 1
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.