Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data time check #189

Merged
merged 2 commits into from
Nov 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions api/ops/tasks/detection/core/detectionTypes/lifetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,13 @@ def lifetimeDetect(df, granularity):
"""
Method to perform anomaly detection on given dataframe
"""
today = dt.datetime.now()
today = dt.datetime.now().replace(minute=0, second=0, microsecond=0, tzinfo=None)
df["ds"] = pd.to_datetime(df["ds"])
df = df.sort_values("ds")
df["ds"] = df["ds"].apply(lambda date: date.isoformat()[:19])
todayISO = today.replace(hour=0, minute=0, second=0, microsecond=0, tzinfo=None).isoformat()[:19]
if granularity == "day":
today = today.replace(hour=0)
todayISO = today.isoformat()[:19]
df = df[df["ds"] < todayISO]
maxVal = df.y.max()
minVal = df.y.min()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ def percentChangeDetect(df, granularity, threshold):
Method to perform anomaly detection on given dataframe using fbProphet
"""
threshold = float(threshold)
today = dt.datetime.now()
today = dt.datetime.now().replace(minute=0, second=0, microsecond=0, tzinfo=None)
df["ds"] = pd.to_datetime(df["ds"])
df = df.sort_values("ds")
df["ds"] = df["ds"].apply(lambda date: date.isoformat()[:19])
todayISO = today.replace(hour=0, minute=0, second=0, microsecond=0, tzinfo=None).isoformat()[:19]
if granularity == "day":
today = today.replace(hour=0)
todayISO = today.isoformat()[:19]
df = df[df["ds"] < todayISO]
df["percentageChange"] = 100 * (df.y - df.y.shift(1)) / df.y.shift(1)
df["anomaly"] = (abs(df["percentageChange"]) > threshold) * 14 + 1
Expand Down
8 changes: 4 additions & 4 deletions api/ops/tasks/detection/core/detectionTypes/prophet.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ def prophetDetect(df, granularity, iterations=None):
"""
Method to perform anomaly detection on given dataframe using fbProphet
"""
today = dt.datetime.now()
today = dt.datetime.now().replace(minute=0, second=0, microsecond=0, tzinfo=None)
df["ds"] = pd.to_datetime(df["ds"])
df["ds"] = df["ds"].apply(lambda date: date.isoformat()[:19])
todayISO = today.replace(
hour=0, minute=0, second=0, microsecond=0, tzinfo=None
).isoformat()[:19]
if granularity == "day":
today = today.replace(hour=0)
todayISO = today.isoformat()[:19]
df = df[df["ds"] < todayISO]
lastActualRow = df[-1:]
lastISO = df.iloc[-1]["ds"]
Expand Down
6 changes: 4 additions & 2 deletions api/ops/tasks/detection/core/detectionTypes/valueThreshold.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ def valueThresholdDetect(df, granularity, operator, value1, value2):
"between": '((df["y"] >= lowerVal) & (df["y"] <= upperVal)) * 14 + 1',
"!between": '((df["y"] < lowerVal) | (df["y"] > upperVal)) * 14 + 1'
}
today = dt.datetime.now()
today = dt.datetime.now().replace(minute=0, second=0, microsecond=0, tzinfo=None)
df["ds"] = pd.to_datetime(df["ds"])
df = df.sort_values("ds")
df["ds"] = df["ds"].apply(lambda date: date.isoformat()[:19])
todayISO = today.replace(hour=0, minute=0, second=0, microsecond=0, tzinfo=None).isoformat()[:19]
if granularity == "day":
today = today.replace(hour=0)
todayISO = today.isoformat()[:19]
df = df[df["ds"] < todayISO]
df["anomaly"] = eval(operationDict[operator])
anomalyLatest = checkLatestAnomaly(df, operationStrDict[operator])
Expand Down