cs2df 3.0.4__tar.gz → 3.1.1__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.
@@ -1,13 +1,13 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: cs2df
3
- Version: 3.0.4
3
+ Version: 3.1.1
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
7
7
  Project-URL: Issues, https://github.com/Starfie1d1272/cs2-demo-format/issues
8
8
  License: MIT
9
9
  Requires-Python: >=3.11
10
- Requires-Dist: demoparser2>=0.41.2
10
+ Requires-Dist: demoparser2>=0.42.2
11
11
  Requires-Dist: jsonschema>=4.21
12
12
  Requires-Dist: numpy>=1.26
13
13
  Requires-Dist: orjson>=3.9
@@ -1,12 +1,12 @@
1
1
  [project]
2
2
  name = "cs2df"
3
- version = "3.0.4"
3
+ version = "3.1.1"
4
4
  description = "Reference exporter & validator CLI for cs2-demo-format v3 (CS2 demo → ZIP data package)"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.11"
7
7
  license = { text = "MIT" }
8
8
  dependencies = [
9
- "demoparser2>=0.41.2",
9
+ "demoparser2>=0.42.2",
10
10
  "pandas>=2.0",
11
11
  "numpy>=1.26",
12
12
  "orjson>=3.9",
@@ -5,7 +5,7 @@ demoparser2 / pandas stack installed. Heavy imports are deferred into the
5
5
  submodules that need them.
6
6
  """
7
7
 
8
- __version__ = "3.0.4"
8
+ __version__ = "3.1.1"
9
9
 
10
10
  SCHEMA_VERSION = "cs2-demo-format/3.0"
11
11
  EXPORTER_NAME = "cs2df"
@@ -12,6 +12,7 @@ import argparse
12
12
  import builtins
13
13
  import json
14
14
  import os
15
+ import re
15
16
  import sys
16
17
  import time
17
18
  from concurrent.futures import ProcessPoolExecutor, as_completed
@@ -27,7 +28,9 @@ def main(argv: list[str] | None = None) -> int:
27
28
  sub = parser.add_subparsers(dest="command", required=True)
28
29
 
29
30
  p_exp = sub.add_parser("export", help="export a CS2 .dem to a v3 ZIP package")
30
- p_exp.add_argument("demo", help="path to the .dem file")
31
+ p_exp.add_argument("demo", nargs="+",
32
+ help="path to the .dem file; pass multiple split parts "
33
+ "(…-p1.dem …-p2.dem) of ONE match to merge them")
31
34
  p_exp.add_argument("-o", "--output", default=None,
32
35
  help="output zip path (default: <demo>.zip next to the input)")
33
36
  p_exp.add_argument("--research", action="store_true",
@@ -78,16 +81,20 @@ def main(argv: list[str] | None = None) -> int:
78
81
 
79
82
 
80
83
  def _cmd_export(args) -> int:
81
- from .package import export_demo
84
+ from .package import export_demo_merged
82
85
 
83
- dem = Path(args.demo)
84
- if not dem.exists():
85
- print(f"ERROR: demo not found: {dem}", file=sys.stderr)
86
+ dems = [Path(d) for d in args.demo]
87
+ missing = [str(d) for d in dems if not d.exists()]
88
+ if missing:
89
+ print(f"ERROR: demo not found: {', '.join(missing)}", file=sys.stderr)
86
90
  return 1
87
91
  if not _compress_level_ok(args.compress_level):
88
92
  print("ERROR: --compress-level must be between 0 and 9", file=sys.stderr)
89
93
  return 1
90
- out = Path(args.output) if args.output else dem.with_suffix(".zip")
94
+ # 多段合并时输出名去掉 -pN 后缀,落到第一段同目录。
95
+ first = dems[0]
96
+ default_stem = re.sub(r"-p\d+$", "", first.stem)
97
+ out = Path(args.output) if args.output else first.with_name(default_stem + ".zip")
91
98
 
92
99
  t0 = time.perf_counter()
93
100
  progress = None
@@ -95,12 +102,14 @@ def _cmd_export(args) -> int:
95
102
  def progress(stage: str, frac: float) -> None:
96
103
  print(f" [{frac * 100:5.1f}%] {stage}")
97
104
 
98
- data, _match_meta = export_demo(str(dem), research=args.research,
99
- sample_rate=args.sample_rate,
100
- window_before_ms=args.window_before,
101
- window_after_ms=args.window_after,
102
- compress_level=args.compress_level,
103
- progress=progress)
105
+ if len(dems) > 1:
106
+ print(f"合并 {len(dems)} 段 → {out.name}")
107
+ data, _match_meta = export_demo_merged([str(d) for d in dems], research=args.research,
108
+ sample_rate=args.sample_rate,
109
+ window_before_ms=args.window_before,
110
+ window_after_ms=args.window_after,
111
+ compress_level=args.compress_level,
112
+ progress=progress)
104
113
  out.write_bytes(data)
105
114
  dt = time.perf_counter() - t0
106
115
  print(f"wrote {out} ({len(data) / 1e6:.2f} MB) in {dt:.1f}s")
@@ -160,7 +160,13 @@ def build_players(raw: dict) -> PlayerDirectory:
160
160
  if not sid or sid in seen or not _is_valid_steamid(sid):
161
161
  continue
162
162
  seen.add(sid)
163
- team_key = team_num_to_key.get(int(r.get("team_num") or 0))
163
+ # team_num 可能为 NaN(polars float 缺失列)——典型是有合法 steamid 但无队伍的
164
+ # 教练/观察员。注意 NaN 在 Python 中为真值,`NaN or 0` 仍是 NaN,int(NaN) 会抛
165
+ # ValueError,必须显式判 None/NaN 后跳过(等价于无 teamKey)。
166
+ tn = r.get("team_num")
167
+ if tn is None or tn != tn:
168
+ continue
169
+ team_key = team_num_to_key.get(int(tn))
164
170
  if not team_key:
165
171
  continue
166
172
  out.append({"steamId64": sid, "name": str(r.get("name") or sid), "teamKey": team_key})
@@ -266,7 +272,7 @@ def build_damages(raw: dict, players: PlayerDirectory, round_model: _RoundModel)
266
272
  remaining_health: dict[tuple[int, int], int] = defaultdict(lambda: 100)
267
273
 
268
274
  for r in sorted(raw.get("hurts", []), key=lambda row: int(row.get("tick") or 0)):
269
- n = round_model.round_for_event(r)
275
+ n = _active_event_round_number(round_model, r)
270
276
  if n is None:
271
277
  continue
272
278
  vic_sid = _sid(r.get("user_steamid"))
@@ -313,7 +319,7 @@ def build_blinds(raw: dict, players: PlayerDirectory, round_model: _RoundModel,
313
319
  flash_lookup = flash_lookup or {}
314
320
  out = []
315
321
  for r in raw.get("blinds", []):
316
- n = round_model.round_for_event(r)
322
+ n = _active_event_round_number(round_model, r)
317
323
  if n is None:
318
324
  continue
319
325
  flasher_sid = _sid(r.get("attacker_steamid"))
@@ -0,0 +1,189 @@
1
+ """Merge split GOTV recordings of ONE match into a single parse_demo() output.
2
+
3
+ HLTV occasionally splits one match's GOTV demo into parts (``…-p1.dem``,
4
+ ``…-p2.dem``). Across parts the round COUNTER is global (part 2 already starts at
5
+ round 3), but the TICK clock restarts from ~0 in every file. We therefore:
6
+
7
+ 1. parse each part with :func:`cs2df.parse.parse_demo`;
8
+ 2. shift every tick in each later part past the previous parts' span, so the
9
+ merged timeline is strictly monotonic (within-part tick deltas — and thus
10
+ reaction times, round spans, duel windows — are preserved by a constant shift);
11
+ 3. concatenate the event streams and per-frame DataFrames;
12
+ 4. keep match metadata / roster from the first part (the true match start).
13
+
14
+ The merged dict has the exact shape :func:`parse_demo` returns, so
15
+ :func:`cs2df.package.build_package` re-derives coherent per-match artifacts
16
+ (player-stats, clutches, …) over the union — no per-artifact merge logic needed.
17
+ """
18
+
19
+ from __future__ import annotations
20
+
21
+ from typing import Any
22
+
23
+ # Metadata / roster taken from the first part, never shifted or concatenated.
24
+ _META_FIRST = {
25
+ "_timings", "header", "tickrate", "sample_rate", "match_start_tick",
26
+ "team_a_name", "team_b_name", "player_info",
27
+ }
28
+ # Event lists: list[dict]; shift any of these tick-bearing keys present on a row.
29
+ _EVENT_LISTS = {
30
+ "round_starts", "round_freeze_ends", "round_ends",
31
+ "deaths", "hurts", "fires", "blinds",
32
+ "bomb_planted", "bomb_defused", "bomb_exploded", "bomb_beginplant",
33
+ "bomb_begindefuse", "bomb_dropped", "bomb_pickup",
34
+ "grenade_detonations", "inferno_expires", "smoke_expires",
35
+ "grenade_throws", "grenade_trajectories",
36
+ "round_side_samples", "economy_raw",
37
+ }
38
+ _ROW_TICK_KEYS = ("tick", "destroy_tick", "start_tick")
39
+ # Round-structure lists are ownership-filtered, never tick-trimmed; the rest are
40
+ # combat/effect events that get trimmed of a resumed part's pre-live residue.
41
+ _ROUND_LISTS = {"round_starts", "round_freeze_ends", "round_ends"}
42
+ _DF_KEYS = {"fire_velocity_df", "replay_df", "duel_df"}
43
+ _INT_TICK_LISTS = {"replay_ticks", "freeze_ticks"}
44
+ _WINDOW_LISTS = {"duel_windows"} # list[tuple[start, end]]
45
+
46
+ # Inter-part gap, in seconds, inserted between segments so spans never touch.
47
+ _GAP_SECONDS = 8
48
+
49
+
50
+ def _round_of(row: dict[str, Any], is_end: bool) -> int:
51
+ """Actual round number for a round_* event from its total_rounds_played.
52
+
53
+ total_rounds_played at round_end == that round's number; at round_start /
54
+ round_freeze_end it is N-1 for round N. Mirrors cs2df.rounds._rn semantics.
55
+ """
56
+ trp = int(row.get("total_rounds_played") or 0)
57
+ return trp if is_end else trp + 1
58
+
59
+
60
+ def _max_tick(raw: dict[str, Any]) -> int:
61
+ """Largest tick observed in a part (used to compute the next part's offset)."""
62
+ cands = [0]
63
+ for key in ("round_ends", "round_freeze_ends", "grenade_throws"):
64
+ for row in raw.get(key) or []:
65
+ for tk in ("tick", "destroy_tick"):
66
+ v = row.get(tk)
67
+ if isinstance(v, (int, float)) and v > 0:
68
+ cands.append(int(v))
69
+ for key in _INT_TICK_LISTS:
70
+ cands.extend(int(t) for t in (raw.get(key) or []) if t)
71
+ for key in _DF_KEYS:
72
+ df = raw.get(key)
73
+ if df is not None and hasattr(df, "columns") and "tick" in getattr(df, "columns", []) and len(df):
74
+ cands.append(int(df["tick"].max()))
75
+ return max(cands)
76
+
77
+
78
+ def _shift_part(raw: dict[str, Any], off: int) -> None:
79
+ """Add ``off`` to every tick in ``raw`` in place (off == 0 → no-op)."""
80
+ if off == 0:
81
+ return
82
+ for key in _EVENT_LISTS:
83
+ for row in raw.get(key) or []:
84
+ for tk in _ROW_TICK_KEYS:
85
+ v = row.get(tk)
86
+ if isinstance(v, (int, float)) and v > 0:
87
+ row[tk] = int(v) + off
88
+ for key in _DF_KEYS:
89
+ df = raw.get(key)
90
+ if df is not None and hasattr(df, "columns") and "tick" in getattr(df, "columns", []):
91
+ df = df.copy()
92
+ df["tick"] = df["tick"] + off
93
+ raw[key] = df
94
+ for key in _INT_TICK_LISTS:
95
+ lst = raw.get(key)
96
+ if lst:
97
+ raw[key] = [int(t) + off for t in lst]
98
+ for key in _WINDOW_LISTS:
99
+ lst = raw.get(key)
100
+ if lst:
101
+ raw[key] = [(int(s) + off, int(e) + off) for s, e in lst]
102
+
103
+
104
+ def merge_raw(parts: list[dict[str, Any]]) -> dict[str, Any]:
105
+ """Merge per-part parse_demo() outputs into one (parts in play order)."""
106
+ if not parts:
107
+ raise ValueError("merge_raw: no parts")
108
+ if len(parts) == 1:
109
+ return parts[0]
110
+
111
+ # 1. shift each part past the previous parts' span.
112
+ running = 0
113
+ for part in parts:
114
+ _shift_part(part, running)
115
+ running += _max_tick(part) + part.get("tickrate", 64) * _GAP_SECONDS
116
+
117
+ # 1b. round ownership: a part only owns rounds past the previous parts'. When a
118
+ # GOTV recording resumes it re-emits a few warmup/restart round_* events with low
119
+ # total_rounds_played; those would collide in build_rounds' per-round tick maps
120
+ # (e.g. overwriting an earlier part's freeze tick and getting the seam round
121
+ # dropped as bogus). Drop each later part's round_* events for already-owned rounds.
122
+ prev_max = 0
123
+ for idx, part in enumerate(parts):
124
+ if idx > 0:
125
+ for key, is_end in (("round_ends", True), ("round_starts", False),
126
+ ("round_freeze_ends", False)):
127
+ rows = part.get(key) or []
128
+ part[key] = [r for r in rows if _round_of(r, is_end) > prev_max]
129
+ # Trim combat/effect residue captured before this part's first live round
130
+ # (a resume starts mid-freeze and re-emits seam events the previous part
131
+ # already owns). Threshold = first owned round's freeze-end tick.
132
+ freezes = [int(r.get("tick") or 0) for r in part.get("round_freeze_ends") or []
133
+ if int(r.get("tick") or 0) > 0]
134
+ trim_before = min(freezes) if freezes else 0
135
+ if trim_before > 0:
136
+ for key in _EVENT_LISTS - _ROUND_LISTS:
137
+ rows = part.get(key) or []
138
+ part[key] = [r for r in rows
139
+ if not (0 < int(r.get("tick") or 0) < trim_before)]
140
+ ends = part.get("round_ends") or []
141
+ if ends:
142
+ prev_max = max([prev_max] + [_round_of(r, True) for r in ends])
143
+
144
+ # 2. assemble the merged dict.
145
+ merged: dict[str, Any] = {}
146
+ base = parts[0]
147
+ for key in _META_FIRST:
148
+ if key in base:
149
+ merged[key] = base[key]
150
+
151
+ for key in _EVENT_LISTS:
152
+ out: list[Any] = []
153
+ for part in parts:
154
+ out.extend(part.get(key) or [])
155
+ merged[key] = out
156
+
157
+ import pandas as pd # lazy: native dep
158
+ for key in _DF_KEYS:
159
+ frames = [part[key] for part in parts
160
+ if part.get(key) is not None and len(part[key])]
161
+ merged[key] = pd.concat(frames, ignore_index=True) if frames else base.get(key)
162
+
163
+ for key in _INT_TICK_LISTS:
164
+ seen: set[int] = set()
165
+ for part in parts:
166
+ seen.update(int(t) for t in (part.get(key) or []))
167
+ merged[key] = sorted(seen)
168
+
169
+ for key in _WINDOW_LISTS:
170
+ out_w: list[Any] = []
171
+ for part in parts:
172
+ out_w.extend(part.get(key) or [])
173
+ merged[key] = out_w
174
+
175
+ return merged
176
+
177
+
178
+ def parse_and_merge(dem_paths: list[str], **parse_kwargs: Any) -> dict[str, Any]:
179
+ """Parse each part with parse_demo() and merge into one raw dict."""
180
+ from .parse import parse_demo
181
+ progress = parse_kwargs.pop("progress", None)
182
+ n = len(dem_paths)
183
+ parts: list[dict[str, Any]] = []
184
+ for i, path in enumerate(dem_paths):
185
+ def _scaled(stage: str, frac: float, _i=i) -> None:
186
+ if progress is not None:
187
+ progress(f"[part {_i + 1}/{n}] {stage}", (_i + frac) / n)
188
+ parts.append(parse_demo(path, progress=_scaled if progress else None, **parse_kwargs))
189
+ return merge_raw(parts)
@@ -65,6 +65,42 @@ def export_demo(dem_path: str, *, research: bool = False, sample_rate: int = 8,
65
65
  compress_level=compress_level)
66
66
 
67
67
 
68
+ def export_demo_merged(dem_paths: list[str], *, research: bool = False, sample_rate: int = 8,
69
+ window_before_ms: int = 2000, window_after_ms: int = 1000,
70
+ compress_level: int = 3,
71
+ progress: ProgressFn | None = None) -> tuple[bytes, dict]:
72
+ """Parse several split GOTV parts of ONE match, merge, and build a single ZIP.
73
+
74
+ Use for HLTV demos split into ``…-p1.dem`` / ``…-p2.dem``: ticks are reconciled
75
+ onto a global timeline so the package's per-match derivations stay coherent.
76
+ """
77
+ if len(dem_paths) == 1:
78
+ return export_demo(dem_paths[0], research=research, sample_rate=sample_rate,
79
+ window_before_ms=window_before_ms, window_after_ms=window_after_ms,
80
+ compress_level=compress_level, progress=progress)
81
+ from .merge import parse_and_merge
82
+
83
+ # Combined hash over all parts, in order, so the merged package has a stable id.
84
+ try:
85
+ h = hashlib.sha256()
86
+ for part in dem_paths:
87
+ h.update(_sha256_hex(part).encode("ascii"))
88
+ demo_hash: str | None = h.hexdigest()
89
+ except Exception:
90
+ demo_hash = None
91
+
92
+ scaled = (lambda stage, frac: progress(stage, frac * 0.9)) if progress else None
93
+ raw = parse_and_merge(list(dem_paths), sample_rate=sample_rate, research=research,
94
+ window_before_ms=window_before_ms,
95
+ window_after_ms=window_after_ms, progress=scaled)
96
+ if progress:
97
+ progress("build package", 0.92)
98
+ return build_package(raw, dem_paths[0], demo_hash,
99
+ window_before_ms=window_before_ms,
100
+ window_after_ms=window_after_ms,
101
+ compress_level=compress_level)
102
+
103
+
68
104
  def build_package(raw: dict[str, Any], dem_path: str, demo_hash: str | None, *,
69
105
  window_before_ms: int = 2000, window_after_ms: int = 1000,
70
106
  compress_level: int = 3) -> tuple[bytes, dict]:
@@ -25,6 +25,8 @@ import logging
25
25
  import time
26
26
  from typing import TYPE_CHECKING, Any, Callable
27
27
 
28
+ from .rounds import _resolve_round_attempts
29
+
28
30
  if TYPE_CHECKING:
29
31
  import pandas as pd
30
32
  from demoparser2 import DemoParser # type: ignore
@@ -433,43 +435,24 @@ def parse_demo(dem_path: str, *, sample_rate: int = 8, research: bool = False,
433
435
 
434
436
  # ── sampling grids ────────────────────────────────────────────────────────────
435
437
 
436
- def _freeze_by_round(round_freeze_ends: list[dict]) -> dict[int, int]:
437
- """total_rounds_played at round_freeze_end = N-1 for round N."""
438
- out: dict[int, int] = {}
439
- for r in round_freeze_ends:
440
- rn = int(r.get("total_rounds_played") or 0) + 1
441
- t = int(r.get("tick") or 0)
442
- if rn > 0 and t > 0:
443
- out[rn] = t
444
- return out
445
-
446
-
447
- def _round_starts_by_round(round_starts: list[dict]) -> dict[int, int]:
448
- out: dict[int, int] = {}
449
- for r in round_starts:
450
- rn = int(r.get("total_rounds_played") or 0) + 1
451
- t = int(r.get("tick") or 0)
452
- if rn > 0 and t > 0 and rn not in out:
453
- out[rn] = t
454
- return out
455
-
456
438
 
457
- def _round_spans(round_ends: list[dict],
458
- round_freeze_ends: list[dict],
459
- round_starts: list[dict] | None = None) -> list[tuple[int, int]]:
439
+ def _round_spans(
440
+ round_ends: list[dict],
441
+ round_freeze_ends: list[dict],
442
+ round_starts: list[dict],
443
+ ) -> list[tuple[int, int]]:
460
444
  """[(freeze_end_tick, event_end_tick)] for rounds with a valid window."""
461
- freeze = _freeze_by_round(round_freeze_ends)
462
- starts = _round_starts_by_round(round_starts or [])
463
- spans: list[tuple[int, int]] = []
464
- for r in round_ends:
465
- rn = int(r.get("total_rounds_played") or 0)
466
- end_t = int(r.get("tick") or 0)
467
- next_start_t = starts.get(rn + 1)
468
- event_end_t = next_start_t - 1 if next_start_t is not None else end_t
469
- start_t = freeze.get(rn, 0)
470
- if start_t > 0 and event_end_t > start_t:
471
- spans.append((start_t, event_end_t))
472
- return spans
445
+ attempts = _resolve_round_attempts(round_starts, round_freeze_ends, round_ends)
446
+ return [
447
+ (
448
+ window.freeze_end_tick,
449
+ window.next_start_tick - 1
450
+ if window.next_start_tick is not None and index < len(attempts) - 1
451
+ else window.end_tick,
452
+ )
453
+ for index, (window, _, _) in enumerate(attempts)
454
+ if window.freeze_end_tick > 0
455
+ ]
473
456
 
474
457
 
475
458
  def _build_sample_ticks(round_ends: list[dict], round_freeze_ends: list[dict],
@@ -48,6 +48,7 @@ class _RoundWindow:
48
48
  start_tick: int
49
49
  freeze_end_tick: int
50
50
  end_tick: int
51
+ next_start_tick: int | None = None
51
52
 
52
53
 
53
54
  @dataclass
@@ -69,6 +70,8 @@ class _RoundModel:
69
70
  self._event_end_by_round = {}
70
71
  for i, window in enumerate(ordered):
71
72
  next_start = ordered[i + 1].start_tick if i + 1 < len(ordered) else None
73
+ if next_start is not None and window.next_start_tick is not None:
74
+ next_start = min(next_start, window.next_start_tick)
72
75
  self._event_end_by_round[window.round_number] = (
73
76
  next_start - 1 if next_start is not None else window.end_tick
74
77
  )
@@ -113,9 +116,60 @@ def _event_steamid(row: dict) -> str | None:
113
116
 
114
117
  # ── round builder ──────────────────────────────────────────────────────────────
115
118
 
116
- def build_rounds(
117
- raw: dict, team_map: dict[str, str]
118
- ) -> tuple[list[dict], _RoundModel]:
119
+
120
+ def _resolve_round_attempts(
121
+ round_starts: list[dict], round_freeze_ends: list[dict], round_ends: list[dict]
122
+ ) -> list[tuple[_RoundWindow, dict, str]]:
123
+ """Pair scoring ends with their own start and freeze-end in tick order."""
124
+ markers = [
125
+ (int(row.get("tick") or 0), kind, row)
126
+ for kind, rows in enumerate((round_starts, round_freeze_ends, round_ends))
127
+ for row in rows
128
+ if int(row.get("tick") or 0) > 0
129
+ ]
130
+ markers.sort(key=lambda marker: (marker[0], marker[1]))
131
+ demo_starts = [tick for tick, kind, _ in markers if kind == 0]
132
+ starts: dict[int, int] = {}
133
+ freezes: dict[int, int] = {}
134
+ completed: dict[int, tuple[_RoundWindow, dict, str]] = {}
135
+ for tick, kind, row in markers:
136
+ number = _rn(row) + (kind != 2)
137
+ if number <= 0:
138
+ continue
139
+ if kind == 0:
140
+ if starts.get(number) == tick:
141
+ continue
142
+ # A start at an already-scored round invalidates that score and
143
+ # the rest of the old timeline from that round onward.
144
+ for rolled_back in [n for n in completed if n >= number]:
145
+ del completed[rolled_back]
146
+ starts.pop(rolled_back, None)
147
+ freezes.pop(rolled_back, None)
148
+ starts[number] = tick
149
+ freezes.pop(number, None)
150
+ elif kind == 1:
151
+ freezes[number] = tick
152
+ else:
153
+ winner = str(row.get("winner") or "").lower()
154
+ if winner not in ("t", "2", "ct", "3"):
155
+ # Restart markers can report the previous completed round
156
+ # number even though they do not represent a scoring end.
157
+ continue
158
+ freeze = freezes.get(number, 0)
159
+ if tick <= freeze:
160
+ continue
161
+ next_index = bisect.bisect_right(demo_starts, tick)
162
+ next_start = (
163
+ demo_starts[next_index] if next_index < len(demo_starts) else None
164
+ )
165
+ window = _RoundWindow(
166
+ number, starts.get(number, 0), freeze, tick, next_start
167
+ )
168
+ completed[number] = (window, row, "t" if winner in ("t", "2") else "ct")
169
+ return [completed[number] for number in sorted(completed)]
170
+
171
+
172
+ def build_rounds(raw: dict, team_map: dict[str, str]) -> tuple[list[dict], _RoundModel]:
119
173
  """Return (rounds_list, side_map) from raw demoparser2 output.
120
174
 
121
175
  side_map[(roundNumber, teamKey)] = "t" | "ct"
@@ -124,120 +178,51 @@ def build_rounds(
124
178
  (rounds completed so far), so we store at actual_round = n + 1.
125
179
  total_rounds_played at round_end = N (the round that just completed).
126
180
  """
127
- freeze_tick: dict[int, int] = {}
128
- for r in raw.get("round_freeze_ends", []):
129
- n = _rn(r)
130
- t = int(r.get("tick") or 0)
131
- actual_round = n + 1
132
- if actual_round > 0 and t > 0:
133
- freeze_tick[actual_round] = t
134
-
135
- start_tick: dict[int, int] = {}
136
- for r in raw.get("round_starts", []):
137
- n = _rn(r)
138
- t = int(r.get("tick") or 0)
139
- actual_round = n + 1
140
- if actual_round > 0 and t > 0 and actual_round not in start_tick:
141
- start_tick[actual_round] = t
142
-
143
181
  team_a_score = 0
144
182
  team_b_score = 0
145
183
  out: list[dict] = []
146
184
  side_map: dict[tuple[int, str], str] = {}
147
185
  windows: list[_RoundWindow] = []
148
186
 
149
- # A single round can emit multiple round_end events (e.g. a bogus warmup /
150
- # restart end fired before the real one). Keep only the latest-tick end per
151
- # round number so the same round is never counted twice.
152
- best_by_round: dict[int, dict] = {}
153
- for r in raw.get("round_ends", []):
154
- n = _rn(r)
155
- if n <= 0:
156
- continue
157
- prev = best_by_round.get(n)
158
- if prev is None or int(r.get("tick") or 0) > int(prev.get("tick") or 0):
159
- best_by_round[n] = r
160
- round_ends_sorted = [best_by_round[n] for n in sorted(best_by_round)]
161
-
162
- for r in round_ends_sorted:
163
- n = _rn(r)
164
- if n <= 0:
165
- continue
166
-
167
- end_tick = int(r.get("tick") or 0)
168
- s_tick = start_tick.get(n, 0)
169
- fz_tick = freeze_tick.get(n, 0)
170
-
171
- # A real round must end after its own freeze period; an end at or before
172
- # freeze-end is a bogus warmup/restart event — drop it (don't score it).
173
- if fz_tick > 0 and 0 < end_tick <= fz_tick:
174
- continue
175
-
187
+ attempts = _resolve_round_attempts(
188
+ raw.get("round_starts", []),
189
+ raw.get("round_freeze_ends", []),
190
+ raw.get("round_ends", []),
191
+ )
192
+ for window, end, winner_side in attempts:
193
+ n = window.round_number
194
+ fz_tick = window.freeze_end_tick
176
195
  team_a_side, team_b_side = _sides_for_round(raw, team_map, n, fz_tick)
177
196
  side_map[(n, "teamA")] = team_a_side
178
197
  side_map[(n, "teamB")] = team_b_side
179
-
180
- # v2: startTick, freezeEndTick, endTick must all be >= 1
181
- if s_tick <= 0 or fz_tick <= 0 or end_tick <= 0:
182
- winner_raw = str(r.get("winner") or "").lower()
183
- if winner_raw in ("t", "2"):
184
- winner_key = "teamA" if team_a_side == "t" else "teamB"
185
- elif winner_raw in ("ct", "3"):
186
- winner_key = "teamA" if team_a_side == "ct" else "teamB"
187
- else:
188
- winner_key = None
189
-
190
- if winner_key == "teamA":
191
- team_a_score += 1
192
- elif winner_key == "teamB":
193
- team_b_score += 1
194
- continue
195
-
196
- winner_raw = str(r.get("winner") or "").lower()
197
- if winner_raw in ("t", "2"):
198
- winner_side = "t"
199
- winner_key = "teamA" if team_a_side == "t" else "teamB"
200
- elif winner_raw in ("ct", "3"):
201
- winner_side = "ct"
202
- winner_key = "teamA" if team_a_side == "ct" else "teamB"
203
- else:
204
- winner_side = None
205
- winner_key = None
206
-
207
- if not winner_key or not winner_side:
208
- continue
209
-
210
- end_reason = normalize_round_end_reason(r.get("reason"))
211
-
212
- out.append({
213
- "roundNumber": n,
214
- "startTick": s_tick,
215
- "freezeEndTick": fz_tick,
216
- "endTick": end_tick,
217
- "teamASide": team_a_side,
218
- "teamBSide": team_b_side,
219
- "teamAScoreBefore": team_a_score,
220
- "teamBScoreBefore": team_b_score,
221
- "teamAEconomy": None,
222
- "teamBEconomy": None,
223
- "winnerTeamKey": winner_key,
224
- "winnerSide": winner_side,
225
- "endReason": end_reason,
226
- })
227
- windows.append(_RoundWindow(n, s_tick, fz_tick, end_tick))
198
+ winner_key = "teamA" if team_a_side == winner_side else "teamB"
199
+
200
+ # Keep the score for partial recordings even if a round has no window.
201
+ if window.start_tick > 0 and fz_tick > 0:
202
+ out.append(
203
+ {
204
+ "roundNumber": n,
205
+ "startTick": window.start_tick,
206
+ "freezeEndTick": fz_tick,
207
+ "endTick": window.end_tick,
208
+ "teamASide": team_a_side,
209
+ "teamBSide": team_b_side,
210
+ "teamAScoreBefore": team_a_score,
211
+ "teamBScoreBefore": team_b_score,
212
+ "teamAEconomy": "semi",
213
+ "teamBEconomy": "semi",
214
+ "winnerTeamKey": winner_key,
215
+ "winnerSide": winner_side,
216
+ "endReason": normalize_round_end_reason(end.get("reason")),
217
+ }
218
+ )
219
+ windows.append(window)
228
220
 
229
221
  if winner_key == "teamA":
230
222
  team_a_score += 1
231
- elif winner_key == "teamB":
223
+ else:
232
224
  team_b_score += 1
233
225
 
234
- # Replace any None economy with "semi"
235
- for rd in out:
236
- if rd["teamAEconomy"] is None:
237
- rd["teamAEconomy"] = "semi"
238
- if rd["teamBEconomy"] is None:
239
- rd["teamBEconomy"] = "semi"
240
-
241
226
  return out, _RoundModel(windows=windows, side_map=side_map)
242
227
 
243
228
 
@@ -140,10 +140,11 @@ def build_replay(raw: dict, players: PlayerDirectory, round_model: _RoundModel,
140
140
 
141
141
  rounds_out: list[dict] = []
142
142
  windows = sorted(round_model.windows, key=lambda w: w.round_number)
143
- for i, w in enumerate(windows):
144
- next_start_tick = windows[i + 1].start_tick if i + 1 < len(windows) else None
145
- stop_tick = next_start_tick if next_start_tick is not None else w.end_tick + 1
146
- grid = np.arange(w.freeze_end_tick, stop_tick, step, dtype="int64")
143
+ for w in windows:
144
+ event_end_tick = round_model.event_end_tick(w.round_number)
145
+ if event_end_tick is None:
146
+ continue
147
+ grid = np.arange(w.freeze_end_tick, event_end_tick + 1, step, dtype="int64")
147
148
  if len(grid) == 0:
148
149
  continue
149
150
  sl = _slice_by_tick(df, tick_values, int(grid[0]), int(grid[-1]))
@@ -0,0 +1,68 @@
1
+ from __future__ import annotations
2
+
3
+ from cs2df.merge import merge_raw
4
+
5
+
6
+ def _part(tickrate, round_ends, round_starts, round_freeze_ends, hurts):
7
+ return {
8
+ "tickrate": tickrate,
9
+ "round_ends": round_ends,
10
+ "round_starts": round_starts,
11
+ "round_freeze_ends": round_freeze_ends,
12
+ "hurts": hurts,
13
+ "deaths": [],
14
+ }
15
+
16
+
17
+ def test_merge_two_parts_keeps_seam_round_shifts_ticks_and_trims_residue():
18
+ # Part 0 owns rounds 1-2 (total_rounds_played: end == round number).
19
+ part0 = _part(
20
+ 64,
21
+ round_ends=[{"total_rounds_played": 1, "tick": 200},
22
+ {"total_rounds_played": 2, "tick": 460}],
23
+ round_starts=[{"total_rounds_played": 0, "tick": 50},
24
+ {"total_rounds_played": 1, "tick": 300}],
25
+ round_freeze_ends=[{"total_rounds_played": 0, "tick": 100},
26
+ {"total_rounds_played": 1, "tick": 360}],
27
+ hurts=[{"tick": 150}, {"tick": 400}],
28
+ )
29
+ # Part 1 owns rounds 3-4 with a LOCAL tick clock (restarts near 0) and resume
30
+ # residue: spurious low-trp round_* events (actual round 2, already owned) plus a
31
+ # phantom hurt at the very first tick.
32
+ part1 = _part(
33
+ 64,
34
+ round_ends=[{"total_rounds_played": 2, "tick": 1}, # spurious (round 2)
35
+ {"total_rounds_played": 3, "tick": 200},
36
+ {"total_rounds_played": 4, "tick": 460}],
37
+ round_starts=[{"total_rounds_played": 1, "tick": 2}, # spurious (round 2)
38
+ {"total_rounds_played": 2, "tick": 5},
39
+ {"total_rounds_played": 3, "tick": 300}],
40
+ round_freeze_ends=[{"total_rounds_played": 1, "tick": 3}, # spurious
41
+ {"total_rounds_played": 2, "tick": 60},
42
+ {"total_rounds_played": 3, "tick": 360}],
43
+ hurts=[{"tick": 4}, {"tick": 120}, {"tick": 400}], # tick 4 == resume residue
44
+ )
45
+
46
+ merged = merge_raw([part0, part1])
47
+
48
+ # Seam round 2 survives; rounds are 1..4 with no gap/duplicate.
49
+ end_rounds = [int(r["total_rounds_played"]) for r in merged["round_ends"]]
50
+ assert end_rounds == [1, 2, 3, 4]
51
+
52
+ # Round ticks are strictly monotonic across the seam (part 1 shifted past part 0).
53
+ end_ticks = [r["tick"] for r in merged["round_ends"]]
54
+ assert end_ticks == sorted(end_ticks) and len(set(end_ticks)) == len(end_ticks)
55
+ assert end_ticks[1] < end_ticks[2] # part0's round 2 < part1's round 3
56
+
57
+ # Resume residue (the tick-4 phantom hurt) is trimmed; the 4 real hurts remain.
58
+ assert len(merged["hurts"]) == 4
59
+ # No hurt sits in the dead gap between part0's last tick and part1's first live round.
60
+ assert all(h["tick"] <= 460 or h["tick"] >= end_ticks[1] for h in merged["hurts"])
61
+
62
+
63
+ def test_single_part_passthrough():
64
+ part = _part(64, [{"total_rounds_played": 1, "tick": 200}],
65
+ [{"total_rounds_played": 0, "tick": 50}],
66
+ [{"total_rounds_played": 0, "tick": 100}],
67
+ [{"tick": 150}])
68
+ assert merge_raw([part]) is part
@@ -83,8 +83,8 @@ def test_replay_marks_round_start_bomb_carrier_from_inventory():
83
83
 
84
84
  def test_parse_replay_ticks_include_post_round_tail_before_next_start():
85
85
  round_ends = [
86
- {"total_rounds_played": 1, "tick": 200},
87
- {"total_rounds_played": 2, "tick": 460},
86
+ {"total_rounds_played": 1, "tick": 200, "winner": "t"},
87
+ {"total_rounds_played": 2, "tick": 460, "winner": "ct"},
88
88
  ]
89
89
  round_freeze_ends = [
90
90
  {"total_rounds_played": 0, "tick": 100},
@@ -0,0 +1,136 @@
1
+ from __future__ import annotations
2
+
3
+ from cs2df.events import PlayerDirectory, build_damages, build_kills
4
+ from cs2df.parse import _build_sample_ticks
5
+ from cs2df.rounds import _RoundModel, _RoundWindow, build_rounds
6
+
7
+
8
+ def test_round_for_tick_assigns_post_round_tail_to_previous_round():
9
+ round_model = _RoundModel(
10
+ windows=[
11
+ _RoundWindow(round_number=1, start_tick=50, freeze_end_tick=100, end_tick=200),
12
+ _RoundWindow(round_number=2, start_tick=300, freeze_end_tick=360, end_tick=460),
13
+ ],
14
+ side_map={},
15
+ )
16
+
17
+ assert round_model.round_for_tick(200) == 1
18
+ assert round_model.round_for_tick(250) == 1
19
+ assert round_model.round_for_tick(299) == 1
20
+ assert round_model.round_for_tick(300) == 2
21
+
22
+
23
+ def test_kills_after_round_end_before_next_start_are_kept_in_previous_round():
24
+ players = PlayerDirectory([
25
+ {"steamId64": "76561198000000001", "name": "attacker", "teamKey": "teamA"},
26
+ {"steamId64": "76561198000000002", "name": "victim", "teamKey": "teamB"},
27
+ ])
28
+ round_model = _RoundModel(
29
+ windows=[
30
+ _RoundWindow(round_number=1, start_tick=50, freeze_end_tick=100, end_tick=200),
31
+ _RoundWindow(round_number=2, start_tick=300, freeze_end_tick=360, end_tick=460),
32
+ ],
33
+ side_map={(1, "teamA"): "t", (1, "teamB"): "ct"},
34
+ )
35
+ raw = {
36
+ "deaths": [{
37
+ "tick": 250,
38
+ "user_steamid": "76561198000000002",
39
+ "attacker_steamid": "76561198000000001",
40
+ "weapon": "ak47",
41
+ "user_X": 1,
42
+ "user_Y": 2,
43
+ "user_Z": 3,
44
+ }],
45
+ }
46
+
47
+ kills = build_kills(raw, players, round_model)
48
+
49
+ assert len(kills) == 1
50
+ assert kills[0]["roundNumber"] == 1
51
+ assert kills[0]["tick"] == 250
52
+
53
+
54
+ def test_round_restart_keeps_previous_result_and_excludes_abandoned_ticks():
55
+ starts = [
56
+ {"total_rounds_played": 0, "tick": 10},
57
+ {"total_rounds_played": 1, "tick": 100},
58
+ {"total_rounds_played": 1, "tick": 160},
59
+ ]
60
+ freezes = [
61
+ {"total_rounds_played": 0, "tick": 20},
62
+ {"total_rounds_played": 1, "tick": 170},
63
+ ]
64
+ ends = [
65
+ {"total_rounds_played": 1, "tick": 90, "winner": "ct"},
66
+ {"total_rounds_played": 1, "tick": 160, "winner": None},
67
+ {"total_rounds_played": 2, "tick": 200, "winner": "ct"},
68
+ ]
69
+
70
+ rounds, model = build_rounds(
71
+ {"round_starts": starts, "round_freeze_ends": freezes, "round_ends": ends}, {}
72
+ )
73
+
74
+ assert [r["roundNumber"] for r in rounds] == [1, 2]
75
+ assert (rounds[1]["startTick"], rounds[1]["freezeEndTick"]) == (160, 170)
76
+ assert model.round_for_tick(99) == 1
77
+ assert model.round_for_tick(100) is None
78
+ assert model.round_for_tick(159) is None
79
+ assert model.round_for_tick(160) == 2
80
+ ticks = _build_sample_ticks(ends, freezes, starts, step=1)
81
+ assert all(not 100 <= tick < 170 for tick in ticks)
82
+ assert 99 in ticks and 170 in ticks
83
+
84
+ attacker = "76561198000000001"
85
+ victim = "76561198000000002"
86
+ players = PlayerDirectory(
87
+ [
88
+ {"steamId64": attacker, "name": "attacker", "teamKey": "teamA"},
89
+ {"steamId64": victim, "name": "victim", "teamKey": "teamB"},
90
+ ]
91
+ )
92
+ damage = {
93
+ "user_steamid": victim,
94
+ "attacker_steamid": attacker,
95
+ "weapon": "ak47",
96
+ "dmg_health": 50,
97
+ }
98
+ damages = build_damages(
99
+ {"hurts": [{**damage, "tick": tick} for tick in (130, 160, 180)]},
100
+ players,
101
+ model,
102
+ )
103
+ assert [(row["tick"], row["victimHealthBefore"]) for row in damages] == [(180, 100)]
104
+
105
+
106
+ def test_rollback_replaces_scored_attempt_and_discards_later_old_rounds():
107
+ raw = {
108
+ "round_starts": [
109
+ {"total_rounds_played": 0, "tick": 10},
110
+ {"total_rounds_played": 1, "tick": 100},
111
+ {"total_rounds_played": 2, "tick": 210},
112
+ {"total_rounds_played": 1, "tick": 260},
113
+ ],
114
+ "round_freeze_ends": [
115
+ {"total_rounds_played": 0, "tick": 20},
116
+ {"total_rounds_played": 1, "tick": 110},
117
+ {"total_rounds_played": 2, "tick": 220},
118
+ {"total_rounds_played": 1, "tick": 270},
119
+ ],
120
+ "round_ends": [
121
+ {"total_rounds_played": 1, "tick": 90, "winner": "ct"},
122
+ {"total_rounds_played": 2, "tick": 200, "winner": "t"},
123
+ {"total_rounds_played": 3, "tick": 250, "winner": "t"},
124
+ {"total_rounds_played": 1, "tick": 260, "winner": None},
125
+ {"total_rounds_played": 2, "tick": 300, "winner": "ct"},
126
+ ],
127
+ }
128
+
129
+ rounds, model = build_rounds(raw, {})
130
+
131
+ assert [r["roundNumber"] for r in rounds] == [1, 2]
132
+ assert (rounds[1]["startTick"], rounds[1]["freezeEndTick"]) == (260, 270)
133
+ assert (rounds[1]["endTick"], rounds[1]["winnerSide"]) == (300, "ct")
134
+ assert model.round_for_tick(150) is None
135
+ assert model.round_for_tick(230) is None
136
+ assert model.round_for_tick(270) == 2
@@ -30,7 +30,7 @@ wheels = [
30
30
 
31
31
  [[package]]
32
32
  name = "cs2df"
33
- version = "3.0.4"
33
+ version = "3.1.1"
34
34
  source = { editable = "." }
35
35
  dependencies = [
36
36
  { name = "demoparser2" },
@@ -47,7 +47,7 @@ dev = [
47
47
 
48
48
  [package.metadata]
49
49
  requires-dist = [
50
- { name = "demoparser2", specifier = ">=0.41.2" },
50
+ { name = "demoparser2", specifier = ">=0.42.2" },
51
51
  { name = "jsonschema", specifier = ">=4.21" },
52
52
  { name = "numpy", specifier = ">=1.26" },
53
53
  { name = "orjson", specifier = ">=3.9" },
@@ -59,7 +59,7 @@ dev = [{ name = "pytest", specifier = ">=8" }]
59
59
 
60
60
  [[package]]
61
61
  name = "demoparser2"
62
- version = "0.41.3"
62
+ version = "0.42.2"
63
63
  source = { registry = "https://pypi.org/simple" }
64
64
  dependencies = [
65
65
  { name = "numpy" },
@@ -69,30 +69,30 @@ dependencies = [
69
69
  { name = "tqdm" },
70
70
  ]
71
71
  wheels = [
72
- { url = "https://files.pythonhosted.org/packages/07/35/c6f8a4ee6717572f649c4b20b6868d77f37abab2e367bed43d0421a4a812/demoparser2-0.41.3-cp311-cp311-macosx_10_12_x86_64.whl", hash = "sha256:6793f49a60f950e7b84dbf937520a662ed92008e0913e1e9d0afd870aa60ca81", size = 4211956, upload-time = "2026-05-13T16:18:55.046Z" },
73
- { url = "https://files.pythonhosted.org/packages/98/ae/f1224f748053a3ea298f1831b427aff16847a802227a52f85295a3b6df91/demoparser2-0.41.3-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:060e9cbe3e35123ffd86a1eecc54d432bac6ea195ddc6fc005e7feb512fa6313", size = 3901631, upload-time = "2026-05-13T16:51:12.501Z" },
74
- { url = "https://files.pythonhosted.org/packages/ae/b6/4bcec985fcf70e16b4b3ca5e74098c1263b878ccc5e7b59d7b9fce373f4e/demoparser2-0.41.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:2314179d85218384ae429740efb25c18d786d42bf49b3b920abf287a8e9236d1", size = 4085075, upload-time = "2026-05-13T16:39:53.227Z" },
75
- { url = "https://files.pythonhosted.org/packages/32/f1/1e913e272e568e363d05bcda752ecd4d1827df47de44c55415485b7b47eb/demoparser2-0.41.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:48a61e39e333f61707d2f8dc87431da1d803339e2321328d5ad6d96b0b6c43c1", size = 4473834, upload-time = "2026-05-13T16:44:35.873Z" },
76
- { url = "https://files.pythonhosted.org/packages/98/ff/377885eafe8174449e1220bc188897b4f60ba9e1dc9a4fe6218997bd6951/demoparser2-0.41.3-cp311-cp311-win32.whl", hash = "sha256:bcc78920429b83c4ea6c3657c374b320d1c00b0a916a6221ba26705a7bfaded7", size = 4146875, upload-time = "2026-05-13T16:45:31.776Z" },
77
- { url = "https://files.pythonhosted.org/packages/72/96/4bb5ec480e04e19a0a51180c9accff3ad54e8b998c44cc0ddcf039154c4c/demoparser2-0.41.3-cp311-cp311-win_amd64.whl", hash = "sha256:5c387a77384dd323990f253f5e0e7851c7e455639875b1d9d3f9fcd47ba7b40c", size = 4712102, upload-time = "2026-05-13T16:45:22.757Z" },
78
- { url = "https://files.pythonhosted.org/packages/0e/86/9d87609eced38710df734ef21afeec8b518f968ba453439cd4f7e70515c3/demoparser2-0.41.3-cp312-cp312-macosx_10_12_x86_64.whl", hash = "sha256:1f49d0413eff38ea3fd5ad48ef60c0550d68bb692c4dbc434415978da4dfc718", size = 4206621, upload-time = "2026-05-13T16:45:44.095Z" },
79
- { url = "https://files.pythonhosted.org/packages/1d/27/efeeadda4742ed95bd4a6b90996982626933035aeee5ddf5aca9b0e4e82f/demoparser2-0.41.3-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:fb43201f16f8118848e6913cace4478e2214a04a4088887f215b9f265b606d8b", size = 3899390, upload-time = "2026-05-13T16:18:43.879Z" },
80
- { url = "https://files.pythonhosted.org/packages/ab/63/49e87967c89b51d5f827d14a36d118b0cb8ff1f4de439d27cc8b5786813d/demoparser2-0.41.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:252d10b884b9d3f93dd0059e8c899d602acba522eb28ab810715b4ba9937e2a5", size = 4080945, upload-time = "2026-05-13T16:39:37.256Z" },
81
- { url = "https://files.pythonhosted.org/packages/14/b1/b2efda2f0e626da6f563efcba55dda027f1faefcc94e6ff06926eefdfab9/demoparser2-0.41.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:520601f5f29eddbd273833925c3497704f20bcb0c3b1af29f432ad80d4198d06", size = 4471123, upload-time = "2026-05-13T16:49:13.741Z" },
82
- { url = "https://files.pythonhosted.org/packages/59/13/874ab7232a87e9e0d8584fd3666bbc2d959ee9a990d13eb6147950aa50ac/demoparser2-0.41.3-cp312-cp312-win32.whl", hash = "sha256:669bac72ae7b79615e1ce0eadbd3878860a9c34bb443cec31b182bddd2547849", size = 4148621, upload-time = "2026-05-13T16:47:58.904Z" },
83
- { url = "https://files.pythonhosted.org/packages/20/c1/89f7d01ad6d6d6cb879d8b2aba421a99f6a2a1beb23057290029593ab440/demoparser2-0.41.3-cp312-cp312-win_amd64.whl", hash = "sha256:0829cb6839b1c5d8b2350a2e2d78cd304e615bb72e738191d5bbdbebce7d9352", size = 4710045, upload-time = "2026-05-13T16:47:05.699Z" },
84
- { url = "https://files.pythonhosted.org/packages/22/85/fbfe99f93ee070f4423ec6b2c064ed532298826eddaa3da15d17301616b6/demoparser2-0.41.3-cp313-cp313-macosx_10_12_x86_64.whl", hash = "sha256:dc4458741c04bba80ddef2aeebfd5a631b9f0002ea8e04e69ab6b86edba46885", size = 4206261, upload-time = "2026-05-13T16:38:27.416Z" },
85
- { url = "https://files.pythonhosted.org/packages/46/8a/0f804e394d6f0584dd99915c1bfe4168bcbc8619c2262797c5f3257c8061/demoparser2-0.41.3-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:2d0a980ab490921625975cd248cc52627201d7b1d41d27ccdbb72bbbafb3b5e9", size = 3899101, upload-time = "2026-05-13T16:40:55.545Z" },
86
- { url = "https://files.pythonhosted.org/packages/b0/53/58654a1df7c43312cfa04d0dfa6862a5f0a74e655aaf9d8c376be5d12e40/demoparser2-0.41.3-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:e4ff12171e12a11dfdfa86d2f4769436402ec95e94b750b870c162eda1f6017a", size = 4080942, upload-time = "2026-05-13T16:39:31.517Z" },
87
- { url = "https://files.pythonhosted.org/packages/f0/57/685c76e39a34620e6b40e3495ff1677b62236fef851260d5af4c5110c9cc/demoparser2-0.41.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:a11c22064ea9603fc4f3619a3d991a07e38ca6b2d81e8288cbefc76b89a720c7", size = 4470780, upload-time = "2026-05-13T16:39:01.044Z" },
88
- { url = "https://files.pythonhosted.org/packages/01/77/53a2f8aa11767825e8eceeaa4dec637ca09cf76e5bd8794fb68c94db3cba/demoparser2-0.41.3-cp313-cp313-win32.whl", hash = "sha256:73a5a37455ce00ec23cedf7ca06c73f8a58ed576c8876599cc9a4c0e8746c95d", size = 4148690, upload-time = "2026-05-13T16:43:55.599Z" },
89
- { url = "https://files.pythonhosted.org/packages/88/20/56f61e4e12494e2228480b1cd2d490fbf245a521c15f38d9c14726d11aea/demoparser2-0.41.3-cp313-cp313-win_amd64.whl", hash = "sha256:fb4e42a5d1bc0aca5d87794337308147eb7445de205ee05e6882f7273690c166", size = 4709027, upload-time = "2026-05-13T16:48:47.853Z" },
90
- { url = "https://files.pythonhosted.org/packages/39/37/17e7a40e8e24c3e0fa7191966f555ae8d7c60575212b11156a5de7d3dbc0/demoparser2-0.41.3-cp314-cp314-macosx_10_12_x86_64.whl", hash = "sha256:aa19e00eb7088c3e5a1018330cacf5647996b69300523dc17d9194fc06752d1a", size = 4208553, upload-time = "2026-05-13T16:47:28.486Z" },
91
- { url = "https://files.pythonhosted.org/packages/8e/f5/8a29245aa87d362572448243c795db61375c3519262c59f54b95c154ce1c/demoparser2-0.41.3-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:1e50760fab02db4d8772bc5facca9f635f825388b5c5f1ea959e451d254d7587", size = 3900490, upload-time = "2026-05-13T16:48:34.483Z" },
92
- { url = "https://files.pythonhosted.org/packages/b6/a8/0bc485cc92e3d598a5cbace4e9af87ff5c4e2257acb3da0495e5b3cf5699/demoparser2-0.41.3-cp314-cp314-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:da18b0fe8df1744551a04196967c30310041ec472f008163ab19bd31c2ff2389", size = 4079997, upload-time = "2026-05-13T16:39:36.818Z" },
93
- { url = "https://files.pythonhosted.org/packages/42/93/efffda9ac4df57783c983c28a10485df8a3fc55da021c5db5812b3d4a9cc/demoparser2-0.41.3-cp314-cp314-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:4888077d1ea8f9d133e0e9646811c0d07b26011e884df3d88574379b1e237397", size = 4470786, upload-time = "2026-05-13T16:39:02.692Z" },
94
- { url = "https://files.pythonhosted.org/packages/d5/18/d23e06fffccf9372d97f2f5c5ecb83eb65fa7870261851058d0e11fa47b6/demoparser2-0.41.3-cp314-cp314-win32.whl", hash = "sha256:117999dd340b8f9ca01ed76f8e5a021f468014e0a4eb20380f033fe8077ffacb", size = 4147141, upload-time = "2026-05-13T16:49:56.613Z" },
95
- { url = "https://files.pythonhosted.org/packages/88/7b/af2cb5ad637ed693427fbca17d5c68a3818b4b0e14c4cb6378910274ae06/demoparser2-0.41.3-cp314-cp314-win_amd64.whl", hash = "sha256:cb05e532a3194305ff80c2a10908bf6e811dd462aa99a62596f96ecfdaf61aef", size = 4710161, upload-time = "2026-05-13T16:42:20.244Z" },
72
+ { url = "https://files.pythonhosted.org/packages/6e/3a/288a26028088b3a6b3cd9375aba3e62aaa570347b93b06f961c43b51cfdd/demoparser2-0.42.2-cp311-cp311-macosx_10_12_x86_64.whl", hash = "sha256:68c24256dd0db962d379fb1b0156b2017bf5d7ee9091ca5605afbdbc6dfe225c", size = 4161842, upload-time = "2026-11-12T14:50:04.682Z" },
73
+ { url = "https://files.pythonhosted.org/packages/07/83/b171ba092c1fba670c351328dd0c40f509d1c042fb6bceb3e8e9d2677a10/demoparser2-0.42.2-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:4f9a14351270eb9eda65ec19e91a23967978c638a79188aea9901f5601d1353d", size = 3877341, upload-time = "2026-11-12T14:55:20.191Z" },
74
+ { url = "https://files.pythonhosted.org/packages/85/ab/9fe5b28f87d4f0e3763cdb30b4f94ad1bdf32e0ac738aedd84939d699f7b/demoparser2-0.42.2-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:6a75ffc95f3ff18b48f936800bf6a351fdcde451756ec936a7f471cc330a5853", size = 4047634, upload-time = "2026-11-12T14:28:43.71Z" },
75
+ { url = "https://files.pythonhosted.org/packages/a5/47/c6a556d294538eefab643e0972b2cee64a47578057138f5a07a6f922fb87/demoparser2-0.42.2-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:3ceaab6a91284b530088f8814031f69e34103ef6dc700730d3fe7a0b42f6c634", size = 4407372, upload-time = "2026-11-12T14:29:23.735Z" },
76
+ { url = "https://files.pythonhosted.org/packages/4f/8b/b7bafcdafa678731ab917cfae3ecd37b2ecf6767a2b47cbcb3e8a457ac70/demoparser2-0.42.2-cp311-cp311-win32.whl", hash = "sha256:97d2e5bf7757f2abe362f374e53b72512578557f56a2544b3fe6226a3b499693", size = 4055424, upload-time = "2026-11-12T14:32:57.959Z" },
77
+ { url = "https://files.pythonhosted.org/packages/17/28/cee4816b064ed2667a112870409279144d50a267897b6d1cc851a521484c/demoparser2-0.42.2-cp311-cp311-win_amd64.whl", hash = "sha256:0b8db90856603061f1cbdd2f31c00190394266e5539630c2276194e89ba4a0ae", size = 4625424, upload-time = "2026-11-12T14:32:15.453Z" },
78
+ { url = "https://files.pythonhosted.org/packages/9a/ed/239a2e20e32eda1ebd57c9929131caed7e22fec0615add0ff179aa3c11b2/demoparser2-0.42.2-cp312-cp312-macosx_10_12_x86_64.whl", hash = "sha256:e87d458a9022331b98f93a0634e04cd1939cb1af8916cd24e29a65ee042d360b", size = 4157819, upload-time = "2026-11-12T14:44:44.707Z" },
79
+ { url = "https://files.pythonhosted.org/packages/f1/36/fd1df47857e268d137b68bb4cf2c6c3c994e31ed5e82ffac871a0d9c7063/demoparser2-0.42.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:d3c921884c6c50491e2a2942081c715b27fddd33789bf81262763a8762890845", size = 3873735, upload-time = "2026-11-12T14:48:31.65Z" },
80
+ { url = "https://files.pythonhosted.org/packages/f0/6e/82ba3960c3b6b3ade2047a10f77bf864d010b5faf130180737cf7d0d34e1/demoparser2-0.42.2-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:1067d112072869e4fda055d58813af9522feaf64a87cb8aa6c2bd949bb8345c4", size = 4045485, upload-time = "2026-11-12T14:34:28.562Z" },
81
+ { url = "https://files.pythonhosted.org/packages/15/18/8dcf751424ccf1473debca32af1f303feffcf9f143a1b95a92f94a7ad34e/demoparser2-0.42.2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:20ec9d21daf51c6d634cf544b931fedff584dcc8d0173405c1fc07015abe6bca", size = 4404681, upload-time = "2026-11-12T14:33:06.738Z" },
82
+ { url = "https://files.pythonhosted.org/packages/1b/3a/8026a7732e903510fb287cc1fff2c636f46cfa301cef498daed2751727b1/demoparser2-0.42.2-cp312-cp312-win32.whl", hash = "sha256:ab9d4055e4f456bb44c9bd3c5105e96189247cbe6142746d472b64f1b80bcc88", size = 4056121, upload-time = "2026-11-12T14:32:52.52Z" },
83
+ { url = "https://files.pythonhosted.org/packages/66/de/9a4b4c6401845ce141404fc07581b181f02a8f0aaf253dcba400ab4f25f0/demoparser2-0.42.2-cp312-cp312-win_amd64.whl", hash = "sha256:42a066226f000ed7d0a117722acda3d5de42635aa0e3b730fc74475e959afdae", size = 4624894, upload-time = "2026-11-12T14:32:22.606Z" },
84
+ { url = "https://files.pythonhosted.org/packages/2c/b1/e72dfac017f73bee4943b457ac289e630053ae966b80209d2c4091af6af2/demoparser2-0.42.2-cp313-cp313-macosx_10_12_x86_64.whl", hash = "sha256:ed4ae11b0d76a5ad22f9587cee4e9d0e32aced4186cf665314b8fc1f0043bbd5", size = 4158133, upload-time = "2026-11-12T15:04:56.04Z" },
85
+ { url = "https://files.pythonhosted.org/packages/16/17/da9256722bbc42e6391dd0dbe680658e4c47a443a9ec0970df2dd349759c/demoparser2-0.42.2-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:3b3800dfb28e49538e1122b68760061d378e3ab1d4a45b3a9fee05a7f3eae030", size = 3874001, upload-time = "2026-11-12T14:43:44.762Z" },
86
+ { url = "https://files.pythonhosted.org/packages/f5/ad/07a2780ebfaa4c0a481ab76a612e6e0908d7793c518b79c7ea37353ce701/demoparser2-0.42.2-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:b163e5dc591cafa5419b676baffe40a4718712650eca8af6f8c69a1a5842fdd9", size = 4045521, upload-time = "2026-11-12T14:30:06.735Z" },
87
+ { url = "https://files.pythonhosted.org/packages/52/9a/021ce5e3df7e7d712b73159b8336f62350dcf508559653201b8c971d291a/demoparser2-0.42.2-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:757a3ad8174c6137325f65b5e035cb066d609364ab10706942060f2075fa0df7", size = 4404088, upload-time = "2026-11-12T14:28:41.502Z" },
88
+ { url = "https://files.pythonhosted.org/packages/8b/e5/f271c8e062a6691429c8c21ec9109d429e4707a4db56aa127598405dba58/demoparser2-0.42.2-cp313-cp313-win32.whl", hash = "sha256:f3bd6287ca3125762d043fc4ee9ba12f8abb821a69dfd78cf0efd6c930e382a9", size = 4056041, upload-time = "2026-11-12T14:37:07.054Z" },
89
+ { url = "https://files.pythonhosted.org/packages/89/9a/ea0035fe88372919c788f7a79a82d36ac1e8d79b6fefbbd8a0e647136531/demoparser2-0.42.2-cp313-cp313-win_amd64.whl", hash = "sha256:bf553070c72dc992d9c0e5a3961864ae0ba66920402e07c6de99f3325ec0b406", size = 4624865, upload-time = "2026-11-12T14:32:30.132Z" },
90
+ { url = "https://files.pythonhosted.org/packages/71/d0/c2c2ab86e7383bbc4ac73f10d102cfa47c0ece1d4f5ebf84ab94c4dd8883/demoparser2-0.42.2-cp314-cp314-macosx_10_12_x86_64.whl", hash = "sha256:28c1ed70117f083c000655408eabb246465bc194a3b1ade4d994f6338a9f5ddb", size = 4157899, upload-time = "2026-11-12T14:55:02.502Z" },
91
+ { url = "https://files.pythonhosted.org/packages/5c/58/9cc76b777eed5bef10faf1be93d4b48abca556d0c0b27e6b3b6832648fa5/demoparser2-0.42.2-cp314-cp314-macosx_11_0_arm64.whl", hash = "sha256:cc66af677feaf5be1920d0f4556cd92aa86224f2b6cfb91dcaf3171aca6c07d5", size = 3874204, upload-time = "2026-11-12T15:03:30.71Z" },
92
+ { url = "https://files.pythonhosted.org/packages/85/7c/3519f5f0e5892154527347dc375bae83df0efd77cfa7e7bfe67106a8ee85/demoparser2-0.42.2-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.whl", hash = "sha256:0b8cd6ec29862f3609cb9921d5bae2072a3fd3a7ec1a773708e6713dec45a3a6", size = 4045409, upload-time = "2026-11-12T14:29:53.664Z" },
93
+ { url = "https://files.pythonhosted.org/packages/1c/66/65714f5ea1e317f66526bd1b38bbae555f637dca81ed77ff3eafadf368f7/demoparser2-0.42.2-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.whl", hash = "sha256:1d87ab96cdcdc58b4ca899a1d64abe4fdb846a79ed4f9c62a4c5f630cd15f510", size = 4405360, upload-time = "2026-11-12T14:34:08.714Z" },
94
+ { url = "https://files.pythonhosted.org/packages/2c/48/a53aeb38c3bc1839361a16f3bbdea75a83c60b96e0dfeb3ee3fbcc9fb3c8/demoparser2-0.42.2-cp314-cp314-win32.whl", hash = "sha256:6db4aaf2445ce6bf0b89f00e8a5fcd7403c37cd05248a2601de5e70bf05237ec", size = 4054507, upload-time = "2026-11-12T14:32:53.644Z" },
95
+ { url = "https://files.pythonhosted.org/packages/fd/f3/a4379d80be591b924e686f135838cd660a2b87a971691ac965e0f020fd71/demoparser2-0.42.2-cp314-cp314-win_amd64.whl", hash = "sha256:3e9183c6c9aefebd538145d37ef6e76b6e39c735823e4101123bbd60f56e287f", size = 4626314, upload-time = "2026-11-12T14:32:40.885Z" },
96
96
  ]
97
97
 
98
98
  [[package]]
@@ -1,50 +0,0 @@
1
- from __future__ import annotations
2
-
3
- from cs2df.events import PlayerDirectory, build_kills
4
- from cs2df.rounds import _RoundModel, _RoundWindow
5
-
6
-
7
- def test_round_for_tick_assigns_post_round_tail_to_previous_round():
8
- round_model = _RoundModel(
9
- windows=[
10
- _RoundWindow(round_number=1, start_tick=50, freeze_end_tick=100, end_tick=200),
11
- _RoundWindow(round_number=2, start_tick=300, freeze_end_tick=360, end_tick=460),
12
- ],
13
- side_map={},
14
- )
15
-
16
- assert round_model.round_for_tick(200) == 1
17
- assert round_model.round_for_tick(250) == 1
18
- assert round_model.round_for_tick(299) == 1
19
- assert round_model.round_for_tick(300) == 2
20
-
21
-
22
- def test_kills_after_round_end_before_next_start_are_kept_in_previous_round():
23
- players = PlayerDirectory([
24
- {"steamId64": "76561198000000001", "name": "attacker", "teamKey": "teamA"},
25
- {"steamId64": "76561198000000002", "name": "victim", "teamKey": "teamB"},
26
- ])
27
- round_model = _RoundModel(
28
- windows=[
29
- _RoundWindow(round_number=1, start_tick=50, freeze_end_tick=100, end_tick=200),
30
- _RoundWindow(round_number=2, start_tick=300, freeze_end_tick=360, end_tick=460),
31
- ],
32
- side_map={(1, "teamA"): "t", (1, "teamB"): "ct"},
33
- )
34
- raw = {
35
- "deaths": [{
36
- "tick": 250,
37
- "user_steamid": "76561198000000002",
38
- "attacker_steamid": "76561198000000001",
39
- "weapon": "ak47",
40
- "user_X": 1,
41
- "user_Y": 2,
42
- "user_Z": 3,
43
- }],
44
- }
45
-
46
- kills = build_kills(raw, players, round_model)
47
-
48
- assert len(kills) == 1
49
- assert kills[0]["roundNumber"] == 1
50
- assert kills[0]["tick"] == 250
File without changes
File without changes
File without changes
File without changes
File without changes