Skip to content

Commit

Permalink
Merge pull request #152 from circleguard/timewarp-full-frametimes
Browse files Browse the repository at this point in the history
expose full frametime list in TimewarpResult
  • Loading branch information
tybug authored Jun 21, 2020
2 parents 9838dbb + e9eda05 commit ca528bc
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 15 deletions.
39 changes: 26 additions & 13 deletions circleguard/investigator.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,20 @@ def __init__(self, replay, detect, max_angle, min_distance, beatmap=None):
self.detect = detect

def investigate(self):
replay = self.replay
# equivalent of filtering out replays with no replay data from comparer on init
if self.replay.replay_data is None:
if replay.replay_data is None:
return
if self.detect & Detect.RELAX:
ur = self.ur(self.replay, self.beatmap)
yield RelaxResult(self.replay, ur)
ur = self.ur(replay, self.beatmap)
yield RelaxResult(replay, ur)
if self.detect & Detect.CORRECTION:
snaps = self.aim_correction(self.replay, self.max_angle, self.min_distance)
yield CorrectionResult(self.replay, snaps)
snaps = self.aim_correction(replay, self.max_angle, self.min_distance)
yield CorrectionResult(replay, snaps)
if self.detect & Detect.TIMEWARP:
frametime = self.median_frametime(self.replay)
yield TimewarpResult(self.replay, frametime)
frametimes = self.frametimes(replay)
frametime = self.median_frametime(frametimes)
yield TimewarpResult(replay, frametime, frametimes)

@staticmethod
def ur(replay, beatmap):
Expand Down Expand Up @@ -195,22 +197,33 @@ def aim_correction_sam(replay_data, num_jerks, min_jerk):
return [jerks, ischeat]

@staticmethod
def median_frametime(replay):
def frametimes(replay):
"""
Calculates the median time between the frames of ``replay``.
Returns the time between each pair of consecutive frames in ``replay``.
Parameters
----------
replay: :class:`~.Replay`
The replay to find the median frametime of.
The replay to get the frametimes of.
"""
# replay.t is cumsum so convert it back to "time since previous frame"
return np.diff(replay.t)

@staticmethod
def median_frametime(frametimes):
"""
Calculates the median time between the frames in ``frametimes``.
Parameters
----------
frametimes: list[int]
The frametimes to find the median of.
Notes
-----
Median is used instead of mean to lessen the effect of outliers.
"""
# replay.t is cumsum so convert it back to "time since previous frame"
t = np.diff(replay.t)
return np.median(t)
return np.median(frametimes)

@staticmethod
def _parse_beatmap(beatmap):
Expand Down
9 changes: 8 additions & 1 deletion circleguard/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,16 @@ class TimewarpResult(InvestigationResult):
The replay investigated.
frametime: float
The average (median) time between frames of the replay.
frametimes: list[int]
A list of the time between frames of the replay. You should not rely
on ``frametime`` being the median of this list, as circlecore may clean
or otherwise modify the frametime list before computing its median. This
attribute holds the "raw" frametimes, without any modification by
circlecore.
"""

def __init__(self, replay: Replay, frametime: float):
def __init__(self, replay: Replay, frametime: float, frametimes: list):
super().__init__(replay, ResultType.TIMEWARP)
self.frametime = convert_statistic(frametime, replay.mods, to="cv")
self.frametimes = frametimes
self.ucv_frametime = frametime
2 changes: 1 addition & 1 deletion circleguard/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "4.3.2"
__version__ = "4.3.3"

0 comments on commit ca528bc

Please sign in to comment.