1# Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. 2# 3# Use of this source code is governed by a BSD-style license 4# that can be found in the LICENSE file in the root of the source 5# tree. An additional intellectual property rights grant can be found 6# in the file PATENTS. All contributing project authors may 7# be found in the AUTHORS file in the root of the source tree. 8 9"""EvaluationScore factory class. 10""" 11 12import logging 13 14from . import exceptions 15from . import eval_scores 16 17 18class EvaluationScoreWorkerFactory(object): 19 """Factory class used to instantiate evaluation score workers. 20 21 The ctor gets the parametrs that are used to instatiate the evaluation score 22 workers. 23 """ 24 25 def __init__(self, polqa_tool_bin_path, echo_metric_tool_bin_path): 26 self._score_filename_prefix = None 27 self._polqa_tool_bin_path = polqa_tool_bin_path 28 self._echo_metric_tool_bin_path = echo_metric_tool_bin_path 29 30 def SetScoreFilenamePrefix(self, prefix): 31 self._score_filename_prefix = prefix 32 33 def GetInstance(self, evaluation_score_class): 34 """Creates an EvaluationScore instance given a class object. 35 36 Args: 37 evaluation_score_class: EvaluationScore class object (not an instance). 38 39 Returns: 40 An EvaluationScore instance. 41 """ 42 if self._score_filename_prefix is None: 43 raise exceptions.InitializationException( 44 'The score file name prefix for evaluation score workers is not set') 45 logging.debug( 46 'factory producing a %s evaluation score', evaluation_score_class) 47 48 if evaluation_score_class == eval_scores.PolqaScore: 49 return eval_scores.PolqaScore( 50 self._score_filename_prefix, self._polqa_tool_bin_path) 51 elif evaluation_score_class == eval_scores.EchoMetric: 52 return eval_scores.EchoMetric( 53 self._score_filename_prefix, self._echo_metric_tool_bin_path) 54 else: 55 return evaluation_score_class(self._score_filename_prefix) 56