Skip to content
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
3 changes: 1 addition & 2 deletions demos/signal-processing/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
psycopg2-binary==2.9.9
tsfresh==0.20.1
alibi-detect==0.11.4
alibi-detect==0.11.4
19 changes: 9 additions & 10 deletions stacks/signal-processing/tsdb.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
"# The following libraries have already been included in the jupyter image: see here demos/signal-processing/Dockerfile-jupyter\n",
"# These are just left in as examples to show how other libraries can be added.\n",
"#!pip install psycopg2-binary\n",
"#!pip install -U tsfresh\n",
"#!pip install alibi-detect"
]
},
Expand Down Expand Up @@ -103,18 +102,18 @@
"while True:\n",
" clear_output(wait=True)\n",
" display('Iteration: '+str(i))\n",
" \n",
"\n",
" sql = f\"\"\"\\\n",
" SELECT time, {', '.join(cols)}\n",
" from conditions \n",
" from conditions\n",
" where (timestamp '{last_time}' = timestamp '1970-01-01' or time > timestamp '{last_time}') and time < now()\n",
" order by time asc \n",
" order by time asc\n",
" limit 1000\n",
" \"\"\"\n",
" \n",
"\n",
" df = pd.read_sql_query(sql, engine)\n",
" df_scores = df[['time']].copy()\n",
" \n",
"\n",
" od = SpectralResidual(\n",
" threshold=1.,\n",
" window_amp=20,\n",
Expand All @@ -125,21 +124,21 @@
" n_est_points=10,\n",
" n_grad_points=5\n",
" )\n",
" \n",
"\n",
" for col in cols:\n",
" result = od.predict(\n",
" df[col].to_numpy(),\n",
" t=None,\n",
" return_instance_score=True\n",
" )\n",
" df_scores[col+'_score'] = result['data']['instance_score'].tolist()\n",
" \n",
"\n",
" df_scores.to_sql('scores_sr', engine, index=False, if_exists='append')\n",
" \n",
"\n",
" # get last timestamp to use for next offset\n",
" last_time = pd.to_datetime(df.time.tail(1).values[0]).strftime('%Y-%m-%d %H:%M:%S.%f %Z')\n",
" print(f'Next offset: {last_time}, fetched: {df_scores.r1_score.size}')\n",
" \n",
"\n",
" time.sleep(12)\n",
" i += 1"
]
Expand Down