{ "cells": [ { "cell_type": "markdown", "id": "8d7c3cc5-d80b-41ab-b040-6ffafa9542dd", "metadata": {}, "source": [ "![](https://raw.githubusercontent.com/MomsFriendlyRobotCompany/the-collector/master/pics/header.jpg)\n", "# The Collector" ] }, { "cell_type": "code", "execution_count": 1, "id": "449a0a11-a9a5-49a0-bbd2-267df6658be0", "metadata": {}, "outputs": [], "source": [ "# reload library\n", "%load_ext autoreload\n", "%autoreload 2" ] }, { "cell_type": "code", "execution_count": 45, "id": "ecb4d894-42a0-4575-8f25-a9d17946691b", "metadata": {}, "outputs": [], "source": [ "from collector import Collector\n", "from collector import nuke\n", "import numpy as np" ] }, { "cell_type": "code", "execution_count": 46, "id": "24c7ddb3-cfab-41c3-8eec-61070c3f3a02", "metadata": {}, "outputs": [], "source": [ "c = Collector()\n", "c.timestamp = False\n", "d = np.array([[1,2,3],[4.,5.,6.]])\n", "i = {\"b\":[1,2,3,4]}" ] }, { "cell_type": "markdown", "id": "9c9ead77-cc7f-498b-8d6e-1e3d960f0760", "metadata": {}, "source": [ "## CSV" ] }, { "cell_type": "code", "execution_count": 47, "id": "9ab7606a-b809-46e1-9648-f293cee66ae3", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Saving 2 data points in csv to:\n", "--> test_test_now.csv\n", "Loaded 2 data points from:\n", "--> test_test_now.csv\n", "[[ True True True]\n", " [ True True True]]\n" ] }, { "data": { "text/plain": [ "{'data': [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]}" ] }, "execution_count": 47, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c.write(\"test_test_now.csv\",d)\n", "dd = c.read(\"test_test_now.csv\")\n", "# print(dd[\"info\"] == i)\n", "print(dd[\"data\"] == d)\n", "dd" ] }, { "cell_type": "markdown", "id": "babd8032-9de3-4881-a7e0-bb751be765f1", "metadata": {}, "source": [ "## Gzip'ed JSON" ] }, { "cell_type": "code", "execution_count": 48, "id": "f935ed1c-e118-4428-912f-5ddd83db2f45", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Saving 2 data points in json gzip to:\n", "--> test_test_now.gzip\n", "Loaded 2 data points from:\n", "--> test_test_now.gzip\n", "True\n", "[[ True True True]\n", " [ True True True]]\n" ] }, { "data": { "text/plain": [ "{'info': {'b': [1, 2, 3, 4]}, 'data': [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]}" ] }, "execution_count": 48, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c.write(\"test_test_now.gzip\",d,i)\n", "dd = c.read(\"test_test_now.gzip\")\n", "print(dd[\"info\"] == i)\n", "print(dd[\"data\"] == d)\n", "dd" ] }, { "cell_type": "markdown", "id": "dfe08d63-dd86-4d0d-8f98-59fbb8f836f0", "metadata": {}, "source": [ "## JSON" ] }, { "cell_type": "code", "execution_count": 21, "id": "c70441e4-395b-4353-a54c-59d3a2492037", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Saving 2 data points in json to:\n", "--> test_test_now.json\n", "Loaded 2 data points from:\n", "--> test_test_now.json\n", "True\n", "[[ True True True]\n", " [ True True True]]\n" ] } ], "source": [ "c.write(\"test_test_now.json\",d,i)\n", "dd = c.read(\"test_test_now.json\")\n", "print(dd[\"info\"] == i)\n", "print(dd[\"data\"] == d)" ] }, { "cell_type": "markdown", "id": "da293926-e270-4961-af13-f7f6c00e0322", "metadata": {}, "source": [ "## Pickle" ] }, { "cell_type": "code", "execution_count": 40, "id": "7ae01b97-c00b-4de2-87c4-913a3ff1d1d3", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Saving 2 data points in pickle to:\n", "--> 2023-08-08T18:53:53_test_test_now.pkl\n", "Loaded 2 data points from:\n", "--> 2023-08-08T18:53:53_test_test_now.pkl\n", "True\n", "[[ True True True]\n", " [ True True True]]\n" ] }, { "data": { "text/plain": [ "{'info': {'b': [1, 2, 3, 4]}, 'data': [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]]}" ] }, "execution_count": 40, "metadata": {}, "output_type": "execute_result" } ], "source": [ "fname = c.write(\"test_test_now.pkl\",d,i)\n", "dd = c.read(fname)\n", "print(dd[\"info\"] == i)\n", "print(dd[\"data\"] == d)\n", "dd" ] }, { "cell_type": "code", "execution_count": 49, "id": "3313afb7-69a2-4478-92e0-bebf6dfc5707", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Saving 2 data points in pickle to:\n", "--> data/2023-08-08T18:57:52_test_test_now.pkl\n", "Loaded 2 data points from:\n", "--> data/2023-08-08T18:57:52_test_test_now.pkl\n", "True\n", "[[ True True True]\n", " [ True True True]]\n" ] } ], "source": [ "c.timestamp = True\n", "fname = c.write(\"data/test_test_now.pkl\",d,i)\n", "dd = c.read(fname)\n", "print(dd[\"info\"] == i)\n", "print(dd[\"data\"] == d)" ] }, { "cell_type": "markdown", "id": "b129886d-db09-424b-8bfd-0fafa3c3ed6a", "metadata": {}, "source": [ "## Nuke" ] }, { "cell_type": "code", "execution_count": 50, "id": "00ede705-3be4-45d4-8ad9-8ebcc246f9db", "metadata": {}, "outputs": [], "source": [ "nuke(recursive=True)" ] }, { "cell_type": "code", "execution_count": null, "id": "9e25460e-dfad-448b-b345-d5757ee59a8a", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.4" } }, "nbformat": 4, "nbformat_minor": 5 }