jeudi 24 mars 2016

Find Time Gaps in Records

Hi have a security camera that records in continuous mode. It saves a record of its recordings to a sqlite database file into a few different files. I'm trying to find time gaps in the recordings. The problem is that certain recording events overlap so I can't simply find the time difference between starttime and stoptime. Here is the query I am currently using:

select b.id,  datetime(b.starttime, "-8 Hour") as starttime, datetime(b.stoptime, "-8 Hour") as endtime, b.recording_id
from blocks b, recordings a 
where b.recording_id = a.id and a.recording_type_id = 1 order by b.starttime asc

Here is an excerpt from a query where I sort by Starttime:

+------------------------------------------------------------+
| id   starttime           endtime             recording_id  |
+------------------------------------------------------------+
| ---- ------------------- ------------------- ------------  |
| 6824 2016-03-22 12:32:48 2016-03-22 12:38:08 389           |
| 6825 2016-03-22 12:38:08 2016-03-22 12:43:28 389           |
| 6826 2016-03-22 12:39:00 2016-03-22 12:41:10 418           |
| 6827 2016-03-22 12:43:28 2016-03-22 12:48:48 389           |
| 6828 2016-03-22 12:48:48 2016-03-22 12:54:08 389           |
| 6829 2016-03-22 12:54:08 2016-03-22 12:59:28 389           |
+------------------------------------------------------------+

I get a time gap from ID 6826 to ID 6827 when in fact there isn't one. ID 6825 lines up with ID 6827.

Any ideas how to make this work. I thought about hammering each second of each day to test if it lies between any of the times and create a record that way but that's just brutish.

Aucun commentaire:

Enregistrer un commentaire