Skip to content

Commit 9e66e2c

Browse files
committed
TSML: Improve timeseries-anomaly-detection.ipynb notebook
- Use `REFRESH TABLE` to synchronize data - Improve formatting around `CONNECTION_STRING`
1 parent 091ffdc commit 9e66e2c

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

topic/timeseries/timeseries-anomaly-detection.ipynb

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
"In this step, we will create the table and populate it with the dataset from [nab-machine-failure.csv]. If you are using CrateDB Cloud, you can use the [URL import] available in the console, otherwise, use the `COPY FROM` statement used below. You can run it in the console in the Admin UI or you can use [Crash], in this case, we are using SQLAlchemy.\n",
8989
"\n",
9090
"[URL import]: https://cratedb.com/docs/cloud/en/latest/reference/overview.html#import-from-url\n",
91-
"[nab-machine-failure.csv]: https://github.com/crate/cratedb-datasets/raw/main/timeseries/nab-machine-failure.csv\",\n",
91+
"[nab-machine-failure.csv]: https://github.com/crate/cratedb-datasets/raw/main/timeseries/nab-machine-failure.csv\n",
9292
"[Crash]: https://cratedb.com/docs/crate/crash/en/latest/getting-started.html"
9393
]
9494
},
@@ -98,25 +98,22 @@
9898
"metadata": {},
9999
"outputs": [],
100100
"source": [
101-
"# Use this connection string template for CrateDB Cloud Clusters\n",
101+
"# crate://<USER>:<PASSWORD>@<HOST>\n",
102102
"CONNECTION_STRING = os.environ.get(\n",
103103
" \"CRATEDB_CONNECTION_STRING\",\n",
104-
" \"crate://<USER>:<PASSWORD>@<HOST>\",\n",
105-
")\n",
106-
"\n",
107-
"# Use this connection string template for CrateDB running locally\n",
108-
"#CONNECTION_STRING = os.environ.get(\n",
109-
"# \"CRATEDB_CONNECTION_STRING\",\n",
110-
"# \"crate://localhost:4200\",\n",
111-
"# )\n",
104+
" \"crate://localhost:4200\",\n",
105+
" )\n",
112106
"\n",
113107
"engine = sa.create_engine(CONNECTION_STRING, echo=os.environ.get('DEBUG'))\n",
114108
"\n",
115-
"query_create_table = 'CREATE TABLE machine_data (\"timestamp\" TIMESTAMP, \"value\" DOUBLE PRECISION)' \n",
116-
"query_copy_from = \"COPY machine_data FROM 'https://github.com/crate/cratedb-datasets/raw/main/timeseries/nab-machine-failure.csv';\"\n",
109+
"sql_ddl = 'CREATE TABLE machine_data (\"timestamp\" TIMESTAMP, \"value\" DOUBLE PRECISION)'\n",
110+
"sql_load = \"COPY machine_data FROM 'https://github.com/crate/cratedb-datasets/raw/main/timeseries/nab-machine-failure.csv';\"\n",
111+
"sql_refresh = \"REFRESH TABLE machine_data;\"\n",
112+
"\n",
117113
"with engine.connect() as conn:\n",
118-
" conn.execute(sa.text(query_create_table))\n",
119-
" conn.execute(sa.text(query_copy_from))\n"
114+
" conn.execute(sa.text(sql_ddl))\n",
115+
" conn.execute(sa.text(sql_load))\n",
116+
" conn.execute(sa.text(sql_refresh))"
120117
]
121118
},
122119
{

0 commit comments

Comments
 (0)