Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Saving data into file and computing average

  1. #1
    Junior Member
    Join Date
    Jan 2020
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Saving data into file and computing average

    Hello,

    I have a simple program that reads temperature, humidity and some other data from server every 10 seconds. Together it is 8 float numbers. This way i see in realtime the temperature, humidity and other parameters. But now i would also like to see history of this data. For instance, i see that the temperature right now is 28C, but i am interested in seeing what was the average of last 24 hours. Or maybe average since it started measuring it.

    Now solution to this is very simple. Write this 8 floats into file every 10 seconds and then just sum all the numbers and divide by the number of lines. The problem is that in just 1 day, i will get 8640 lines of data, that means 69120 float numbers. I am running this program from my main computer where i also do other things like an occasional video game. And somehow it seems that summing and dividing such a huge amount of numbers will crank up my cpu and eat a lot of ram. Or am i mistaken ?

    What would be the best solution for this problem. Again, i am ok with just the average of last 24 hours, or maybe last 7 days. I want the program to be as lighweight as possible, without burning huge amount of cpu.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Saving data into file and computing average

    it seems that
    Try it and see what happens. Work on fixing a problem when it is found.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jan 2020
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Saving data into file and computing average

    Quote Originally Posted by Norm View Post
    Try it and see what happens. Work on fixing a problem when it is found.
    Alright, ur right. I will try the brute method just out of curiosity, to see how much resources it takes, might not take much at all. But after that i think i got a solution. I will simply store values in array in a program and only write to file occasionaly. Lets say i measure values every 10 seconds. That means 6 lines per minute, 360 lines per hour. I could only write to file every hour and write down the average i get from that hour (360 lines in an array). In the meanwhile i will still gladly take any pointers, i mean programs do that all the time, log things, view data, etc. So there must be an efficient way to do that.

Similar Threads

  1. Data Dedupllication In Cloud Computing
    By Jason Phang in forum The Cafe
    Replies: 3
    Last Post: June 5th, 2019, 05:32 AM
  2. Data Storage Security in Cloud Computing
    By Amakuru in forum Member Introductions
    Replies: 1
    Last Post: October 23rd, 2012, 02:34 AM
  3. [SOLVED] I need help with saving state data.
    By JonLane in forum Collections and Generics
    Replies: 6
    Last Post: February 27th, 2012, 03:48 AM
  4. Something wrong with computing the average
    By maximus20895 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: October 18th, 2010, 07:51 AM
  5. need help with saving data
    By bardd in forum Java Theory & Questions
    Replies: 5
    Last Post: September 19th, 2010, 02:33 PM