From 4fd94a4ad8343d1ef0015cbf1eefc908417b7a97 Mon Sep 17 00:00:00 2001 From: mcotton Date: Thu, 1 Jun 2023 12:59:17 -0500 Subject: [PATCH] filter events call --- EagleEyev3/__init__.py | 2 +- Playground.ipynb | 314 ++++++++++++++++------------------------- 2 files changed, 123 insertions(+), 193 deletions(-) diff --git a/EagleEyev3/__init__.py b/EagleEyev3/__init__.py index a73e7b9..fb2ba06 100644 --- a/EagleEyev3/__init__.py +++ b/EagleEyev3/__init__.py @@ -507,7 +507,7 @@ class Camera(Device): # remove duplicates seen = set() - self.events['status'] = [event for event in self.events['status'] if event['id'] not in seen and not seen.add(event['id'])] + self.events['status'] = [event for event in self.events['status'] if event['endTimestamp'] and event['id'] not in seen and not seen.add(event['id'])] seen = set() self.events['motion'] = [event for event in self.events['motion'] if event['id'] not in seen and not seen.add(event['id'])] diff --git a/Playground.ipynb b/Playground.ipynb index 1f44d2a..3ae6bdf 100644 --- a/Playground.ipynb +++ b/Playground.ipynb @@ -5,31 +5,11 @@ "id": "d4582341", "metadata": {}, "source": [ - "# EagleEyev3 Playground #\n", + "# EagleEyev3 Playground\n", "\n", "To make this playground work, it is easier to read the `access_token` off the filesystem but you can always run the example server `python server.py` to go thorugh the Oauth2 flow. By default it will save the `access_token` into a file named `.lazy_login`. The module looks for that file and tries reading t" ] }, - { - "cell_type": "markdown", - "id": "51b8b66e", - "metadata": {}, - "source": [ - "## Adjust Log Level" - ] - }, - { - "cell_type": "code", - "execution_count": 46, - "id": "06d91db2", - "metadata": {}, - "outputs": [], - "source": [ - "import logging\n", - "logger = logging.getLogger()\n", - "logger.setLevel('WARN')" - ] - }, { "cell_type": "markdown", "id": "8355d241", @@ -40,7 +20,7 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 1, "id": "1394471a", "metadata": {}, "outputs": [], @@ -50,12 +30,45 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": 2, "id": "486a2537", "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "INFO:root:200 in get_base_url\n", + "INFO:root:200 in get_current_user\n" + ] + } + ], + "source": [ + "een = EagleEyev3()" + ] + }, + { + "cell_type": "markdown", + "id": "51b8b66e", + "metadata": {}, + "source": [ + "## Adjust Log Level" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "06d91db2", + "metadata": {}, "outputs": [], "source": [ - "een = EagleEyev3()" + "import logging\n", + "logger = logging.getLogger()\n", + "#logger.setLevel('DEBUG')\n", + "#logger.setLevel('INFO')\n", + "logger.setLevel('WARN')\n", + "#logger.setLevel('ERROR')\n", + "#logger.setLevel('CRITICAL')" ] }, { @@ -63,12 +76,12 @@ "id": "0311109c-869c-4190-97c1-a6e717a8eeba", "metadata": {}, "source": [ - "## Who am I and what is my access_token" + "## Who am I" ] }, { "cell_type": "code", - "execution_count": 49, + "execution_count": 4, "id": "e14e2be5-a5f9-4b8c-ae60-76c61cb61b8b", "metadata": {}, "outputs": [ @@ -78,7 +91,7 @@ "'Mark Cotton - mcotton@mcottondesign.com'" ] }, - "execution_count": 49, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -89,7 +102,7 @@ }, { "cell_type": "code", - "execution_count": 50, + "execution_count": 5, "id": "4ef47ae2-a010-4b7e-87f6-3dbf0a047e16", "metadata": {}, "outputs": [ @@ -99,7 +112,7 @@ "'eyJraWQiOiI2ODYxYjBjYS0wZjI2LTExZWQtODYxZC0wMjQyYWMxMjAwMDIiLCJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJjYWZlZGVmMiIsImF1ZCI6InZtcy5hcGkiLCJpc3MiOiJ2bXMuYXV0aC52MSIsInZtc19hY2NvdW50IjoiMDAwMjgyMDEiLCJleHAiOjE2ODYwMTQ0NjUsImlhdCI6MTY4NTQwOTY2NiwianRpIjoiNDBkMThmZTA0YTZlNWE5NDI0OWE4NmVjNmE5NDA0YzYiLCJjbGllbnRfaWQiOiJQUkVWSUVXLU1BUkstV0VCIiwidm1zX2NsdXN0ZXIiOiJjMDEyIn0.RAVxuQtnb9WSv4jp4hNqEyPaVzlpK6GqodFAUybzrnGiPR9tHE5OIanCZf2aX5IGAyOk9Kn5UYD4h96iIt8cpCXIyrFPKGE3WtspAxYNBwczjAWTuZQ6lOxH2eIeo3QjoTeOZaL8JEfCmc5-NyK4xaTrnb0nuhUnWzB4Vo9xtqzn2mupYUEyOvkgM0nOaTxPlrJLRNjNKDWKwMtuE2wo94HbjeOi8lSvQcMPvm07qvS1nFEaTjzpHCdwENcK6ghEUv5wzbUsDm5FYZFi29MyGLLiwv6csGD8lY0C3FFsG5EbMFzNAqS-v-CriPgA-3X9rpgLiWNIjSFG8vj7ZzCtsg'" ] }, - "execution_count": 50, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } @@ -118,7 +131,7 @@ }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 6, "id": "bb457850", "metadata": {}, "outputs": [], @@ -128,20 +141,17 @@ }, { "cell_type": "code", - "execution_count": 52, + "execution_count": 7, "id": "c43f1db1", "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "[✅ [1001423e] - ATM & Wine,\n", - " ✅ [100d8666] - Cash Register,\n", - " ✅ [10012735] - Fuel Dock,\n", - " ✅ [1002584c] - Safe]" + "[✅ [1001423e] - ATM & Wine, ✅ [100d8666] - Cash Register, ✅ [1002584c] - Safe]" ] }, - "execution_count": 52, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } @@ -152,7 +162,7 @@ }, { "cell_type": "code", - "execution_count": 53, + "execution_count": 8, "id": "ad33bf2a-ea36-4ec1-8335-8a44089f5f7e", "metadata": {}, "outputs": [ @@ -162,11 +172,12 @@ "[? [10090759] - Benny Camera,\n", " ? [1003e10b] - Driveway,\n", " ? [100ba388] - Front Door,\n", + " ? [10012735] - Fuel Dock,\n", " ? [100b7b3b] - Max Camera,\n", " ? [1009ae55] - Office]" ] }, - "execution_count": 53, + "execution_count": 8, "metadata": {}, "output_type": "execute_result" } @@ -177,7 +188,7 @@ }, { "cell_type": "code", - "execution_count": 54, + "execution_count": 9, "id": "f4c6fe67", "metadata": {}, "outputs": [ @@ -187,11 +198,12 @@ "[? [10090759] - Benny Camera,\n", " ? [1003e10b] - Driveway,\n", " ? [100ba388] - Front Door,\n", + " ? [10012735] - Fuel Dock,\n", " ? [100b7b3b] - Max Camera,\n", " ? [1009ae55] - Office]" ] }, - "execution_count": 54, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -218,66 +230,44 @@ }, { "cell_type": "code", - "execution_count": 55, + "execution_count": 10, "id": "ef1ea137-d9fb-4f6f-b241-fb019c8e3230", "metadata": {}, "outputs": [], "source": [ - "from datetime import datetime, timedelta\n", - "from pytz import timezone" + "#from datetime import datetime, timedelta\n", + "#from pytz import timezone" ] }, { "cell_type": "code", - "execution_count": 56, + "execution_count": 11, "id": "0841aef0-89c1-45ac-b501-a9196f481d49", "metadata": {}, "outputs": [], "source": [ - "tz = timezone(een.current_user['timeZone']['timeZone'])\n", - "now = datetime.now(tz=tz)" + "#een.user_tz_obj = timezone(een.current_user['timeZone']['timeZone'])\n", + "#now = datetime.now(tz=een.user_tz_obj)" ] }, { "cell_type": "code", - "execution_count": 57, + "execution_count": 12, "id": "ae53f810-cb77-48e3-b148-72ef7038bb89", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'2023-05-31T23:01:04.271-05:00'" - ] - }, - "execution_count": 57, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ - "now.isoformat(timespec='milliseconds')" + "#now.isoformat(timespec='milliseconds')" ] }, { "cell_type": "code", - "execution_count": 58, + "execution_count": 13, "id": "4d708ccb-80b1-4d88-aa2e-d93a71cbdc04", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'2023-05-31T17:01:04.640-05:00'" - ] - }, - "execution_count": 58, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ - "(datetime.now(tz=tz) - timedelta(hours=6)).isoformat(timespec='milliseconds')" + "#(datetime.now(tz=een.user_tz_obj) - timedelta(hours=6)).isoformat(timespec='milliseconds')" ] }, { @@ -296,7 +286,7 @@ }, { "cell_type": "code", - "execution_count": 59, + "execution_count": 14, "id": "a9d81b0d-72e6-4404-b30e-3a341a9e6639", "metadata": {}, "outputs": [ @@ -304,7 +294,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "{\"id\":\"2470978d-1285-446f-9504-f2399a4e2819\",\"subscriptionConfig\":{\"lifeCycle\":\"temporary\",\"timeToLiveSeconds\":900},\"deliveryConfig\":{\"type\":\"serverSentEvents.v1\",\"sseUrl\":\"https://api.c012.eagleeyenetworks.com/api/v3.0/sse/eventSubscriptions/2470978d-1285-446f-9504-f2399a4e2819\"}}\n" + "{\"id\":\"493237a3-2929-4886-b9c1-446325eb533e\",\"subscriptionConfig\":{\"lifeCycle\":\"temporary\",\"timeToLiveSeconds\":900},\"deliveryConfig\":{\"type\":\"serverSentEvents.v1\",\"sseUrl\":\"https://api.c012.eagleeyenetworks.com/api/v3.0/sse/eventSubscriptions/493237a3-2929-4886-b9c1-446325eb533e\"}}\n" ] } ], @@ -335,7 +325,7 @@ }, { "cell_type": "code", - "execution_count": 60, + "execution_count": 15, "id": "53d3bff7-848f-4669-ab66-57597313fa0d", "metadata": { "editable": true, @@ -355,7 +345,7 @@ }, { "cell_type": "code", - "execution_count": 61, + "execution_count": 16, "id": "91cfe32d-db80-40fb-8ea9-d60f8a647b0d", "metadata": {}, "outputs": [ @@ -365,7 +355,7 @@ "" ] }, - "execution_count": 61, + "execution_count": 16, "metadata": {}, "output_type": "execute_result" } @@ -376,7 +366,7 @@ }, { "cell_type": "code", - "execution_count": 62, + "execution_count": 17, "id": "2016a9cf-9ce8-48af-8e3f-c058024c544e", "metadata": {}, "outputs": [], @@ -390,32 +380,12 @@ "id": "8c140aaf-766f-4255-94ef-199d17cbc7a6", "metadata": {}, "source": [ - "## Getting list of Events ##" + "## Getting list of Events" ] }, { "cell_type": "code", - "execution_count": 109, - "id": "2a5c78ed-eb96-45aa-a773-1681671a0d42", - "metadata": {}, - "outputs": [], - "source": [ - "end_timestamp = datetime.now(tz=tz).isoformat(timespec='milliseconds')" - ] - }, - { - "cell_type": "code", - "execution_count": 110, - "id": "14132706-1d29-4fb9-b5b0-3dc7519118aa", - "metadata": {}, - "outputs": [], - "source": [ - "start_timestamp = (datetime.now(tz=tz) - timedelta(hours=6)).isoformat(timespec='milliseconds')" - ] - }, - { - "cell_type": "code", - "execution_count": 111, + "execution_count": 18, "id": "74e78ee1-33b8-4a88-9d23-cd6281603a5b", "metadata": {}, "outputs": [ @@ -423,135 +393,95 @@ "name": "stdout", "output_type": "stream", "text": [ - "2023-05-31T17:12:35.355-05:00 2023-05-31T23:12:34.754-05:00\n" + "2023-06-01T12:57:22.388-05:00 2023-06-01T06:57:22.388-05:00\n" ] } ], "source": [ - "print(start_timestamp, end_timestamp)" + "print(een.time_now(), een.time_before())" ] }, { "cell_type": "code", - "execution_count": 112, + "execution_count": null, "id": "c84c30dd-4b7c-415b-8e6f-e77de70d1924", "metadata": { "scrolled": true }, "outputs": [], "source": [ - "for cam in een.cameras:\n", - " blah = cam.get_list_of_events(start_timestamp=start_timestamp, end_timestamp=end_timestamp)" + "for i in range(0,20):\n", + " ts = een.time_now()\n", + "\n", + " for cam in een.cameras:\n", + " blah = cam.get_list_of_events(end_timestamp=een.time_before(ts=ts, hours=(6*i)), \\\n", + " start_timestamp=een.time_before(ts=ts, hours=(6*(i+1))) )" ] }, { "cell_type": "code", - "execution_count": 113, - "id": "f6c11a52-63e1-4b65-8149-4d0e31d13870", + "execution_count": null, + "id": "13809cc7-9ec2-4e15-9495-e64feaecca6d", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[{'type': 'een.deviceCloudStatusUpdateEvent.v1',\n", - " 'id': '100d8666-2023-05-31T22:01:22.001Z-een.deviceCloudStatusUpdateEvent.v1',\n", - " 'startTimestamp': '2023-05-31T22:01:22.001+00:00',\n", - " 'endTimestamp': None,\n", - " 'span': True,\n", - " 'accountId': '00028201',\n", - " 'actorId': '100d8666',\n", - " 'actorAccountId': '00028201',\n", - " 'actorType': 'camera',\n", - " 'creatorId': 'een.systemHealth',\n", - " 'dataSchemas': ['data.een.deviceCloudStatusUpdate.v1'],\n", - " 'data': [{'type': 'een.deviceCloudStatusUpdateEvent.v1',\n", - " 'creatorId': 'een.systemHealth',\n", - " 'newStatus': {'connectionStatus': 'online'}}]},\n", - " {'type': 'een.deviceCloudStatusUpdateEvent.v1',\n", - " 'id': '100d8666-2023-05-31T22:11:35.901Z-een.deviceCloudStatusUpdateEvent.v1',\n", - " 'startTimestamp': '2023-05-31T22:11:35.901+00:00',\n", - " 'endTimestamp': None,\n", - " 'span': True,\n", - " 'accountId': '00028201',\n", - " 'actorId': '100d8666',\n", - " 'actorAccountId': '00028201',\n", - " 'actorType': 'camera',\n", - " 'creatorId': 'een.systemHealth',\n", - " 'dataSchemas': ['data.een.deviceCloudStatusUpdate.v1'],\n", - " 'data': [{'type': 'een.deviceCloudStatusUpdateEvent.v1',\n", - " 'creatorId': 'een.systemHealth',\n", - " 'newStatus': {'connectionStatus': 'online'}}]},\n", - " {'type': 'een.deviceCloudStatusUpdateEvent.v1',\n", - " 'id': '100d8666-2023-05-31T22:12:35.355Z-een.deviceCloudStatusUpdateEvent.v1',\n", - " 'startTimestamp': '2023-05-31T22:12:35.355+00:00',\n", - " 'endTimestamp': None,\n", - " 'span': True,\n", - " 'accountId': '00028201',\n", - " 'actorId': '100d8666',\n", - " 'actorAccountId': '00028201',\n", - " 'actorType': 'camera',\n", - " 'creatorId': 'een.systemHealth',\n", - " 'dataSchemas': ['data.een.deviceCloudStatusUpdate.v1'],\n", - " 'data': [{'type': 'een.deviceCloudStatusUpdateEvent.v1',\n", - " 'creatorId': 'een.systemHealth',\n", - " 'newStatus': {'connectionStatus': 'online'}}]}]" - ] - }, - "execution_count": 113, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], + "source": [ + "len(een.cameras[2].events['status'])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f6c11a52-63e1-4b65-8149-4d0e31d13870", + "metadata": { + "scrolled": true + }, + "outputs": [], "source": [ "een.cameras[2].events['status']" ] }, { "cell_type": "code", - "execution_count": 115, + "execution_count": null, "id": "67d4f79b-2b43-4bdb-9068-28ac9d8d921c", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "106" - ] - }, - "execution_count": 115, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "len(een.cameras[2].events['motion'])" ] }, { "cell_type": "code", - "execution_count": 116, - "id": "9bf0a03d-cede-4e66-af88-ec17de19ef22", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'Cash Register'" - ] - }, - "execution_count": 116, - "metadata": {}, - "output_type": "execute_result" - } - ], + "execution_count": null, + "id": "287cbf7b-52c4-4aac-abeb-be94d0594c19", + "metadata": { + "scrolled": true + }, + "outputs": [], "source": [ - "een.cameras[2].name" + "#een.cameras[2].get_list_of_events(end_timestamp=een.time_now(), start_timestamp=een.time_before())" ] }, { "cell_type": "code", "execution_count": null, - "id": "287cbf7b-52c4-4aac-abeb-be94d0594c19", + "id": "8be8d503-b46d-4ba7-884e-2c21c3987129", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b761affe-ec32-4bd2-ba20-a2a6fb9db801", + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1cebbb4e-4c4e-4ab0-9627-251eb812b2f1", "metadata": {}, "outputs": [], "source": []