Win a copy of hapi.js in Action this week in the HTML, CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

capturing maximum value in a file based on data in another arraylist

 
saeid jamali
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't need thosevalues per hour. all I need at this point is to calculate the average, min an max value of the temp per hour.
 
Carey Brown
Bartender
Posts: 2125
26
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, do you plan on passing a list that only contains readings for a single hour to your Max() method?
 
saeid jamali
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Carey Brown wrote:So, do you plan on passing a list that only contains readings for a single hour to your Max() method?

My plan is to parse a list that contains like temperature only based on changes in hour data
 
saeid jamali
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So is there anybody who can help?
 
Campbell Ritchie
Sheriff
Posts: 52001
90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, of course there are people who can help. But you haven't taken much notice of the help you have already been given.
 
Carey Brown
Bartender
Posts: 2125
26
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By taking the burden of dividing the data into hourly block out of the statistics calculations, not only does it simplify the code, but it also allows you to get statistics for ranges other than hours.
 
Campbell Ritchie
Sheriff
Posts: 52001
90
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use a Stream and get the maximum like this:-If you get that sort of code to run (Java8 only) you will find you get a lot more than the maximum. You can filter the Stream by adding a line 1½ like this:-
.filter(w -> w.getDate().isLater(startDate) && w.getDate().isEarlier(endDate))
I would use the new Java8 classes for the dates, not java.util.C‍alendar.
 
saeid jamali
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So as you said instead of adding the each sensor reading to a new arralist I'm trying to keep in one arraylist and call them using getter but I have a big problem with nulls. for example insteadof line 3 and 9 I'm trying to add the creat an object and add the data to statics lists

the issue is in the first loop there is no data getTempmin so it will be null in the Arraylist and in the second loop there is no data for getTempmax so it will be null in the ArrayList and when I want to use the list in a chart it won't work because of the huge amount of the null elements.
I tried to remove the null and I tried a few ways which didn't work and still got null in my output and I thought maybe it's a better idea if I prevent the null in the first place.
So is there any efficient wat to avoid null in the list?
I tried to use if the element is not null add it to the chart but what if it is null then there will be no data for that specific time so it wasn't a good way.
 
Junilu Lacar
Sheriff
Posts: 9338
96
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you were using Java 8 streams you'd just stream the list, group by hour, then get the average/max/min temp per group.

That's assuming the list contains sensor data for a single day.
 
saeid jamali
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have that part covered now but the only issue is when these two codes are executed the arrayList  for 6 elements will look like this.
[min=null, max=80]
[min=null, max=70]
[min=null, max=60]
[min=30, max=null]
[min=20, max=null]
[min=15, max=null]

I want it to look like

[min=30, max=80]
[min=20, max=70]
[min=15, max=60]
 
Campbell Ritchie
Sheriff
Posts: 52001
90
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you calculating the maxima and minima? It would appear you have a class with maximum and minimum fields and you are only setting one whereas you ought to set both.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!