| Total Complexity | 5 | 
| Total Lines | 43 | 
| Duplicated Lines | 0 % | 
| Changes | 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  | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 9 | |||
| 10 | from mandos.model.hits import AbstractHit, HitFrame, Pair  | 
            ||
| 11 | |||
| 12 | SimilarityDf = TypedDfs.typed("DistanceDf").symmetric().build() | 
            ||
| 13 | |||
| 14 | |||
| 15 | class AnalysisUtils:  | 
            ||
| 16 | @classmethod  | 
            ||
| 17 | def elle(cls, x: float) -> float:  | 
            ||
| 18 | return math.log10(1 + x)  | 
            ||
| 19 | |||
| 20 | @classmethod  | 
            ||
| 21 | def hit_multidict(cls, hits: Sequence[AbstractHit], key: str):  | 
            ||
| 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]  | 
            ||
| 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 |