The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Java Help
|
Help! Averaging weekly values from a file
Discuss Help! Averaging weekly values from a file in the Java Help forum on Dev Shed. Help! Averaging weekly values from a file Java Help forum discussing all Java platforms - J2ME, J2SE and J2EE - as well as relevant standards, APIs and frameworks such as Swing, Servlets, JSPs, Applets, Struts, Spring, Hibernate, ANT, EJB, and other Java-related topics.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

November 28th, 2012, 07:53 PM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 5
Time spent in forums: 1 h 29 m 2 sec
Reputation Power: 0
|
|
|
Help! Averaging weekly values from a file
Basically i have an assignment where i have to read information from a text file that has a month of data and use it to find different averages and min and max values etc.
The problem is that i am not sure how to figure out the average for just one week since the information in my file is for one month.
I figured out how to read the file and how to do monthly averages but i am not sure how to do it for just one week.
This is what i have so far (i decided to do a loop):
count = 0;
double weekOneAveragePressure;
double sumWeekOneAveragePressure = 0;
while (count<counter){
sumWeekOneAveragePressure += Pressure[count];
if (count<6)
sumWeekOneAveragePressure += Pressure[count];
else if (count==6)
weekOneAveragePressure = (sumWeekOneAveragePressure / count);
count++;
I start by resetting the count to zero cause i used it to calculate monthly averages. The counter was also declared before in a try and catch statement where the file reading and array declarations take place.
What would i have to add and fix to the code to make it calculate the average of just one week (7days)?
|

November 28th, 2012, 08:44 PM
|
 |
Contributing User
|
|
Join Date: Aug 2010
Location: SW Missouri
|
|
Quote: | how to do it for just one week |
Have a counter for weekly data. Reset it to 0 at the start of every week.
|

November 29th, 2012, 06:06 AM
|
|
Contributing User
|
|
Join Date: Mar 2007
Location: Portugal
Posts: 38
  
Time spent in forums: 4 Days 6 h 34 m 46 sec
Reputation Power: 8
|
|
|
The 7 day can work if you have records for saturday and sunday also, because if your week is only monday to friday it won't work.
But first of all how is the data organized?
By days? or Simply a complete month data?
|

November 29th, 2012, 09:34 AM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 5
Time spent in forums: 1 h 29 m 2 sec
Reputation Power: 0
|
|
|
Its organized from a separate text file, which has 30 different numbers for each of the seven categories (pressure, temperature, etc) and are seperated by commas.
Like this:
01,0.475,19.5,-149.0,30,92,No
02,0.480,20.5,-142.0,28,96,No
03,0.505,19.1,-152.0,39,72,Yes
04,0.425,22.5,-143.0,31,90,No
05,0.528,18.2,-140.0,42,69,Yes
06,0.490,18.3,-138.0,34,99,No
07,0.498,23.1,-141.0,37,82,Yes
.......etc.
|

November 29th, 2012, 09:36 AM
|
 |
Contributing User
|
|
Join Date: Aug 2010
Location: SW Missouri
|
|
|
Can you tell when the data for each week starts?
|

November 29th, 2012, 10:01 AM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 5
Time spent in forums: 1 h 29 m 2 sec
Reputation Power: 0
|
|
|
Basically the data is everything in each column. Each column has 30 numbers which represents one month. Somehow i am supposed to break it down into weeks and calcucate the averages for each week.
This is my code for calculating a monthly average for the column which represents data for pressure:
double averagePressure;
double sumPressure = 0;
int count = 0;
while (count<counter)
{
sumPressure += Pressure[count];
count++;
}
averagePressure = (sumPressure / count);
|

November 29th, 2012, 10:12 AM
|
 |
Contributing User
|
|
Join Date: Aug 2010
Location: SW Missouri
|
|
Quote: | Each column has 30 numbers which represents one month. |
Does each column represent the data for a day? What about the months with 31 or 28/29 days?
You need to know what each piece of data represents.
In post#4 each line starts with a new number that looks like a row number. What is the first value on each line? How many lines are in the file? Are they all numbered as shown in post#4?
Last edited by NormR : November 29th, 2012 at 10:14 AM.
|

November 29th, 2012, 10:24 AM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 5
Time spent in forums: 1 h 29 m 2 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by NormR Does each column represent the data for a day? What about the months with 31 or 28/29 days?
You need to know what each piece of data represents. |
The data is just for one month (september; which has thirty days.
The first column represents the days, second column represents pressure, third represents highest temperature, fourth represents lowest temperature, fifth is for wind speed, sixth is for battery power, and seventh is a true/false thing (boolean).
So each row would represent the data for all types each day.
|

November 29th, 2012, 10:33 AM
|
 |
Contributing User
|
|
Join Date: Aug 2010
Location: SW Missouri
|
|
|
How do you tell which data is for the each day of the month?
Does the first column have the day of the month?
Then are days 01 to 07 one week of data?
And 08 to 14 are the second week of data?
Can you explain what your problem is with determining when a week starts?
Would the first week start at day 01 and the second week start with 08?
|

November 29th, 2012, 10:36 AM
|
|
Registered User
|
|
Join Date: Nov 2012
Posts: 5
Time spent in forums: 1 h 29 m 2 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by NormR How do you tell which data is for the each day of the month?
Does the first column have the day of the month?
Then are days 01 to 07 one week of data?
And 08 to 14 are the second week of data?
Can you explain what your problem is with determining when a week starts?
Would the first week start at day 01 and the second week start with 08? |
Yes and my issue is that i dont know how i would find out the averages for those 7 days and then the averages for 8-14
|

November 29th, 2012, 10:39 AM
|
 |
Contributing User
|
|
Join Date: Aug 2010
Location: SW Missouri
|
|
Quote: | how i would find out the averages for those 7 days |
Add up the daily values for the 7 days and divide by 7
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|