monthly_energy_balance_work.../sra_engine.py

35 lines
1.1 KiB
Python
Raw Normal View History

import subprocess
from subprocess import SubprocessError, TimeoutExpired, CalledProcessError
import platform
from hub.exports.exports_factory import ExportsFactory
from hub.imports.results_factory import ResultFactory
class SraEngine:
2023-06-07 14:48:21 -04:00
def __init__(self, city, file_path, output_file_path):
"""
SRA class
:param file_path: _sra.xml file path
:param output_file_path: path to output the sra calculation
"""
self._city = city
self._file_path = file_path
self._output_file_path = output_file_path
if platform.system() == 'Linux':
self._executable = 'sra'
elif platform.system() == 'Windows':
self._executable = 'shortwave_integer'
2023-06-07 14:48:21 -04:00
ExportsFactory('sra', self._city, output_file_path).export()
self._run()
ResultFactory('sra', self._city, output_file_path).enrich()
def _run(self):
"""
Calls the software
"""
try:
subprocess.run([self._executable, str(self._file_path)], stdout=subprocess.DEVNULL)
except (SubprocessError, TimeoutExpired, CalledProcessError) as error:
raise Exception(error)