Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
FedericoCeratto committed May 11, 2023
1 parent 212d2e9 commit 8bc8413
Show file tree
Hide file tree
Showing 2 changed files with 384 additions and 35 deletions.
76 changes: 41 additions & 35 deletions detector/detector/detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ def rebuild_status(click, start_date, end_date, services) -> None:
# If there are changes we then extract the whole history for each changed
# TCAI in rebuild_feeds.


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

# Stability should grow slowly when accessible_perc is constant over time
# but drop quickly if accessible_perc changes a lot
# Stability moves slowly towards 1 when accessible_perc is constant over
# time but drop quickly towards 0 when accessible_perc changes a lot.
# It is later on used to decide when we are confident enough to make
# statements on BLOCKED/OK status. It is also immediately set to 0 when we
# detect a blocking change event to mitigate flapping.
s_def = 0.7 # default stability
stability = np.cos(3.14 / 2 * delta)
m["stab_insta"] = stability

tau = 0.99
good = stability * (1 - tau) + m.stability.fillna(s_def) * tau
stability_thr = 0.8 # threshold to consider a TCAI stable
gtau = 0.99 # moving average tau for
btau = 0.7

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

thr = 0.8
s = stability >= thr
# m[s]["stability"] = good[s]
m.loc[s, "stability"] = good[s]
s = stability < thr
m.loc[s, "stability"] = bad[s]
bad = stability * (1 - btau) + m.stability.fillna(s_def) * btau
bstable = stability < stability_thr
m.loc[bstable, "stability"] = bad[bstable]

m.status = m.status.fillna("UNKNOWN")
m.old_status = m.status.fillna("UNKNOWN")
Expand Down Expand Up @@ -688,23 +690,27 @@ def process_data(blocking_status, new):
# moving average on cnt
m["cnt"] = mavg_cnt

assert sorted(m.columns) == [
"accessible_perc",
"change",
"cnt",
"confirmed_perc",
"input",
"input_ap",
"input_cnt",
"old_status",
"probe_asn",
"probe_cc",
"pure_anomaly_perc",
"stab_insta",
"stability",
"status",
"test_name",
] or True, sorted(m.columns)
assert (
sorted(m.columns)
== [
"accessible_perc",
"change",
"cnt",
"confirmed_perc",
"input",
"input_ap",
"input_cnt",
"old_status",
"probe_asn",
"probe_cc",
"pure_anomaly_perc",
"stab_insta",
"stability",
"status",
"test_name",
]
or True
), sorted(m.columns)
return m, events


Expand Down Expand Up @@ -780,8 +786,7 @@ def load_blocking_status_df(click):


def reprocess_data_from_df(idf, debug=False):
"""Reprocess data using Pandas
Used for testing/tuning
"""Reprocess data using Pandas. Used primarily for testing.
"""
status = pd.DataFrame(
columns=[
Expand Down Expand Up @@ -832,6 +837,7 @@ def reprocess_data_from_df(idf, debug=False):
events = pd.concat(events_tmp)
else:
events = pd.DataFrame()
print("DONE")
return events, status, status_history


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

# create_tables()
# FIXME: configure services
# TODO: configure services
services = {
"Facebook": ["https://www.facebook.com/"],
"Twitter": ["https://twitter.com/"],
Expand Down
Loading

0 comments on commit 8bc8413

Please sign in to comment.