_diff
_diff
¶
Change detection utilities for the event polling system.
diff_dicts
¶
diff_dicts(
old: dict[str, Any],
new: dict[str, Any],
*,
include_fields: frozenset[str] | None = None,
exclude_fields: frozenset[str] | None = None,
) -> list[Change]
Shallow diff of two dicts, returning a list of Change objects.
Compares top-level keys only. Nested dicts/lists are compared by equality.
| PARAMETER | DESCRIPTION |
|---|---|
old
|
Previous snapshot.
TYPE:
|
new
|
Current snapshot.
TYPE:
|
include_fields
|
If set, only diff these fields.
TYPE:
|
exclude_fields
|
If set, skip these fields.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[Change]
|
List of Change objects for fields that differ. |
Source code in cocapi/events/_diff.py
10 11 12 13 14 15 16 17 18 19 20 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 | |
diff_member_tags
¶
diff_member_tags(
old_members: list[dict[str, Any]],
new_members: list[dict[str, Any]],
) -> tuple[
list[dict[str, Any]],
list[dict[str, Any]],
list[tuple[dict[str, Any], dict[str, Any]]],
]
Compare member lists by tag to detect joins, leaves, and updates.
| PARAMETER | DESCRIPTION |
|---|---|
old_members
|
Previous member list.
TYPE:
|
new_members
|
Current member list.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[dict[str, Any]]
|
Tuple of (joined, left, updated) where: |
list[dict[str, Any]]
|
|
list[tuple[dict[str, Any], dict[str, Any]]]
|
|
tuple[list[dict[str, Any]], list[dict[str, Any]], list[tuple[dict[str, Any], dict[str, Any]]]]
|
|
Source code in cocapi/events/_diff.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
diff_named_list
¶
diff_named_list(
old_items: list[dict[str, Any]],
new_items: list[dict[str, Any]],
key: str = "name",
compare_field: str = "level",
) -> list[tuple[str, Any, Any]]
Diff two lists of dicts keyed by key, comparing compare_field.
Used for troops, spells, heroes, and equipment which all share a
{"name": str, "level": int} structure.
| PARAMETER | DESCRIPTION |
|---|---|
old_items
|
Previous list snapshot.
TYPE:
|
new_items
|
Current list snapshot.
TYPE:
|
key
|
Dict key used to identify items (default
TYPE:
|
compare_field
|
Dict key whose value is compared (default
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[tuple[str, Any, Any]]
|
List of |
list[tuple[str, Any, Any]]
|
compare_field changed. New items appear as |
Source code in cocapi/events/_diff.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |