I have some values over time, given in terms of windows like this:
left = [(0, 2, 'foo'), (2, 5, 'bar')]
right = [(1, 3, 'bas'), (3, 4, 'qux')]
And I need to combine them into windows when some pair of values held true, like this:
correct = [(0, 1, 'foo', None), (1, 2, 'foo', 'bas'), (2, 3, 'bar', 'bas'), (3, 4, 'bar', 'qux'), (4, 5, 'bar', None)]
What's the most performant way to do this?
#
programming #
python #
compsci
Hypolite Petovan
•Then I would iterate over all the possible values, checking for key existence in either transformed window arrays, and when we find one, it creates a new item in the resulting array with the new value from the changing array and the previous value of the other array.
The tricky part is the end since there's no more "starting value" but I assume you can have a
last key => null value
pair for this.For your example, the transformed arrays would look like this:
Of course this method requires the windows to be contiguous.
Life Sim Engine
•Life Sim Engine
•https://github.com/Tactical-Metaphysics/LiSE/blob/query/LiSE/LiSE/query.py#L403-L582
but it's a maze of special cases and I feel like there must be a better way
LiSE/query.py at query · Tactical-Metaphysics/LiSE
GitHubLife Sim Engine
•Life Sim Engine
•Hypolite Petovan
•Life Sim Engine
•Might have provided inspiration since the code was advancing down the list too quickly and I needed to take it step by step
Hypolite Petovan
•