Skip to content

funtracks.actions.update_node_attrs

Classes:

Name Description
UpdateNodeAttrs

Action for user updates to node attributes. Cannot update protected

UpdateNodeAttrs

UpdateNodeAttrs(tracks: SolutionTracks, node: Node, attrs: dict[str, Any])

Bases: TracksAction

Action for user updates to node attributes. Cannot update protected attributes (time, area, track id), as these are controlled by internal application logic.

Parameters:

Name Type Description Default

tracks

Tracks

The tracks to update the node attributes for

required

node

Node

The node to update the attributes for

required

attrs

dict[str, Any]

A mapping from attribute name to list of new attribute values for the given nodes.

required

Raises:

Type Description
ValueError

If a protected attribute is in the given attribute mapping.

Methods:

Name Description
inverse

Restore previous attributes

Source code in src/funtracks/actions/update_node_attrs.py
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
def __init__(
    self,
    tracks: SolutionTracks,
    node: Node,
    attrs: dict[str, Any],
):
    """
    Args:
        tracks (Tracks): The tracks to update the node attributes for
        node (Node): The node to update the attributes for
        attrs (dict[str, Any]): A mapping from attribute name to list of new attribute
            values for the given nodes.

    Raises:
        ValueError: If a protected attribute is in the given attribute mapping.
    """
    super().__init__(tracks)
    protected_attrs = [
        tracks.time_attr,
        NodeAttr.AREA.value,
        NodeAttr.TRACK_ID.value,
    ]
    for attr in attrs:
        if attr in protected_attrs:
            raise ValueError(f"Cannot update attribute {attr} manually")
    self.node = node
    self.prev_attrs = {attr: self.tracks.get_node_attr(node, attr) for attr in attrs}
    self.new_attrs = attrs
    self._apply()

inverse

inverse() -> TracksAction

Restore previous attributes

Source code in src/funtracks/actions/update_node_attrs.py
51
52
53
54
55
56
57
def inverse(self) -> TracksAction:
    """Restore previous attributes"""
    return UpdateNodeAttrs(
        self.tracks,
        self.node,
        self.prev_attrs,
    )