Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added average hit error and unstable rate to the ranking graph tooltip.
Signed-off-by: Jeffrey Han <itdelatrisu@gmail.com>
  • Loading branch information
itdelatrisu committed Feb 4, 2017
1 parent dd93a25 commit 3b746ec
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
57 changes: 57 additions & 0 deletions src/itdelatrisu/opsu/GameData.java
Expand Up @@ -33,13 +33,16 @@
import itdelatrisu.opsu.replay.ReplayFrame;
import itdelatrisu.opsu.ui.Colors;
import itdelatrisu.opsu.ui.Fonts;
import itdelatrisu.opsu.ui.UI;
import itdelatrisu.opsu.ui.animations.AnimationEquation;
import itdelatrisu.opsu.user.UserList;

import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.concurrent.LinkedBlockingDeque;

Expand Down Expand Up @@ -239,6 +242,12 @@ public HitErrorInfo(int time, int x, int y, int timeDiff) {
/** List containing recent hit error information. */
private LinkedBlockingDeque<HitErrorInfo> hitErrorList;

/** List containing all hit error time differences. */
private List<Integer> hitErrors;

/** Performance string containing hit error averages and unstable rate. */
private String performanceString = null;

/** Hit object types, used for drawing results. */
public enum HitObjectType { CIRCLE, SLIDERTICK, SLIDER_FIRST, SLIDER_LAST, SPINNER }

Expand Down Expand Up @@ -394,6 +403,8 @@ public void clear() {
}
hitResultList = new LinkedBlockingDeque<HitObjectResult>();
hitErrorList = new LinkedBlockingDeque<HitErrorInfo>();
hitErrors = new ArrayList<Integer>();
performanceString = null;
fullObjectCount = 0;
combo = 0;
comboMax = 0;
Expand Down Expand Up @@ -1321,6 +1332,26 @@ public void updateDisplays(int delta) {
}
}

/**
* Updates displayed ranking elements based on a delta value.
* @param delta the delta interval since the last call
* @param mouseX the mouse x coordinate
* @param mouseY the mouse y coordinate
*/
public void updateRankingDisplays(int delta, int mouseX, int mouseY) {
// graph tooltip
Image graphImg = GameImage.RANKING_GRAPH.getImage();
float graphX = 416 * GameImage.getUIscale();
float graphY = 688 * GameImage.getUIscale();
if (isGameplay &&
mouseX >= graphX - graphImg.getWidth() / 2f && mouseX <= graphX + graphImg.getWidth() / 2f &&
mouseY >= graphY - graphImg.getHeight() / 2f && mouseY <= graphY + graphImg.getHeight() / 2f) {
if (performanceString == null)
performanceString = getPerformanceString(hitErrors);
UI.updateTooltip(delta, performanceString, true);
}
}

/**
* Returns the current combo streak.
*/
Expand Down Expand Up @@ -1728,5 +1759,31 @@ public Replay getReplay(ReplayFrame[] frames, LifeFrame[] lifeFrames, Beatmap be
*/
public void addHitError(int time, int x, int y, int timeDiff) {
hitErrorList.addFirst(new HitErrorInfo(time, x, y, timeDiff));
hitErrors.add(timeDiff);
}

/**
* Computes the error values and unstable rate for the map.
* @see <a href="https://osu.ppy.sh/wiki/Accuracy#Performance_Graph">https://osu.ppy.sh/wiki/Accuracy#Performance_Graph</a>
*/
private String getPerformanceString(List<Integer> errors) {
int earlyCount = 0, lateCount = 0;
int earlySum = 0, lateSum = 0;
for (int diff : errors) {
if (diff < 0) {
earlyCount++;
earlySum += diff;
} else if (diff > 0) {
lateCount++;
lateSum += diff;
}
}
float hitErrorEarly = (earlyCount > 0) ? (float) earlySum / earlyCount : 0f;
float hitErrorLate = (lateCount > 0) ? (float) lateSum / lateCount : 0f;
float unstableRate = (!errors.isEmpty()) ? (float) (Utils.standardDeviation(errors) * 10) : 0f;
return String.format(
"Accuracy:\nError: %.2fms - %.2fms avg\nUnstable Rate: %.2f",
hitErrorEarly, hitErrorLate, unstableRate
);
}
}
16 changes: 16 additions & 0 deletions src/itdelatrisu/opsu/Utils.java
Expand Up @@ -54,6 +54,7 @@
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Scanner;
import java.util.jar.JarFile;

Expand Down Expand Up @@ -255,6 +256,21 @@ public static float lerp(float a, float b, float t) {
return a * (1 - t) + b * t;
}

/**
* Calculates the standard deviation of the numbers in the list.
*/
public static double standardDeviation(List<Integer> list) {
float avg = 0f;
for (int i : list)
avg += i;
avg /= list.size();
float var = 0f;
for (int i : list)
var += (i - avg) * (i - avg);
var /= list.size();
return Math.sqrt(var);
}

/**
* Maps a difficulty value to the given range.
* @param difficulty the difficulty value
Expand Down
1 change: 1 addition & 0 deletions src/itdelatrisu/opsu/states/GameRanking.java
Expand Up @@ -154,6 +154,7 @@ public void update(GameContainer container, StateBasedGame game, int delta)
MusicController.loopTrackIfEnded(true);
UI.getBackButton().hoverUpdate(delta, mouseX, mouseY);
animationProgress.update(delta);
data.updateRankingDisplays(delta, mouseX, mouseY);
}

@Override
Expand Down

0 comments on commit 3b746ec

Please sign in to comment.