Calculating / Estimating battery capacity from charging power and level

Hi,

I have values of my charging power as well as the battery level and would like to estimate the battery capacity over time.

Normally that would be easy - I just need to integrate the discharge power over time until it stops discharging - the sum of those values would be the capacity of the battery.

But during the day it switches from discharging to charging all the time and this makes it a bit mor complicated.

I have all the data in a InfluxDB and use Grafana for analysis and visualization.

Any ideas how these estimates could be approached?