def process_domain(registered_domain, updated_domains, now=None): """Update the statistics for all fuzz results for this domain.""" if now is None: now = datetime.datetime.now() updated_domains = set(updated_domains) delta_report = repository.get_delta_report(registered_domain) if delta_report is None: return updated_domains for domain in delta_reports.extract_domains(delta_report): if domain in updated_domains: continue updated = statistics_repository.noise_stat_last_updated(domain) if updated is not None and (now - updated) < FREQUENCY: continue stat = statistics_repository.get_noise_stat(domain) if stat is None: stat = NoiseStatistic(domain, deltas=1) else: stat.increment() stat.update_window() statistics_repository.set_noise_stat(stat) statistics_repository.mark_noise_stat_as_updated(domain) updated_domains.add(domain) return updated_domains
def test_update_when_outside_window(): """Test we move the window once we cross the threshold.""" domain = 'www.example.com' now = datetime.datetime.now() future_date = now + datetime.timedelta(days=31) stat = NoiseStatistic(domain, window_start=now) stat.update_window(now=future_date) assert stat.window_start == now + datetime.timedelta(days=15)
def test_update_when_inside_window(): """Test we don't move the window inside the window_size.""" domain = 'www.example.com' now = datetime.datetime.now() future_date = now + datetime.timedelta(days=25) stat = NoiseStatistic(domain, window_start=now) stat.update_window(now=future_date) assert stat.window_start == now
def test_update_when_outside_window_updates_deltas(): """Test we proportionally update the stats when we move a window.""" domain = 'www.example.com' now = datetime.datetime.now() future_date = now + datetime.timedelta(days=31) stat = NoiseStatistic(domain, deltas=10, window_start=now) stat.update_window(now=future_date) assert stat.deltas == 5 # The update to deltas is proportional to progress past the end of the # window, to highlight this we're pretending the update has ran more than # just 1 day after the window is crossed. stat = NoiseStatistic(domain, deltas=16, window_start=now) future_date = now + datetime.timedelta(days=34) stat.update_window(now=future_date) assert stat.deltas == 8 stat = NoiseStatistic(domain, deltas=24, window_start=now) future_date = now + datetime.timedelta(days=45) stat.update_window(now=future_date) assert stat.deltas == 16
def process_domain(registered_domain, now=None): """Update the statistics for all fuzz results for this domain.""" if now is None: now = datetime.datetime.now() delta_report = repository.get_delta_report(registered_domain) if delta_report is None: return for domain in delta_reports.extract_domains(delta_report): updated = statistics_repository.noise_stat_last_updated(domain) if updated is not None and (now - updated) < FREQUENCY: continue stat = statistics_repository.get_noise_stat(domain) if stat is None: stat = NoiseStatistic(domain, deltas=1) else: stat.increment() stat.update_window() statistics_repository.set_noise_stat(stat) statistics_repository.mark_noise_stat_as_updated(domain)