473,585 Members | 2,621 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calculate Moving Average

11 New Member
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 10892
Markus
6,050 Recognized Expert Expert
What is 'moving average'?
Dec 11 '07 #2
paeh
11 New Member
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
GeoffreyTransom
1 New Member
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.blog spot.com
Feb 18 '08 #4

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

Similar topics

2
13597
by: Wayne Aprato | last post by:
I've read most, if not all, of the posts on moving average and still can't find a simple solution to my problem (if a simple solution exists!) I have a table with 2 fields: Hours and Injuries. I have a query based on this table which shows these 2 fields and calculates a third field: Frequency Rate, based on a formula which uses the Hours and...
2
3638
by: Steve | last post by:
Hi all How would I find out the average date when given a bunch of dates? For example, I want to find the average length in time from the following dates: ---------------------------------------------------- Start Date End Date 01/01/2004 12:50pm 02/01/2004 18:40pm 02/01/2004 13:40pm 02/01/2004 13:57pm...
1
20985
by: HEMH6 | last post by:
Weihted Average Write a C program to calculate and print the weighted average of a list of N floating point number, using the formula Xave = F1X1 + F2X2+...+ FnXn where the F's are fractional weighting factors, i.e. 0<=F1<1, and F1+F2+...+Fn=1
4
6531
by: gaga | last post by:
hi guys, a part of my program requires me to calculate an average of items that are sold. the easiest way to do that would be writing a function, but im having trouble making up the parameters. if you can point me which elements to use when performing such a task, i would really appreciate it. thanks
1
7281
by: Sedigh | last post by:
Hi Everybody, I need to write a macro on my Excel sheet to calculate the average of cells for me. This is the code I have written but the average function is not working. Can you please let me know how can I use the Average function in my code. Thanks alot Sub Macro1() Ncol = 1 nrowColumn2 = 1 i = 1 Do Until...
7
10223
by: jamesnkk | last post by:
Hi, Although this question may not directly link to Access, but I think it a common question to those developer.so hope you could suggest a solution. How do I get the average cost for Item sold, so I could calculate the Profit.- Same Product item could bought from different suppliers, different suppliers have different cost price or buying...
0
4628
by: SuzK | last post by:
I am trying to calculate in VBA in Access 2002 a moving average and update a table with the calculations. Fields in my WeeklyData table are Week Ending (date) ItemNbr (double) Sales Dollars (double) Sales Units (double) Promo (Text) -- is null or "X" AvgWklyDollars (double) AvgWklyUnits (double) I have a vba module which I thought would...
3
4866
by: hanie | last post by:
a student wants to know his grade average for the semester. the grades are give in letter grades with numeric equivalents. develop a solution to calculate a grade average given the letter grades(the grade average is is figured per unit of credit!) A=4.0 B=3.0 C=2.0 D=1.0 F=0.0 use a trip value to stop the processing of the loop and case...
1
7605
by: Michel | last post by:
Hello, I need to calculate moving averages of weekly data during the last year. After some search, I believe that the best approach will be to get a dataset from the SQL Server database, browse the records and, using an algorithm, calculate the moving average. There is an article on the "Code Project" website entitled "A Simple Moving...
0
7900
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7832
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8192
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8204
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
3828
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3853
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2338
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1442
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1167
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.