Beispiel #1
0
 def random_threshold(self):
     day_time = time_of_day(self.time)
     week_day = day_of_week(self.time)
     next = list(dropwhile(lambda m: m[0] <= day_time, self.rates[week_day]))
     if len(next) == 0:
         next_time = 24*60*60
     else:
         next_time = next[0][0]
     return next_time - day_time
Beispiel #2
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)
Beispiel #3
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)
Beispiel #4
0
 def rate(self):
     day_time = time_of_day(self.time)
     week_day = day_of_week(self.time)
     return np.interp(day_time, [x[0] for x in self.rates[week_day]], [x[1] for x in self.rates[week_day]])
Beispiel #5
0
 def rate(self):
     day_time = time_of_day(self.time)
     week_day = day_of_week(self.time)
     return np.interp(day_time, [x[0] for x in self.rates[week_day]],
                      [x[1] for x in self.rates[week_day]])