minigrida/protocols/protocol.py

68 lines
1.7 KiB
Python

#!/usr/bin/python
# -*- coding: utf-8 -*-
# \file protocol.py
# \brief TODO
# \author Florent Guiotte <florent.guiotte@gmail.com>
# \version 0.1
# \date 07 sept. 2018
#
# TODO details
import logging
import time
from collections import OrderedDict
class Protocol:
def __init__(self, expe, name=None):
self._log = logging.getLogger(name)
self._expe = expe
self._name = name
self._times = OrderedDict()
self._results_base_name = None
self._log.debug('expe loaded: {}'.format(self._expe))
def get_hashes(self):
self._log.info('Computing hashes')
return(self._get_hashes())
def set_results_base_name(self, base_name):
self._results_base_name = base_name
def run(self):
self._pt = time.process_time()
self._run()
def get_results(self):
return self._get_results()
def get_process_time(self):
return self._times
def _time(self, process):
self._times[process] = time.process_time() - self._pt
self._pt = time.process_time()
def _get_hashes(self):
self._log.warning('Protocol did not override _get_hashes()')
hashes = OrderedDict()
hashes['global'] = 'Protocol did not override _get_hashes()'
return hashes
def _run(self):
self._log.error('Protocol did not override _run()')
raise NotImplementedError('Protocol {} did not override _run()'.format(self))
def _get_results(self):
self._log.warning('Protocol did not override _get_results()')
results = OrderedDict()
results['global'] = 'Protocol did not override _get_results()'
return results
def __str__(self):
return('{}'.format(self._name))
class TestError(Exception):
pass