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"""EvaluationScore factory class.
9"""
10
11import logging
12
13from . import exceptions
14from . import eval_scores
15
16
17class EvaluationScoreWorkerFactory(object):
18    """Factory class used to instantiate evaluation score workers.
19
20  The ctor gets the parametrs that are used to instatiate the evaluation score
21  workers.
22  """
23
24    def __init__(self, polqa_tool_bin_path, echo_metric_tool_bin_path):
25        self._score_filename_prefix = None
26        self._polqa_tool_bin_path = polqa_tool_bin_path
27        self._echo_metric_tool_bin_path = echo_metric_tool_bin_path
28
29    def SetScoreFilenamePrefix(self, prefix):
30        self._score_filename_prefix = prefix
31
32    def GetInstance(self, evaluation_score_class):
33        """Creates an EvaluationScore instance given a class object.
34
35    Args:
36      evaluation_score_class: EvaluationScore class object (not an instance).
37
38    Returns:
39      An EvaluationScore instance.
40    """
41        if self._score_filename_prefix is None:
42            raise exceptions.InitializationException(
43                'The score file name prefix for evaluation score workers is not set'
44            )
45        logging.debug('factory producing a %s evaluation score',
46                      evaluation_score_class)
47
48        if evaluation_score_class == eval_scores.PolqaScore:
49            return eval_scores.PolqaScore(self._score_filename_prefix,
50                                          self._polqa_tool_bin_path)
51        elif evaluation_score_class == eval_scores.EchoMetric:
52            return eval_scores.EchoMetric(self._score_filename_prefix,
53                                          self._echo_metric_tool_bin_path)
54        else:
55            return evaluation_score_class(self._score_filename_prefix)
56