Пример #1
0
    def is_conform(self, cdr):
        # FIXME: pattern should no check conforming, it's another task
        day = day_of_week(cdr.start)
        freq = self.get_pattern()[day][time_of_day(cdr.start)//60//60]

        current = np.roll(self.current, 1)
        current[0] = cdr.start
        diffs = np.array([e[0]-e[1] for e in zip(current, current[1:])])
        current_freq = (60*60)/moving_average_exponential(diffs, ALPHA_FREQ)

        limits = poisson_interval(freq, 1-0.997)  # float

        if not (current_freq <= max(1.0, limits[1]*ALARM_THRESHOLD)):
            print(freq, current_freq, max(1, limits[1]*ALARM_THRESHOLD), )
        return current_freq <= max(1.0, limits[1]*ALARM_THRESHOLD)
Пример #2
0
    def maintain(self, cdr):
        """
        Maintaining should be continuous
        Calls have to be sorted by cdr.start time
        """
        time = time_of_day(cdr.start)//(TIME_DISCRETIZATION//APPROX_WINDOW)
        day = day_of_week(cdr.start)
        if self.last_day_of_week != day and day == 0:  # week switched
            self.data = np.roll(self.data, 1, axis=0)
            self.data[0] = self.extract_week_history()
            self.week_history = np.zeros(shape=(7, (24*60*60)//(TIME_DISCRETIZATION//APPROX_WINDOW)))
            self.weeks += 1
        self.last_day_of_week = day

        self.current = np.roll(self.current, 1)  # for instantaneous frequency
        self.current[0] = cdr.start

        # new freq calc
        current = np.roll(self.current, 1)
        current[0] = cdr.start
        diffs = np.array([e[0]-e[1] for e in zip(current, current[1:])])
        current_freq = (60*60)/moving_average_exponential(diffs, ALPHA_FREQ)
        self.week_history[day, time] = max(self.week_history[day, time], current_freq)
Пример #3
0
 def get_pattern(self):
     return moving_average_exponential(self.data, ALPHA_WEEKS)