system_assignation/hub/imports/usage/usage_helper.py

44 lines
1.6 KiB
Python

"""
Usage helper
SPDX - License - Identifier: LGPL - 3.0 - or -later
Copyright © 2023 Concordia CERC group
Project Coder Pilar Monsalvete Alvarez de Uribarri pilar.monsalvete@concordia.ca
"""
import sys
from hub.hub_logger import logger
import hub.helpers.constants as cte
from hub.helpers.configuration_helper import ConfigurationHelper as ch
class UsageHelper:
"""
UsageHelper class
"""
@staticmethod
def cold_water_temperature(ground_temperature):
keys = ground_temperature.keys()
depths = ground_temperature[keys[0]].keys()
if keys[0] == cte.YEAR:
# taking the deeper temperature available
_cold_temperature = ground_temperature[cte.YEAR][depths[len(depths-1)]]
elif keys[0] == cte.MONTH:
_cold_temperature = 0
for i in range(0, 12):
# taking the deeper temperature available
_cold_temperature += ground_temperature[cte.MONTH][depths[len(depths-1)]] / 12
elif keys[0] == cte.HOUR:
_cold_temperature = 0
for i in range(0, 8760):
# taking the deeper temperature available
_cold_temperature += ground_temperature[cte.HOUR][depths[len(depths-1)]] / 8760
else:
_cold_temperature = ch().cold_water_temperature
logger.error(f'Cold water temperature could not be calculated. Assigned default value = '
f'{ch().cold_water_temperature} degrees Celsius\n')
sys.stderr.write(f'Cold water temperature could not be calculated. Assigned default value = '
f'{ch().cold_water_temperature} degrees Celsius\n')
return _cold_temperature