sorting cameras events

full_example
mcotton 2023-06-01 13:43:09 -05:00
parent 4fd94a4ad8
commit 09e153e3f6
2 changed files with 16 additions and 19 deletions

View File

@ -504,13 +504,16 @@ class Camera(Device):
# filter events by type # filter events by type
[self.events['status'].append(i) for i in response.json()['results'] if i['type'] == 'een.deviceCloudStatusUpdateEvent.v1'] [self.events['status'].append(i) for i in response.json()['results'] if i['type'] == 'een.deviceCloudStatusUpdateEvent.v1']
[self.events['motion'].append(i) for i in response.json()['results'] if i['type'] == 'een.motionDetectionEvent.v1'] [self.events['motion'].append(i) for i in response.json()['results'] if i['type'] == 'een.motionDetectionEvent.v1']
# remove duplicates # remove duplicates
seen = set() seen = set()
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'])] 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() seen = set()
self.events['motion'] = [event for event in self.events['motion'] if event['id'] not in seen and not seen.add(event['id'])] self.events['motion'] = [event for event in self.events['motion'] if event['id'] not in seen and not seen.add(event['id'])]
# sort by event startTimestamp descending
self.events['status'] = sorted(self.events['status'], key=lambda x: x['startTimestamp'], reverse=True)
self.events['motion'] = sorted(self.events['motion'], key=lambda x: x['startTimestamp'], reverse=True)
else: else:
success = False success = False

View File

@ -294,7 +294,7 @@
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"{\"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" "{\"id\":\"967034aa-aa8c-45d4-92c1-af73d0bc9f8d\",\"subscriptionConfig\":{\"lifeCycle\":\"temporary\",\"timeToLiveSeconds\":900},\"deliveryConfig\":{\"type\":\"serverSentEvents.v1\",\"sseUrl\":\"https://api.c012.eagleeyenetworks.com/api/v3.0/sse/eventSubscriptions/967034aa-aa8c-45d4-92c1-af73d0bc9f8d\"}}\n"
] ]
} }
], ],
@ -393,7 +393,7 @@
"name": "stdout", "name": "stdout",
"output_type": "stream", "output_type": "stream",
"text": [ "text": [
"2023-06-01T12:57:22.388-05:00 2023-06-01T06:57:22.388-05:00\n" "2023-06-01T13:41:19.422-05:00 2023-06-01T07:41:19.422-05:00\n"
] ]
} }
], ],
@ -428,18 +428,6 @@
"len(een.cameras[2].events['status'])" "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", "cell_type": "code",
"execution_count": null, "execution_count": null,
@ -447,7 +435,7 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"len(een.cameras[2].events['motion'])" "len(een.cameras[0].events['motion'])"
] ]
}, },
{ {
@ -468,7 +456,11 @@
"id": "8be8d503-b46d-4ba7-884e-2c21c3987129", "id": "8be8d503-b46d-4ba7-884e-2c21c3987129",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [] "source": [
"#for cam in een.cameras:\n",
"# for i in cam.events['status']:\n",
"# print(f\"{cam.name} - {i['startTimestamp']} - {i['data'][0]['newStatus']['connectionStatus']} \")"
]
}, },
{ {
"cell_type": "code", "cell_type": "code",
@ -476,7 +468,9 @@
"id": "b761affe-ec32-4bd2-ba20-a2a6fb9db801", "id": "b761affe-ec32-4bd2-ba20-a2a6fb9db801",
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [] "source": [
"#sorted(een.cameras[2].events['status'], key=lambda x: x['startTimestamp'], reverse=True) "
]
}, },
{ {
"cell_type": "code", "cell_type": "code",