|
10 | 10 | "# The following libraries have already been included in the jupyter image: see here demos/signal-processing/Dockerfile-jupyter\n",
|
11 | 11 | "# These are just left in as examples to show how other libraries can be added.\n",
|
12 | 12 | "#!pip install psycopg2-binary\n",
|
13 |
| - "#!pip install -U tsfresh\n", |
14 | 13 | "#!pip install alibi-detect"
|
15 | 14 | ]
|
16 | 15 | },
|
|
103 | 102 | "while True:\n",
|
104 | 103 | " clear_output(wait=True)\n",
|
105 | 104 | " display('Iteration: '+str(i))\n",
|
106 |
| - " \n", |
| 105 | + "\n", |
107 | 106 | " sql = f\"\"\"\\\n",
|
108 | 107 | " SELECT time, {', '.join(cols)}\n",
|
109 |
| - " from conditions \n", |
| 108 | + " from conditions\n", |
110 | 109 | " where (timestamp '{last_time}' = timestamp '1970-01-01' or time > timestamp '{last_time}') and time < now()\n",
|
111 |
| - " order by time asc \n", |
| 110 | + " order by time asc\n", |
112 | 111 | " limit 1000\n",
|
113 | 112 | " \"\"\"\n",
|
114 |
| - " \n", |
| 113 | + "\n", |
115 | 114 | " df = pd.read_sql_query(sql, engine)\n",
|
116 | 115 | " df_scores = df[['time']].copy()\n",
|
117 |
| - " \n", |
| 116 | + "\n", |
118 | 117 | " od = SpectralResidual(\n",
|
119 | 118 | " threshold=1.,\n",
|
120 | 119 | " window_amp=20,\n",
|
|
125 | 124 | " n_est_points=10,\n",
|
126 | 125 | " n_grad_points=5\n",
|
127 | 126 | " )\n",
|
128 |
| - " \n", |
| 127 | + "\n", |
129 | 128 | " for col in cols:\n",
|
130 | 129 | " result = od.predict(\n",
|
131 | 130 | " df[col].to_numpy(),\n",
|
132 | 131 | " t=None,\n",
|
133 | 132 | " return_instance_score=True\n",
|
134 | 133 | " )\n",
|
135 | 134 | " df_scores[col+'_score'] = result['data']['instance_score'].tolist()\n",
|
136 |
| - " \n", |
| 135 | + "\n", |
137 | 136 | " df_scores.to_sql('scores_sr', engine, index=False, if_exists='append')\n",
|
138 |
| - " \n", |
| 137 | + "\n", |
139 | 138 | " # get last timestamp to use for next offset\n",
|
140 | 139 | " last_time = pd.to_datetime(df.time.tail(1).values[0]).strftime('%Y-%m-%d %H:%M:%S.%f %Z')\n",
|
141 | 140 | " print(f'Next offset: {last_time}, fetched: {df_scores.r1_score.size}')\n",
|
142 |
| - " \n", |
| 141 | + "\n", |
143 | 142 | " time.sleep(12)\n",
|
144 | 143 | " i += 1"
|
145 | 144 | ]
|
|
0 commit comments