Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
07-18-2021 06:22 PM
Hi,
I wish to retrive all the events that happens in the same time and my idea is to find the event based on the start time and end time, I write a stupid code which is not efficient and seems a mass, therefore I would to ask if there is a smart way of retrieve the co-evolving events?
Thanks
MATCH (c:Car {carID:"car_ID"})-[:takePlace]->(e:Event)
with collect(e) as cles
UNWIND cles as cle
match (c:Car {carID:"car_ID"})-[:takePlace]->(e:Event)
where (e.start_time in range(cle.start_time, cle.end_time)) and (e.end_time in range(cle.start_time, cle.end_time))
with collect(e) as coll
return cle, coll
07-29-2021 03:18 PM
This worked for me.
I am not grouping them yet but you can add that.
It shows the events that are happening within the start and end of a different event.
MATCH (e1:Event)
MATCH (e2:Event)
where id(e1)<>id(e2)
WITH e1, e2, Case when e1.start >= e2.start AND e1.end <= e2.end then 'between' else 'not between' END as within
//where within = 'between'
Return e1.id, e2.id, apoc.text.format("%s-%s is %s %s-%s.", [e1.start,e1.end,within,e2.start,e2.end]) as results
Results:
e1.id | e2.id | results |
---|---|---|
b | a | 2-3 is between 1-10. |
b | c | 2-3 is between 2-5. |
c | a | 2-5 is between 1-10. |
d | a | 7-9 is between 1-10. |
d | f | 7-9 is between 4-9. |
e | a | 9-10 is between 1-10. |
f | a | 4-9 is between 1-10. |
My test data:
id | start | end |
---|---|---|
a | 1 | 10 |
b | 2 | 3 |
c | 2 | 5 |
d | 7 | 9 |
e | 9 | 10 |
f | 4 | 9 |
To load up test data:
create (a:Event), (b:Event), (c:Event), (d:Event), (e:Event), (f:Event)
SET
a.start = 1, a.end = 10, a.id = 'a',
b.start = 2, b.end = 3, b.id = 'b',
c.start = 2, c.end = 5, c.id = 'c',
d.start = 7, d.end = 9, d.id = 'd',
e.start = 9, e.end = 10, e.id = 'e',
f.start = 4, f.end = 9, f.id = 'f'
return a, b, c, d, e, f
I hope that helps.
All the sessions of the conference are now available online