Skip to content

Commit 8bc8413

Browse files
WIP
1 parent 212d2e9 commit 8bc8413

File tree

2 files changed

+384
-35
lines changed

2 files changed

+384
-35
lines changed

detector/detector/detector.py

+41-35
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ def rebuild_status(click, start_date, end_date, services) -> None:
357357
# If there are changes we then extract the whole history for each changed
358358
# TCAI in rebuild_feeds.
359359

360+
360361
def run_detection_sql(start_date, end_date, services) -> None:
361362
if not conf.reprocess:
362363
log.info(f"Running detection from {start_date} to {end_date}")
@@ -633,24 +634,25 @@ def process_data(blocking_status, new):
633634
+ m.accessible_perc_BS * nu
634635
)
635636

636-
# Stability should grow slowly when accessible_perc is constant over time
637-
# but drop quickly if accessible_perc changes a lot
637+
# Stability moves slowly towards 1 when accessible_perc is constant over
638+
# time but drop quickly towards 0 when accessible_perc changes a lot.
639+
# It is later on used to decide when we are confident enough to make
640+
# statements on BLOCKED/OK status. It is also immediately set to 0 when we
641+
# detect a blocking change event to mitigate flapping.
638642
s_def = 0.7 # default stability
639-
stability = np.cos(3.14 / 2 * delta)
640-
m["stab_insta"] = stability
641-
642-
tau = 0.99
643-
good = stability * (1 - tau) + m.stability.fillna(s_def) * tau
643+
stability_thr = 0.8 # threshold to consider a TCAI stable
644+
gtau = 0.99 # moving average tau for
645+
btau = 0.7
644646

645-
tau = 0.7
646-
bad = stability * (1 - tau) + m.stability.fillna(s_def) * tau
647+
stability = np.cos(3.14 / 2 * delta)
648+
m["stab_insta"] = stability # used for charting
649+
good = stability * (1 - gtau) + m.stability.fillna(s_def) * gtau
650+
gstable = stability >= stability_thr
651+
m.loc[gstable, "stability"] = good[gstable]
647652

648-
thr = 0.8
649-
s = stability >= thr
650-
# m[s]["stability"] = good[s]
651-
m.loc[s, "stability"] = good[s]
652-
s = stability < thr
653-
m.loc[s, "stability"] = bad[s]
653+
bad = stability * (1 - btau) + m.stability.fillna(s_def) * btau
654+
bstable = stability < stability_thr
655+
m.loc[bstable, "stability"] = bad[bstable]
654656

655657
m.status = m.status.fillna("UNKNOWN")
656658
m.old_status = m.status.fillna("UNKNOWN")
@@ -688,23 +690,27 @@ def process_data(blocking_status, new):
688690
# moving average on cnt
689691
m["cnt"] = mavg_cnt
690692

691-
assert sorted(m.columns) == [
692-
"accessible_perc",
693-
"change",
694-
"cnt",
695-
"confirmed_perc",
696-
"input",
697-
"input_ap",
698-
"input_cnt",
699-
"old_status",
700-
"probe_asn",
701-
"probe_cc",
702-
"pure_anomaly_perc",
703-
"stab_insta",
704-
"stability",
705-
"status",
706-
"test_name",
707-
] or True, sorted(m.columns)
693+
assert (
694+
sorted(m.columns)
695+
== [
696+
"accessible_perc",
697+
"change",
698+
"cnt",
699+
"confirmed_perc",
700+
"input",
701+
"input_ap",
702+
"input_cnt",
703+
"old_status",
704+
"probe_asn",
705+
"probe_cc",
706+
"pure_anomaly_perc",
707+
"stab_insta",
708+
"stability",
709+
"status",
710+
"test_name",
711+
]
712+
or True
713+
), sorted(m.columns)
708714
return m, events
709715

710716

@@ -780,8 +786,7 @@ def load_blocking_status_df(click):
780786

781787

782788
def reprocess_data_from_df(idf, debug=False):
783-
"""Reprocess data using Pandas
784-
Used for testing/tuning
789+
"""Reprocess data using Pandas. Used primarily for testing.
785790
"""
786791
status = pd.DataFrame(
787792
columns=[
@@ -832,6 +837,7 @@ def reprocess_data_from_df(idf, debug=False):
832837
events = pd.concat(events_tmp)
833838
else:
834839
events = pd.DataFrame()
840+
print("DONE")
835841
return events, status, status_history
836842

837843

@@ -844,7 +850,7 @@ def main():
844850
click = Clickhouse.from_url(conf.db_uri) # settings={"use_numpy":True})
845851

846852
# create_tables()
847-
# FIXME: configure services
853+
# TODO: configure services
848854
services = {
849855
"Facebook": ["https://www.facebook.com/"],
850856
"Twitter": ["https://twitter.com/"],

0 commit comments

Comments
 (0)