Closed GoogleCodeExporter closed 8 years ago
About this issue and issue 145.
I have the same problem with version 0.7
I took a look at the source code and found the bug.
In the home activity (HomeActivity.java), you compute the total sleep time (l.
92-99) and then you take the average by dividing by the number of sleep (l.
102).
This is fine as long as there is no overflow.
Here it is the case. You sum up the sleep time (in ms) in an int, l. 88 :
int avgDuration = 0;
As the maximum value for an int is 2^31-1 (2147483647), if you sleep an average
of 8 hours (28800000ms), it gives you a correct average for the first
2147483647/28800000 ~= 74 nights. After that the value is bogus.
A quick simple fix is to declare avgDuration as a long in line 88 :
long avgDuration = 0;
It is even better as SleepRecord.getTimespanText() takes a long as first
parameter so you will avoid a cast. You might consider using a long for
avgFellAsleep as well.
With a long, assuming an average of 8 hours per night, one could sleep
(2^63-1)/28800000 ~= 320 255 973 501 nights, so the average will be accurate
during more than 800 000 000 years!
Original comment by nicolabr...@gmail.com
on 30 Jun 2011 at 3:06
Ive dropped development on this project for some time. If you supply the fix, I
might update the market app (despite catching ire from quite a few people, I am
sure)
Original comment by jondwil...@gmail.com
on 30 Jun 2011 at 3:21
Well here it is.
I also changed the way you compute the average. Since a division is very
time-consuming, I take the inverse of count only once and then multiply each
stat by it.
Original comment by nicolabr...@gmail.com
on 1 Jul 2011 at 7:25
Attachments:
Hey Jon,
Change the int to an long for all ms records should fix the problem.
Best,
Edison
Original comment by wzsddtc
on 12 Jul 2011 at 8:38
nicola, i applied your fix in r132. thank you.
Original comment by jondwil...@gmail.com
on 14 Aug 2011 at 5:00
Original issue reported on code.google.com by
criscoa...@gmail.com
on 24 May 2011 at 3:55