Passed
Push — dependabot/pip/sphinx-copybutt... ( c72176 )
by
unknown
18:24 queued 16:24
created

mandos.analysis.AnalysisUtils.hit_multidict()   A

Complexity

Conditions 2

Size

Total Lines 6
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nop 3
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
"""
2
Calculations.
3
"""
4
import math
5
from collections import defaultdict
6
from typing import Collection, Dict, Sequence, Set, Tuple
7
8
from typeddfs import TypedDfs
0 ignored issues
show
introduced by
Unable to import 'typeddfs'
Loading history...
9
10
from mandos.model.hits import AbstractHit, HitFrame, Pair
11
12
SimilarityDf = TypedDfs.typed("DistanceDf").symmetric().build()
13
14
15
class AnalysisUtils:
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
16
    @classmethod
17
    def elle(cls, x: float) -> float:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
Coding Style Naming introduced by
Argument name "x" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
18
        return math.log10(1 + x)
19
20
    @classmethod
21
    def hit_multidict(cls, hits: Sequence[AbstractHit], key: str):
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
22
        x_to_hits = defaultdict(list)
23
        for hit in hits:
24
            x_to_hits[getattr(hit, key)].append(hit)
25
        return x_to_hits
26
27
    @classmethod
28
    def weights_of_pairs(
29
        cls, hits1: Collection[AbstractHit], hits2: Collection[AbstractHit]
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
30
    ) -> Dict[Pair, Tuple[float, float]]:
31
        """
32
        Calculates the sum of
33
        """
34
        union = {h.to_pair for h in hits1}.union({h.to_pair for h in hits2})
35
        return {p: (cls._score(hits1, p), cls._score(hits2, p)) for p in union}
36
37
    @classmethod
38
    def _score(cls, hits: Collection[AbstractHit], pair: Pair) -> int:
39
        return sum([h.value for h in hits if h.to_pair == pair])
40
41
42
__all__ = ["AnalysisUtils", "SimilarityDf"]
43