How to calculate energy consumption