Home > front end >  Python SQLite Help find Intersection algorithm
Python SQLite Help find Intersection algorithm

Time:11-05

Please help me understand, how to write meeting intersection algorithm?

I wrote a meeting calendar. This calendar uses SQLite3 db for store meetings. Calendar works in range of 24 hours or 1440 minutes. Minimum meeting time is 1 minute.

User entered start_meeting(10:00), end_meeting(11:00)> script converts time to 600 and 660(hours*60 minutes)> before writing data to db script must check that meeting range won't intersect with meeting range in db> if no interception> write meeting to db.

How to check intersection of entered meeting and exists meetings in db? PS: Sorry for english)

for more clarity:
new meeting: 
start_meeting    end_meeting
600              660

database meetings:
start_meeting    end_meeting
530              630
540              600
840              841

CodePudding user response:

I THINK this might work, but haven't had time to test all scenaios:

create table meetings (startM REAL, endM REAL);
insert into meetings VALUES(530,630);
insert into meetings VALUES(540,600);
insert into meetings VALUES(840,841);
select * from meetings where ((600 BETWEEN startM AND endM) OR (660 BETWEEN startM AND endM));

Result is:

530.0|630.0
540.0|600.0

The BETWEEN operator will obviously tell you if a number is between two numbers and I'm guessing that you want EITHER of the 'new meeting' times to not be between the startM and endM. So if there are records returned then there is a conflict.

You will have to do string substitution in Python for the new meeting and then find out the length of the cur.fetchall() command to see if there are conflicts.

Hope this is some guide to you.

  • Related