-
-
Notifications
You must be signed in to change notification settings - Fork 719
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bc90846
commit 2778cf5
Showing
5 changed files
with
50 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,55 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Iterable | ||
|
||
|
||
def scheduler_story(keys: set, transition_log: Iterable) -> list: | ||
def scheduler_story( | ||
keys_or_stimuli: set[str], transition_log: Iterable[tuple] | ||
) -> list[tuple]: | ||
"""Creates a story from the scheduler transition log given a set of keys | ||
describing tasks or stimuli. | ||
Parameters | ||
---------- | ||
keys : set | ||
A set of task `keys` or `stimulus_id`'s | ||
keys_or_stimuli : set[str] | ||
Task keys or stimulus_id's | ||
log : iterable | ||
The scheduler transition log | ||
Returns | ||
------- | ||
story : list | ||
story : list[tuple] | ||
""" | ||
return [t for t in transition_log if t[0] in keys or keys.intersection(t[3])] | ||
return [ | ||
t | ||
for t in transition_log | ||
if t[0] in keys_or_stimuli or keys_or_stimuli.intersection(t[3]) | ||
] | ||
|
||
|
||
def worker_story(keys: set, log: Iterable) -> list: | ||
def worker_story(keys_or_stimuli: set[str], log: Iterable[tuple]) -> list: | ||
"""Creates a story from the worker log given a set of keys | ||
describing tasks or stimuli. | ||
Parameters | ||
---------- | ||
keys : set | ||
A set of task `keys` or `stimulus_id`'s | ||
keys_or_stimuli : set[str] | ||
Task keys or stimulus_id's | ||
log : iterable | ||
The worker log | ||
Returns | ||
------- | ||
story : list | ||
story : list[str] | ||
""" | ||
return [ | ||
msg | ||
for msg in log | ||
if any(key in msg for key in keys) | ||
if any(key in msg for key in keys_or_stimuli) | ||
or any( | ||
key in c for key in keys for c in msg if isinstance(c, (tuple, list, set)) | ||
key in c | ||
for key in keys_or_stimuli | ||
for c in msg | ||
if isinstance(c, (tuple, list, set)) | ||
) | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters