cs2df 3.0.3__tar.gz → 3.0.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cs2df-3.0.3 → cs2df-3.0.4}/PKG-INFO +1 -1
- {cs2df-3.0.3 → cs2df-3.0.4}/pyproject.toml +1 -1
- {cs2df-3.0.3 → cs2df-3.0.4}/src/cs2df/__init__.py +1 -1
- {cs2df-3.0.3 → cs2df-3.0.4}/src/cs2df/parse.py +2 -3
- {cs2df-3.0.3 → cs2df-3.0.4}/src/cs2df/streams.py +9 -48
- {cs2df-3.0.3 → cs2df-3.0.4}/tests/test_replay_boundaries.py +27 -0
- {cs2df-3.0.3 → cs2df-3.0.4}/uv.lock +1 -1
- {cs2df-3.0.3 → cs2df-3.0.4}/.gitignore +0 -0
- {cs2df-3.0.3 → cs2df-3.0.4}/README.md +0 -0
- {cs2df-3.0.3 → cs2df-3.0.4}/src/cs2df/cli.py +0 -0
- {cs2df-3.0.3 → cs2df-3.0.4}/src/cs2df/enums.py +0 -0
- {cs2df-3.0.3 → cs2df-3.0.4}/src/cs2df/events.py +0 -0
- {cs2df-3.0.3 → cs2df-3.0.4}/src/cs2df/package.py +0 -0
- {cs2df-3.0.3 → cs2df-3.0.4}/src/cs2df/rounds.py +0 -0
- {cs2df-3.0.3 → cs2df-3.0.4}/src/cs2df/validate.py +0 -0
- {cs2df-3.0.3 → cs2df-3.0.4}/tests/test_cli_batch.py +0 -0
- {cs2df-3.0.3 → cs2df-3.0.4}/tests/test_round_windows.py +0 -0
- {cs2df-3.0.3 → cs2df-3.0.4}/tests/test_version_consistency.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cs2df
|
|
3
|
-
Version: 3.0.
|
|
3
|
+
Version: 3.0.4
|
|
4
4
|
Summary: Reference exporter & validator CLI for cs2-demo-format v3 (CS2 demo → ZIP data package)
|
|
5
5
|
Project-URL: Homepage, https://github.com/Starfie1d1272/cs2-demo-format
|
|
6
6
|
Project-URL: Repository, https://github.com/Starfie1d1272/cs2-demo-format
|
|
@@ -9,9 +9,8 @@ Performance notes (this module is the reference for fast producers):
|
|
|
9
9
|
~200k row dicts (`to_dict(orient="records")`), which dominated Python-side
|
|
10
10
|
time; v3's columnar layout makes that conversion unnecessary.
|
|
11
11
|
- `inventory` (a per-row list of strings, by far the most expensive tick prop)
|
|
12
|
-
is
|
|
13
|
-
|
|
14
|
-
inventory is only read at the ~24 freeze ticks for economy rows.
|
|
12
|
+
is extracted on the sampled replay grid for held utility and bomb-carrier
|
|
13
|
+
state, and at freeze ticks for economy rows.
|
|
15
14
|
- The research-profile duel windows reuse the already-parsed kill/damage ticks
|
|
16
15
|
to compute merged combat windows, then fetch them in ONE lean `parse_ticks`
|
|
17
16
|
call (6 props at full tick) instead of widening the main grid.
|
|
@@ -85,48 +85,6 @@ def _slice_by_tick(df, tick_values, start: int, end: int):
|
|
|
85
85
|
return df.iloc[left:right]
|
|
86
86
|
|
|
87
87
|
|
|
88
|
-
# ── bomb carrier timeline (replaces per-frame inventory parsing) ──────────────
|
|
89
|
-
|
|
90
|
-
def build_bomb_carrier_timeline(raw: dict, players: PlayerDirectory):
|
|
91
|
-
"""(transition_ticks, carrier_pidx) arrays for hasBomb lookups.
|
|
92
|
-
|
|
93
|
-
Derived from bomb lifecycle events: pickup → carrier, dropped/planted/
|
|
94
|
-
exploded/defused → no carrier. This replaces extracting the `inventory`
|
|
95
|
-
tick prop on the whole replay grid, which is the single most expensive
|
|
96
|
-
per-frame property in demoparser2.
|
|
97
|
-
"""
|
|
98
|
-
import numpy as np
|
|
99
|
-
|
|
100
|
-
transitions: list[tuple[int, int]] = [] # (tick, pidx or -1)
|
|
101
|
-
for rows_key, is_pickup in (("bomb_pickup", True), ("bomb_dropped", False),
|
|
102
|
-
("bomb_planted", False), ("bomb_exploded", False),
|
|
103
|
-
("bomb_defused", False)):
|
|
104
|
-
for r in raw.get(rows_key, []):
|
|
105
|
-
tick = int(r.get("tick") or 0)
|
|
106
|
-
if tick <= 0:
|
|
107
|
-
continue
|
|
108
|
-
if is_pickup:
|
|
109
|
-
idx = players.idx(_sid(r.get("user_steamid") or r.get("steamid")))
|
|
110
|
-
transitions.append((tick, idx if idx is not None else -1))
|
|
111
|
-
else:
|
|
112
|
-
transitions.append((tick, -1))
|
|
113
|
-
transitions.sort()
|
|
114
|
-
ticks = np.asarray([t for t, _ in transitions], dtype="int64")
|
|
115
|
-
carrier = np.asarray([c for _, c in transitions], dtype="int64")
|
|
116
|
-
return ticks, carrier
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
def _carrier_at(ticks, carrier, frame_ticks):
|
|
120
|
-
"""Vectorized carrier playerIndex (or -1) at each frame tick."""
|
|
121
|
-
import numpy as np
|
|
122
|
-
|
|
123
|
-
if len(ticks) == 0:
|
|
124
|
-
return np.full(len(frame_ticks), -1, dtype="int64")
|
|
125
|
-
pos = np.searchsorted(ticks, frame_ticks, side="right") - 1
|
|
126
|
-
out = np.where(pos >= 0, carrier[np.clip(pos, 0, None)], -1)
|
|
127
|
-
return out
|
|
128
|
-
|
|
129
|
-
|
|
130
88
|
# ── replay.json ───────────────────────────────────────────────────────────────
|
|
131
89
|
|
|
132
90
|
def build_replay(raw: dict, players: PlayerDirectory, round_model: _RoundModel,
|
|
@@ -155,10 +113,13 @@ def build_replay(raw: dict, players: PlayerDirectory, round_model: _RoundModel,
|
|
|
155
113
|
df["_plidx"] = df["last_place_name"].map(place_map).fillna(-1).astype("int64")
|
|
156
114
|
if "inventory" in df.columns:
|
|
157
115
|
df["_grenades"] = df["inventory"].map(lambda items: classify_inventory(items)[3])
|
|
116
|
+
df["_has_bomb"] = df["inventory"].map(
|
|
117
|
+
lambda items: isinstance(items, (list, tuple))
|
|
118
|
+
and any(normalize_weapon_name(item) == "c4" for item in items)
|
|
119
|
+
)
|
|
158
120
|
else:
|
|
159
121
|
df["_grenades"] = [[] for _ in range(len(df))]
|
|
160
|
-
|
|
161
|
-
bomb_ticks, bomb_carrier = build_bomb_carrier_timeline(raw, players)
|
|
122
|
+
df["_has_bomb"] = False
|
|
162
123
|
tick_values = df["tick"].to_numpy()
|
|
163
124
|
|
|
164
125
|
# projectile trajectories per round
|
|
@@ -190,7 +151,7 @@ def build_replay(raw: dict, players: PlayerDirectory, round_model: _RoundModel,
|
|
|
190
151
|
continue
|
|
191
152
|
player_tracks = []
|
|
192
153
|
for pidx, g in sl.groupby("_pidx", sort=True):
|
|
193
|
-
track = _player_track(g, grid, int(pidx)
|
|
154
|
+
track = _player_track(g, grid, int(pidx))
|
|
194
155
|
if track is not None:
|
|
195
156
|
player_tracks.append(track)
|
|
196
157
|
if not player_tracks:
|
|
@@ -219,7 +180,7 @@ def build_replay(raw: dict, players: PlayerDirectory, round_model: _RoundModel,
|
|
|
219
180
|
}
|
|
220
181
|
|
|
221
182
|
|
|
222
|
-
def _player_track(g, grid, pidx: int
|
|
183
|
+
def _player_track(g, grid, pidx: int) -> dict | None:
|
|
223
184
|
"""One player's columnar track aligned to the round grid.
|
|
224
185
|
|
|
225
186
|
Frames where the player has no row (dead/disconnected) repeat the last
|
|
@@ -260,8 +221,8 @@ def _player_track(g, grid, pidx: int, bomb_ticks, bomb_carrier) -> dict | None:
|
|
|
260
221
|
|
|
261
222
|
alive = (hp > 0).astype("int64")
|
|
262
223
|
has_kit = _num(aligned["has_defuser"], 0.0).to_numpy().astype(bool)
|
|
263
|
-
|
|
264
|
-
has_bomb =
|
|
224
|
+
has_bomb = aligned["_has_bomb"].fillna(False).to_numpy().astype(bool)
|
|
225
|
+
has_bomb = has_bomb & present & (alive == 1)
|
|
265
226
|
flags = (alive * FLAG_ALIVE
|
|
266
227
|
+ has_bomb.astype("int64") * FLAG_HAS_BOMB
|
|
267
228
|
+ (has_kit & present & (alive == 1)).astype("int64") * FLAG_HAS_DEFUSE_KIT)
|
|
@@ -54,6 +54,33 @@ def test_replay_round_extends_to_sample_before_next_round_start():
|
|
|
54
54
|
assert last_tick < 300
|
|
55
55
|
|
|
56
56
|
|
|
57
|
+
def test_replay_marks_round_start_bomb_carrier_from_inventory():
|
|
58
|
+
players = PlayerDirectory([
|
|
59
|
+
{"steamId64": "76561198000000001", "name": "p1", "teamKey": "teamA"},
|
|
60
|
+
])
|
|
61
|
+
round_model = _RoundModel(
|
|
62
|
+
windows=[
|
|
63
|
+
_RoundWindow(round_number=1, start_tick=50, freeze_end_tick=100, end_tick=200),
|
|
64
|
+
_RoundWindow(round_number=2, start_tick=300, freeze_end_tick=360, end_tick=460),
|
|
65
|
+
],
|
|
66
|
+
side_map={},
|
|
67
|
+
)
|
|
68
|
+
rows = [_replay_row(tick) for tick in range(360, 461, 16)]
|
|
69
|
+
for row in rows:
|
|
70
|
+
row["inventory"] = ["C4 Explosive"]
|
|
71
|
+
raw = {
|
|
72
|
+
"replay_df": pd.DataFrame(rows),
|
|
73
|
+
"grenade_trajectories": [],
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
replay = build_replay(raw, players, round_model, tickrate=128, sample_rate=8)
|
|
77
|
+
|
|
78
|
+
assert replay is not None
|
|
79
|
+
second_round = replay["rounds"][0]
|
|
80
|
+
assert second_round["roundNumber"] == 2
|
|
81
|
+
assert all(flags & 2 for flags in second_round["players"][0]["flags"])
|
|
82
|
+
|
|
83
|
+
|
|
57
84
|
def test_parse_replay_ticks_include_post_round_tail_before_next_start():
|
|
58
85
|
round_ends = [
|
|
59
86
|
{"total_rounds_played": 1, "tick": 200},
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|