On Fri, 10 Aug 2018 02:10:34 +0000, Stefan Ram wrote:
> Adam Jensen <
han...@riseup.net> writes:
>>Yes, I am looking for a combination of SQL and Tcl that will derive a
>>set of start and stop numbers from the contents of the database and a
>>query. I am surprised the example wasn't clear for most everyone.
>
> While I now can understand this for the special case given, the
> description of the range of possible inputs is still not clear to me.
>
> For example, what should be the output for:
>
> 10.0|30.0|interesting 12.0|32.0|interesting 15.0|20.0|fail
> 16.0|19.0|interesting 17.0|19.0|interesting 17.0|20.0|fail
>
> , or, if this should not be possible as an input, what are the rules
> that specify what /is/ possible as an input?
I thought the simplified example that isolate the basic problem would be
more convenient than an example with a lot of context. I guess that
turned out to be a little frustrating for some folks. Oops.
Anyway, here's a basic process with your example.
10.0|30.0|interesting
12.0|32.0|interesting
15.0|20.0|fail
16.0|19.0|interesting
17.0|19.0|interesting
17.0|20.0|fail
1. Find all of the "interesting" segments.
10.0|30.0|interesting
12.0|32.0|interesting
16.0|19.0|interesting
17.0|19.0|interesting
2. Find any "interesting" segment overlaps and merge.
10.0|32.0|interesting
3. Find all "fail" segments with a period that overlaps the period of any
"interesting" segment.
15.0|20.0|fail
17.0|20.0|fail
4. Find any overlaps in those (3) "fail" segments and merge.
15.0|20.0|fail
5. Derive a new list of "interesting" segments that omits all (4) "fail"
segments.
10.0|15.0|interesting
20.0|32.0|interesting
I had hoped to get some comments about effective ways to do something
like this in SQL (sqlite) maybe augmented with Tcl.
The labels "interesting" and "fail" are almost arbitrary. I chose them
for the example in an attempt to keep it simple.
Not to complicate the original question, but for anyone who likes more
context, what I was preparing to use for the early tests and experiments
is something like this:
------------------------------------------------------------
CREATE TABLE MediaFiles (
file_id INTEGER PRIMARY KEY AUTOINCREMENT,
file_path TEXT NOT NULL,
file_name TEXT NOT NULL,
source TEXT);
CREATE TABLE Segments (
segment_id INTEGER PRIMARY KEY AUTOINCREMENT,
file_id INTEGER REFERENCES MediaFiles( file_id )
ON UPDATE CASCADE ON DELETE CASCADE,
begin_time REAL,
end_time REAL);
CREATE TABLE Attributes(
attribute_id INTEGER PRIMARY KEY AUTOINCREMENT,
tag TEXT NOT NULL,
description TEXT);
CREATE TABLE SegmentAttributes(
segment_id INTEGER REFERENCES Segments( segment_id )
ON UPDATE CASCADE ON DELETE CASCADE,
attribute_id INTEGER REFERENCES Attributes( attribute_id )
ON UPDATE CASCADE ON DELETE CASCADE,
PRIMARY KEY ( segment_id, attribute_id ));
------------------------------------------------------------
This is very simple. It's just a placeholder for tests while I work on
other parts of the system.