(self, tool_id: str, violations: Collection[Violation])
return ToolHits(tool_id, top)
Collects top hits for a single tool.
Collects top hits for a single tool.
Collects top hits for a single tool .
def _tool_hits(self, tool_id: str, violations: Collection[Violation]) -> ToolHits:
        """
        Collects top hits for a single tool.
        """
        keyfunc = lambda v: v.check_id  # noqa
        sorted_violations = sorted(violations, key=keyfunc)
        counts = sorted(
            (
                Hit(check_id.strip(), next(vv).link, 1 + sum(1 for _ in vv))
                for check_id, vv in itertools.groupby(sorted_violations, keyfunc)
            ),
            key=(lambda hit: hit.count),
            reverse=True,
        )
        top = counts[0 : self._max_bars_per_tool()]
        n_top = sum(h.count for h in top)

        # Add remaining hits as "Other" if more hits than max_bars_per_tool
        if len(counts) > len(top):
            top.append(Hit(Histo.OTHER, None, len(violations) - n_top))

        return ToolHits(tool_id, top)
def _tool_hits ( self , tool_id : str , violations : Collection [ Violation ] ) -> ToolHits : keyfunc = lambda v : v . check_id # noqa sorted_violations = sorted ( violations , key = keyfunc ) counts = sorted ( ( Hit ( check_id . strip ( ) , next ( vv ) . link , 1 + sum ( 1 for _ in vv ) ) for check_id , vv in itertools . groupby ( sorted_violations , keyfunc ) ) , key = ( lambda hit : hit . count ) , reverse = True , ) top = counts [ 0 : self . _max_bars_per_tool ( ) ] n_top = sum ( h . count for h in top ) # Add remaining hits as "Other" if more hits than max_bars_per_tool if len ( counts ) > len ( top ) : top . append ( Hit ( Histo . OTHER , None , len ( violations ) - n_top ) ) return ToolHits ( tool_id , top )