Browse Source

Influxdb Read DB Code

master
flashlan 3 years ago
parent
commit
393f8a2644
  1. 140
      compareDBs.ipynb

140
compareDBs.ipynb

@ -101,7 +101,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 42, "execution_count": 94,
"id": "968403e3-2e5e-4834-b969-be4600e2963a", "id": "968403e3-2e5e-4834-b969-be4600e2963a",
"metadata": { "metadata": {
"tags": [] "tags": []
@ -306,7 +306,6 @@
"cell_type": "markdown", "cell_type": "markdown",
"id": "4a8d5703-9bc9-4d38-83ff-457159304d58", "id": "4a8d5703-9bc9-4d38-83ff-457159304d58",
"metadata": { "metadata": {
"jp-MarkdownHeadingCollapsed": true,
"tags": [] "tags": []
}, },
"source": [ "source": [
@ -611,7 +610,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 54, "execution_count": 95,
"id": "c3e7ebfd-76f1-4ac4-9833-312eb1a531af", "id": "c3e7ebfd-76f1-4ac4-9833-312eb1a531af",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
@ -643,33 +642,38 @@
" )\n", " )\n",
" writer.__del__()\n", " writer.__del__()\n",
" client.__del__()\n", " client.__del__()\n",
" return 0" " return 0\n",
"\n",
"\n",
"def influxdRead(org=InfluxDBUrl, query=query):\n",
" client = influxdbConnect()\n",
" InfluxDf = client.query_api().query_data_frame(org=\"librography\", query=query)\n",
" # display(InfluxDf.head())\n",
" return InfluxDf"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 55, "execution_count": 96,
"id": "e05266b8-ff32-462c-b059-325a40a53d25", "id": "e05266b8-ff32-462c-b059-325a40a53d25",
"metadata": { "metadata": {
"tags": [] "tags": []
}, },
"outputs": [], "outputs": [],
"source": [ "source": [
"client = influxdbLoadCsv()" "dafr = influxdbLoadCsv()\n",
"# dafr.head()"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 51, "execution_count": null,
"id": "71300e86-2e39-4c71-8b0c-6d6e21728e48", "id": "95191283-f11e-456f-8395-36981ab1ac51",
"metadata": { "metadata": {},
"tags": []
},
"outputs": [], "outputs": [],
"source": [ "source": [
"# write from db and benchmark time\n",
"start = timeit.default_timer()\n", "start = timeit.default_timer()\n",
"influxdbWriteCsv(df, InfluxDBBucket)\n", "influxdbWriteCsv(dafr, InfluxDBBucket)\n",
"# dfIdw = cHouseQueryDf(dbname)\n", "# dfIdw = cHouseQueryDf(dbname)\n",
"stop = timeit.default_timer()\n", "stop = timeit.default_timer()\n",
"influxdb_write_execution_time = stop - start" "influxdb_write_execution_time = stop - start"
@ -677,17 +681,15 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 52, "execution_count": 119,
"id": "c8515d8e-2f34-4a2f-b9be-3faefef2d0ca", "id": "3e5bb029-4988-4692-bc5f-9a6f7fcc2159",
"metadata": { "metadata": {},
"tags": []
},
"outputs": [ "outputs": [
{ {
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"89.17334011999992\n" "161.51344409900048\n"
] ]
} }
], ],
@ -697,7 +699,7 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 60, "execution_count": 113,
"id": "ecd217ab-0e16-40a6-9b92-9212b9bb20e9", "id": "ecd217ab-0e16-40a6-9b92-9212b9bb20e9",
"metadata": { "metadata": {
"tags": [] "tags": []
@ -705,10 +707,9 @@
"outputs": [], "outputs": [],
"source": [ "source": [
"query = \"\"\"\n", "query = \"\"\"\n",
"from(bucket: \"system\")\n", "from(bucket: \"EURUSDtest\")\n",
"|> range(start:2023-03-03T18:14:30Z, stop: now())\n", "|> range(start:2023-03-03T18:14:30Z, stop: now())\n",
"|> filter(fn: (r) => r._measurement == \"id\")\n", "|> filter(fn: (r) => r._measurement == \"id\")\n",
"|> filter(fn: (r) => r._field == \"volume\")\n",
"|> pivot(rowKey:[\"_time\"], columnKey: [\"_field\"], valueColumn: \"_value\")\"\"\"\n", "|> pivot(rowKey:[\"_time\"], columnKey: [\"_field\"], valueColumn: \"_value\")\"\"\"\n",
"# |> filter(fn: (r) => r._field == \"volume\")\n", "# |> filter(fn: (r) => r._field == \"volume\")\n",
"# |> filter(fn: (r) => r.cpu == \"cpu-total\")" "# |> filter(fn: (r) => r.cpu == \"cpu-total\")"
@ -716,49 +717,36 @@
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": 58, "execution_count": null,
"id": "09028588-e450-491c-8b84-246807dad9c3", "id": "850c6921-5e1c-417a-bea6-ea18be642008",
"metadata": { "metadata": {},
"tags": []
},
"outputs": [], "outputs": [],
"source": [ "source": [
"# 2021-01-01T00:00:00Z\n", "# read from db and benchmark time\n",
"# 2023-03-03T18:14:30Z\n", "start = timeit.default_timer()\n",
"\n", "dfIdr = cHouseQueryDf(dbname)\n",
"\n", "stop = timeit.default_timer()\n",
"def influxdRead(org=InfluxDBUrl, query=query):\n", "influxdb_read_execution_time = stop - start"
" client = influxdbConnect()\n",
" InfluxDf = client.query_api().query_data_frame(org=org, query=query)\n",
" display(InfluxDf.head())\n",
" return InfluxDf"
] ]
}, },
{ {
"cell_type": "code", "cell_type": "code",
"execution_count": null, "execution_count": 118,
"id": "8f28e32f-59d3-427b-8fe9-3d8bdf0ab675", "id": "3ee3c0dd-cb70-4124-a0fb-db8dd2c134c0",
"metadata": { "metadata": {
"tags": [] "tags": []
}, },
"outputs": [], "outputs": [
"source": [ {
"dfIdb = influxdRead()\n", "name": "stdout",
"dfIdb.head()" "output_type": "stream",
] "text": [
}, "183.94615754100232\n"
{ ]
"cell_type": "code", }
"execution_count": null, ],
"id": "86a950d2-1c8e-46d5-aafe-444beb88bb88",
"metadata": {},
"outputs": [],
"source": [ "source": [
"# read from db and benchmark time\n", "print(influxdb_read_execution_time)"
"start = timeit.default_timer()\n",
"dfIdr = cHouseQueryDf(dbname)\n",
"stop = timeit.default_timer()\n",
"influxdb_read_execution_time = stop - start"
] ]
}, },
{ {
@ -913,48 +901,6 @@
"df.tail()" "df.tail()"
] ]
}, },
{
"cell_type": "code",
"execution_count": 20,
"id": "f861fab2-f1b1-49dd-b758-12d10aef3462",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: user 25.8 s, sys: 408 ms, total: 26.2 s\n",
"Wall time: 1min 36s\n"
]
}
],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "0bb2563d-68e2-4ff4-8842-70ac730dc6b1",
"metadata": {},
"outputs": [],
"source": [
"# data\n",
"# |> pivot(\n",
"# rowKey:[\"_time\"],\n",
"# columnKey: [\"_field\"],\n",
"# valueColumn: \"_value\"\n",
"# )"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "bb1596f9-4cee-4642-803a-ee61c9dddf64",
"metadata": {},
"outputs": [],
"source": [
"# Read"
]
},
{ {
"cell_type": "markdown", "cell_type": "markdown",
"id": "b9ddfdc6-c899-4f6c-9b4e-8ec6ab6d7e05", "id": "b9ddfdc6-c899-4f6c-9b4e-8ec6ab6d7e05",

Loading…
Cancel
Save