<commit_before># -*- coding: utf8 -*-
"""
    This is part of shot detector.
    Produced by w495 at 2017.05.04 04:18:27
"""

from __future__ import (absolute_import,
                        division,
                        print_function,
                        unicode_literals)

import logging
from builtins import range

from shot_detector.filters import (
    ShiftSWFilter,
    DelayFilter,
    NormFilter,
    BaseSWFilter,
)
from shot_detector.plotters.event.base import (
    BaseEventPlotter,
    FilterDescription,
    PlotOptions
)
from shot_detector.utils.log_meta import log_method_call_with


class RescalingVoteEventPlotter(BaseEventPlotter):
    """
        ...
    """
    __logger = logging.getLogger(__name__)

    THRESHOLD = 0.8
    SLIDING_WINDOW_SIZE = 20

    NUMBER_OF_VOTERS = 16

    @log_method_call_with(logging.WARN)
    def seq_filters(self):
        """
        
        :return: 
        """
        delay = DelayFilter()
        norm = NormFilter()
        shift = ShiftSWFilter()
        original = delay(0)
        diff = original - shift
        # noinspection PyUnusedLocal
        threshold = original > self.THRESHOLD
        #
        sad_filter = norm(l=1) | diff | abs
        sw = BaseSWFilter(
            size=self.SLIDING_WINDOW_SIZE,
            min_size=2
        )
        sw_max = sw | max
        sw_min = sw | min
        sw_norm = (original - sw_min) / (sw_max - sw_min)

        # sw_norm = NormSWFilter(min_size=2)

        sw_norm_seq = (sw_norm(size=25 * (i + 1)) for i in
                       range(self.NUMBER_OF_VOTERS))

        # noinspection PyUnusedLocal
        sw_vote_norm = sum(sw_norm_seq) / self.NUMBER_OF_VOTERS

        return (
            FilterDescription(
                # Original signal.
                name='$F_{L_1} = ||F_{t}||_{L_1}$',
                plot_options=PlotOptions(
                    style='-',
                    color='gray',
                    width=3.0,
                ),
                formula=norm(l=1),
            ),

            FilterDescription(
                name='$D_{{\,{size},t}} '
                     '= sw\_norm_{{\,{size} }} D_{{t}}$'.format(
                    size=400
                ),
                plot_options=PlotOptions(
                    style='-',
                    color='red',
                    width=1.0,
                ),
                formula=sad_filter | sw_norm(s=400)
            ),

            FilterDescription(
                name='$D_{{\,{size},t}}'
                     '= sw\_norm_{{\,{size} }} D_{{t}}$'.format(
                    size=40
                ),
                plot_options=PlotOptions(
                    style='-',
                    color='orange',
                    width=1.0,
                ),
                formula=sad_filter | sw_norm(size=40)
            ),

            FilterDescription(
                name='$D_{{\,{size},t}} '
                     '= sw\_norm_{{\,{size} }} D_{{t}}$'.format(
                    size=200
                ),
                plot_options=PlotOptions(
                    style='-',
                    color='orange',
                    width=1.0,
                ),
                formula=sad_filter | sw_norm(s=200)
            ),

            FilterDescription(
                name='$D_{{\,{size},t}} '
                     '= sw\_norm_{{\,{size} }} D_{{t}}$'.format(
                    size=300
                ),
                plot_options=PlotOptions(
                    style='-',
                    color='violet',
                    width=1.0,
                ),
                formula=sad_filter | sw_norm(s=300)
            ),

            FilterDescription(
                # Sum of absolute difference filter.
                name='$D_{t} = ||F_{t} - F_{t-1}||_{L_1}$',
                plot_options=PlotOptions(
                    style='-',
                    color='blue',
                    width=2.0,
                ),
                formula=sad_filter
            ),

            # FilterDescription(
            #     name='$D_{{\,{size},t}} '
            #          '= sw\_norm_{{\,{size} }} D_{{t}}$'.format(
            #         size=100
            #     ),
            #     plot_options=PlotOptions(
            #         style='-',
            #         color='green',
            #         width=1.0,
            #     ),
            #     filter=sad_filter | sw_vote_norm
            # ),

            # FilterDescription(
            #     # The threshold value.
            #     name='$T_{{const}} = {} \in (0; 1)$'.format(
            #         self.THRESHOLD),
            #     plot_options=PlotOptions(
            #         style='-',
            #         color='black',
            #         width=2.0,
            #     ),
            #     filter=norm(l=1) | self.THRESHOLD,
            # ),
        )<commit_msg>fix due to code inspection (2)<commit_after># -*- coding: utf8 -*-
"""
    This is part of shot detector.
    Produced by w495 at 2017.05.04 04:18:27
"""

from __future__ import (absolute_import,
                        division,
                        print_function,
                        unicode_literals)

import logging
from builtins import range

from shot_detector.filters import (
    ShiftSWFilter,
    DelayFilter,
    NormFilter,
    BaseSWFilter,
)
from shot_detector.plotters.event.base import (
    BaseEventPlotter,
    FilterDescription,
    PlotOptions
)
from shot_detector.utils.log_meta import log_method_call_with


class RescalingVoteEventPlotter(BaseEventPlotter):
    """
        ...
    """
    __logger = logging.getLogger(__name__)

    THRESHOLD = 0.8
    SLIDING_WINDOW_SIZE = 20

    NUMBER_OF_VOTERS = 16

    @log_method_call_with(logging.WARN)
    def seq_filters(self):
        """
        
        :return: 
        """
        delay = DelayFilter()
        norm = NormFilter()
        shift = ShiftSWFilter()
        original = delay(0)
        diff = original - shift
        # noinspection PyUnusedLocal
        threshold = original > self.THRESHOLD
        #
        sad_filter = norm(l=1) | diff | abs
        sw = BaseSWFilter(
            size=self.SLIDING_WINDOW_SIZE,
            min_size=2
        )
        sw_max = sw | max
        sw_min = sw | min
        sw_norm = (original - sw_min) / (sw_max - sw_min)

        # sw_norm = NormSWFilter(min_size=2)

        sw_norm_seq = (sw_norm(size=25 * (i + 1)) for i in
                       range(self.NUMBER_OF_VOTERS))

        # noinspection PyUnusedLocal
        sw_vote_norm = sum(sw_norm_seq) / self.NUMBER_OF_VOTERS

        return (
            FilterDescription(
                # Original signal.
                name='$F_{L_1} = ||F_{t}||_{L_1}$',
                plot_options=PlotOptions(
                    style='-',
                    color='gray',
                    width=3.0,
                ),
                formula=norm(l=1),
            ),

            FilterDescription(
                name=(
                    '$D_{{\,{size},t}} '
                    '= sw\_norm_{{\,{size} }} D_{{t}}$'.format(
                        size=400
                    )
                ),
                plot_options=PlotOptions(
                    style='-',
                    color='red',
                    width=1.0,
                ),
                formula=sad_filter | sw_norm(s=400)
            ),

            FilterDescription(
                name=(
                    '$D_{{\,{size},t}}'
                    '= sw\_norm_{{\,{size} }} D_{{t}}$'.format(
                        size=40
                    )
                ),
                plot_options=PlotOptions(
                    style='-',
                    color='orange',
                    width=1.0,
                ),
                formula=sad_filter | sw_norm(size=40)
            ),

            FilterDescription(
                name=(
                    '$D_{{\,{size},t}} '
                    '= sw\_norm_{{\,{size} }} D_{{t}}$'.format(
                        size=200
                    )
                ),
                plot_options=PlotOptions(
                    style='-',
                    color='orange',
                    width=1.0,
                ),
                formula=sad_filter | sw_norm(s=200)
            ),

            FilterDescription(
                name=(
                    '$D_{{\,{size},t}} '
                    '= sw\_norm_{{\,{size} }} D_{{t}}$'.format(
                        size=300
                    )
                ),
                plot_options=PlotOptions(
                    style='-',
                    color='violet',
                    width=1.0,
                ),
                formula=sad_filter | sw_norm(s=300)
            ),

            FilterDescription(
                # Sum of absolute difference filter.
                name='$D_{t} = ||F_{t} - F_{t-1}||_{L_1}$',
                plot_options=PlotOptions(
                    style='-',
                    color='blue',
                    width=2.0,
                ),
                formula=sad_filter
            ),
            #
            # FilterDescription(
            #     name=(
            #         '$D_{{\,{size},t}} '
            #         '= sw\_norm_{{\,{size} }} D_{{t}}$'.format(
            #             size=100
            #         )
            #     ),
            #     plot_options=PlotOptions(
            #         style='-',
            #         color='green',
            #         width=1.0,
            #     ),
            #     formula=sad_filter | sw_vote_norm
            # ),
            #
            # FilterDescription(
            #     # The threshold value.
            #     name=(
            #         '$T_{{const}} = {} \in (0; 1)$'.format(
            #             self.THRESHOLD
            #         )
            #     ),
            #     plot_options=PlotOptions(
            #         style='-',
            #         color='black',
            #         width=2.0,
            #     ),
            #     formula=norm(l=1) | self.THRESHOLD,
            # ),
        )
{'fraction_non_alphanumeric': 0.11979525543852741, 'fraction_numerical': 0.015848016537060736, 'mean_word_length': 1.0283489718506689, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2373320', 'n_tokens_mistral': 2994, 'n_tokens_neox': 2677, 'n_words': 419}