save as csv
This commit is contained in:
@ -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": {
|
||||
|
||||
Reference in New Issue
Block a user