Beispiel #1
0
def sum_score_aggregator(group_results):
    if not group_results:
        return None, None, 'OK'

    scores = [ScoreValue.deserialize(result['score'])
              for result in group_results.itervalues()]
    max_scores = [ScoreValue.deserialize(result['max_score'])
              for result in group_results.itervalues()]

    score = sum(scores[1:], scores[0])
    max_score = sum(max_scores[1:], max_scores[0])
    status = aggregate_statuses([result['status']
        for result in group_results.itervalues()])

    return score, max_score, status
Beispiel #2
0
def min_group_scorer(test_results):
    """Gets minimal result of all tests inside a test group."""

    scores = [ScoreValue.deserialize(result["score"]) for result in test_results.itervalues()]
    score = min(scores)
    status = aggregate_statuses([result["status"] for result in test_results.itervalues()])
    return score, status
Beispiel #3
0
def sum_score_aggregator(group_results):
    if not group_results:
        return None, None, 'OK'

    scores = [ScoreValue.deserialize(result['score'])
              for result in six.itervalues(group_results)]
    max_scores = [ScoreValue.deserialize(result['max_score'])
              for result in six.itervalues(group_results)]

    # the sum below needs a start value of an appropriate type,
    # the default zero is not suitable
    score = sum(scores[1:], scores[0])
    max_score = sum(max_scores[1:], max_scores[0])
    status = aggregate_statuses([result['status']
        for result in six.itervalues(group_results)])

    return score, max_score, status
Beispiel #4
0
def sum_score_aggregator(group_results):
    if not group_results:
        return None, "OK"

    scores = [ScoreValue.deserialize(result["score"]) for result in group_results.itervalues()]
    score = sum(scores[1:], scores[0])
    status = aggregate_statuses([result["status"] for result in group_results.itervalues()])
    return score, status
Beispiel #5
0
    def to_python(self, value):
        if isinstance(value, ScoreValue):
            return value

        if value is None or value == '':
            return None

        return ScoreValue.deserialize(value)
Beispiel #6
0
def sum_group_scorer(test_results):
    """Adds results of all tests inside a test group."""

    if not test_results:
        return None, None, 'OK'

    scores = [ScoreValue.deserialize(result['score'])
              for result in six.itervalues(test_results)]
    max_scores = [ScoreValue.deserialize(result['max_score'])
              for result in six.itervalues(test_results)]

    score = sum(scores[1:], scores[0])
    max_score = sum(max_scores[1:], max_scores[0])
    status = aggregate_statuses([result['status']
        for result in six.itervalues(test_results)])

    return score, max_score, status
Beispiel #7
0
def min_group_scorer(test_results):
    """Gets minimal result of all tests inside a test group."""

    scores = [ScoreValue.deserialize(result['score'])
              for result in test_results.itervalues()]
    max_scores = [ScoreValue.deserialize(result['max_score'])
              for result in test_results.itervalues()]

    score = min(scores)
    max_score = min(max_scores)
    if max_score != max(max_scores):
        raise UnequalMaxScores("Tests in one group cannot "
                "have different max scores.")

    sorted_results = sorted(test_results.values(), key=itemgetter('order'))
    status = aggregate_statuses([result['status']
        for result in sorted_results])

    return score, max_score, status
Beispiel #8
0
def sum_group_scorer(test_results):
    """Adds results of all tests inside a test group."""

    if not test_results:
        return None, "OK"

    scores = [ScoreValue.deserialize(result["score"]) for result in test_results.itervalues()]
    score = sum(scores[1:], scores[0])
    status = aggregate_statuses([result["status"] for result in test_results.itervalues()])
    return score, status
Beispiel #9
0
def sum_score_aggregator(group_results):
    if not group_results:
        return None, None, 'OK'

    scores = [
        ScoreValue.deserialize(result['score'])
        for result in six.itervalues(group_results)
    ]
    max_scores = [
        ScoreValue.deserialize(result['max_score'])
        for result in six.itervalues(group_results)
    ]

    # the sum below needs a start value of an appropriate type,
    # the default zero is not suitable
    score = sum(scores[1:], scores[0])
    max_score = sum(max_scores[1:], max_scores[0])
    status = aggregate_statuses(
        [result['status'] for result in six.itervalues(group_results)])

    return score, max_score, status
Beispiel #10
0
def sum_score_aggregator(group_results):
    if not group_results:
        return None, 'OK'

    scores = [
        ScoreValue.deserialize(result['score'])
        for result in group_results.itervalues()
    ]
    score = sum(scores[1:], scores[0])
    status = aggregate_statuses(
        [result['status'] for result in group_results.itervalues()])
    return score, status
Beispiel #11
0
def sum_group_scorer(test_results):
    """Adds results of all tests inside a test group."""

    if not test_results:
        return None, None, 'OK'

    scores = [
        ScoreValue.deserialize(result['score'])
        for result in six.itervalues(test_results)
    ]
    max_scores = [
        ScoreValue.deserialize(result['max_score'])
        for result in six.itervalues(test_results)
    ]

    score = sum(scores[1:], scores[0])
    max_score = sum(max_scores[1:], max_scores[0])
    status = aggregate_statuses(
        [result['status'] for result in six.itervalues(test_results)])

    return score, max_score, status
Beispiel #12
0
 def to_python(self, value):
     if value is None:
         return None
     elif isinstance(value, ScoreValue):
         return value
     elif isinstance(value, basestring):
         if value == '':
             return None
         return ScoreValue.deserialize(value)
     else:
         raise ValueError("ScoreField.to_python got neither ScoreValue nor "
                          "string: %r" % (value, ))
Beispiel #13
0
 def to_python(self, value):
     if value is None:
         return None
     elif isinstance(value, ScoreValue):
         return value
     elif isinstance(value, basestring):
         if value == '':
             return None
         return ScoreValue.deserialize(value)
     else:
         raise ValueError("ScoreField.to_python got neither ScoreValue nor "
                 "string: %r" % (value,))
Beispiel #14
0
    def get_prep_value(self, value):
        if value is None:
            return None

        # The field might have been filled in code with some strange data
        # we deserialize it to make sure it's in proper format
        if isinstance(value, six.string_types):
            value = ScoreValue.deserialize(value)

        if isinstance(value, ScoreValue):
            return value.serialize()
        else:
            raise ValidationError('Invalid score value object type')
Beispiel #15
0
    def get_prep_value(self, value):
        if value is None:
            return None

        # The field might have been filled in code with some strange data
        # we deserialize it to make sure it's in proper format
        if isinstance(value, six.string_types):
            value = ScoreValue.deserialize(value)

        if isinstance(value, ScoreValue):
            return value.serialize()
        else:
            raise ValidationError('Invalid score value object type')
Beispiel #16
0
def min_group_scorer(test_results):
    """Gets minimal result of all tests inside a test group."""

    scores = [
        ScoreValue.deserialize(result['score'])
        for result in test_results.itervalues()
    ]
    max_scores = [
        ScoreValue.deserialize(result['max_score'])
        for result in test_results.itervalues()
    ]

    score = min(scores)
    max_score = min(max_scores)
    if max_score != max(max_scores):
        raise UnequalMaxScores("Tests in one group cannot "
                               "have different max scores.")

    sorted_results = sorted(test_results.values(), key=itemgetter('order'))
    status = aggregate_statuses(
        [result['status'] for result in sorted_results])

    return score, max_score, status
Beispiel #17
0
    def from_db_value(self, value, expression, connection, context):
        if value is None or value == '':
            return None

        return ScoreValue.deserialize(value)
Beispiel #18
0
    def from_db_value(self, value, expression, connection, context):
        if value is None or value == '':
            return None

        return ScoreValue.deserialize(value)