Created
February 28, 2022 16:42
-
-
Save robweber/d162a07ace09b501be180e8d54cc6f5c to your computer and use it in GitHub Desktop.
Calculate energy based on load percent
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""calc_energy.py | |
calculate the energy usage based on a load percentage and max power rating | |
""" | |
def calc_energy(current_load, max_load, min=5, unit='W'): | |
# load percent * max load | |
current_power = (current_load/100) * max_load | |
# multiply the power by the time increment | |
# time increment should be in hours | |
Wh = current_power * (min/60) | |
if(unit == 'W'): | |
return {"watts": current_power, "watt_hours": Wh} | |
else: | |
return {"kilowatts": current_power/1000, "kilowatt_hours": Wh/1000} | |
# calculate 42% load at 600W max load | |
print(calc_energy(42, 600)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment