I am currently powering my Arduino via a single AA LiFePO4 battery (1Ah). I would like to calculate the battery level percentage. I'm able to calculate the actual voltage just fine. I think it's based on the discharge curve of the particular chemistry. I found the following formula for a LiPo battery (from Adafruit).
This is probably not helping, but with batteries the voltage is so much influenced by the amount of load that is put on them that only if the load is constantly the same, you can use the voltage as a measure of charge. Even better would be to measure when there is no load, and the best is to measure resistance (while charging)
So if you have a variable load, you may be getting better accuracy by measuring the load and multiply this by a factor of time.
LiFePO4 discharge curve is very flat, you will not succeed with any accuracy. LiPo is totally different so that code is of no use.
For such batteries (LiFePO4) you need to constantly record the current use and integrate it to estimate the charge. The discharge curve only really is of use at the very beginning and end of the discharge cycle.