#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    5
    Rep 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)?
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    347
    how to do it for just one week
    Have a counter for weekly data. Reset it to 0 at the start of every week.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2007
    Location
    Portugal
    Posts
    38
    Rep Power
    9
    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?
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    5
    Rep 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.
  8. #5
  9. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    347
    Can you tell when the data for each week starts?
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    5
    Rep 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);
  12. #7
  13. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    347
    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.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    5
    Rep Power
    0
    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.
  16. #9
  17. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    347
    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?
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    5
    Rep Power
    0
    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
  20. #11
  21. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,711
    Rep Power
    347
    how i would find out the averages for those 7 days
    Add up the daily values for the 7 days and divide by 7

IMN logo majestic logo threadwatch logo seochat tools logo