From bb292b5c8ec11004a2c002d61e84b0ae3396b6bb Mon Sep 17 00:00:00 2001 From: crosstyan Date: Tue, 12 Nov 2024 17:37:09 +0800 Subject: [PATCH] save as csv --- parse_exported.ipynb | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/parse_exported.ipynb b/parse_exported.ipynb index f25dcbc..59e445e 100644 --- a/parse_exported.ipynb +++ b/parse_exported.ipynb @@ -33,7 +33,9 @@ "import numpy as np\n", "\n", "\n", - "def to_scatter(key: str, dev_history: AwkwardArray, plot_key: Literal[\"value\", \"rssi\"] = \"value\") -> go.Scatter:\n", + "def to_scatter(\n", + " key: str, dev_history: AwkwardArray, plot_key: Literal[\"value\", \"rssi\"] = \"value\"\n", + ") -> go.Scatter:\n", " x = ak.to_numpy(dev_history[\"time\"])\n", " if plot_key == \"rssi\":\n", " y = ak.to_numpy(dev_history[\"rssi\"])\n", @@ -43,6 +45,7 @@ " raise ValueError(f\"Unknown plot_key: {plot_key}\")\n", " return go.Scatter(x=x, y=y, mode=\"lines+markers\", name=key)\n", "\n", + "\n", "scatters: list[go.Scatter] = []\n", "for k in data.fields:\n", " val = data[k]\n", @@ -59,6 +62,33 @@ "source": [ "display(fig)" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import csv\n", + "def dump_as_csv(mac:str, device_record: AwkwardRecord, filename:str):\n", + " time = ak.to_numpy(device_record[mac][\"time\"]) # type: ignore\n", + " value = ak.to_numpy(device_record[mac][\"value\"]) # type: ignore\n", + " rssi = ak.to_numpy(device_record[mac][\"rssi\"]) # type: ignore\n", + " with open(filename, \"w\") as f:\n", + " writer = csv.writer(f)\n", + " writer.writerow([\"time\", \"value\", \"rssi\"])\n", + " for t, v, r in zip(time, value, rssi):\n", + " writer.writerow([t, v, r])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "dump_as_csv(\"A09E1AE4E710\", data, \"A09E1AE4E710.csv\")" + ] } ], "metadata": {