You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there any way with your library using IntervalDict to get atomic intervals while getting as value the number of times it was overlapped with other intervals in list?
I've done this simple script that gets atomic intervals but I don't know how to get as value the units field in dict multiplied by the number of times the new atomic interval is overlapped with original intervals list.
plans = [{
"start": "2022-03-29T00:00:00+0000" ,
"end": "2022-03-29T05:59:59+0000" ,
"units": 10 ,
},{
"start": "2022-03-29T01:00:00+0000" ,
"end": "2022-03-29T04:59:59+0000" ,
"units": 10 ,
},{
"start": "2022-03-29T02:00:00+0000" ,
"end": "2022-03-29T03:59:59+0000" ,
"units": 10 ,
},{
"start": "2022-03-29T02:29:59+0000" ,
"end": "2022-03-29T03:29:59+0000" ,
"units": 10 ,
},{
"start": "2022-03-29T06:29:59+0000" ,
"end": "2022-03-29T07:29:59+0000" ,
"units": 10 ,
}]
def get_plans_intersected(plans):
d = P.IntervalDict()
i=1
for plan in plans:
d[P.closed(plan["start"], plan["end"])] = i*plan["units"]
i+=1
items=[]
for interval, value in d.items():
for atomic in interval:
items.append((atomic, value))
items.sort()
return [{"start":P.to_data(item[0])[0][1],"end":P.to_data(item[0])[0][2],"units":item[1]} for item in items]
pprint(get_plans_intersected(plans))
It seems now I'm getting the number of times the atomic interval was overlapped. I understand now the combine should be done between each two intervals to decide what value should I get as a result. That is really powerful.
Thanks a lot for this great library for handling intervals in python!
Is there any way with your library using
IntervalDict
to get atomic intervals while getting as value the number of times it was overlapped with other intervals in list?I've done this simple script that gets atomic intervals but I don't know how to get as value the
units
field in dict multiplied by the number of times the new atomic interval is overlapped with original intervals list.And this is the output:
The result
units
values are just a coincidence of the originalplans
list data ordering as for example the non overlapping interval gets 50 units.The text was updated successfully, but these errors were encountered: