Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 28th, 2012, 07:53 PM
Rye Rye is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 5 Rye User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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)?

Reply With Quote
  #2  
Old November 28th, 2012, 08:44 PM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: SW Missouri
Posts: 2,956 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 56 m 11 sec
Reputation Power: 345
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.

Reply With Quote
  #3  
Old November 29th, 2012, 06:06 AM
Revoh Revoh is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2007
Location: Portugal
Posts: 38 Revoh User rank is Corporal (100 - 500 Reputation Level)Revoh User rank is Corporal (100 - 500 Reputation Level)Revoh User rank is Corporal (100 - 500 Reputation Level)Revoh User rank is Corporal (100 - 500 Reputation Level) 
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?

Reply With Quote
  #4  
Old November 29th, 2012, 09:34 AM
Rye Rye is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 5 Rye User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #5  
Old November 29th, 2012, 09:36 AM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: SW Missouri
Posts: 2,956 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 56 m 11 sec
Reputation Power: 345
Can you tell when the data for each week starts?

Reply With Quote
  #6  
Old November 29th, 2012, 10:01 AM
Rye Rye is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 5 Rye User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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);

Reply With Quote
  #7  
Old November 29th, 2012, 10:12 AM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: SW Missouri
Posts: 2,956 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 56 m 11 sec
Reputation Power: 345
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.

Reply With Quote
  #8  
Old November 29th, 2012, 10:24 AM
Rye Rye is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 5 Rye User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #9  
Old November 29th, 2012, 10:33 AM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: SW Missouri
Posts: 2,956 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 56 m 11 sec
Reputation Power: 345
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?

Reply With Quote
  #10  
Old November 29th, 2012, 10:36 AM
Rye Rye is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 5 Rye User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #11  
Old November 29th, 2012, 10:39 AM
NormR's Avatar
NormR NormR is offline
Contributing User
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Aug 2010
Location: SW Missouri
Posts: 2,956 NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level)NormR User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 56 m 11 sec
Reputation Power: 345
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Help! Averaging weekly values from a file

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap