So you'll know that for this specific phone, 4040mAh equals 32 minutes remaining for this phone, instead of 40, because the last 10 chargings, on average, there was 32m remaining @ 4040mAh, 25m @ 4100, 15 @ 4150, 5 @ 4170. And because a battery degrade in time, and a new firmware can also improve - or not - battery duration, your program will always be accurate. I'm maybe wrong, but it's how I see the thing