maybe fixed pp? honestly, no idea
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 1m43s
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 1m43s
This commit is contained in:
parent
49e223a8b9
commit
1efab2ed08
@ -39,5 +39,7 @@ public class Main {
|
||||
|
||||
// Start the app
|
||||
SpringApplication.run(Main.class, args);
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -10,12 +10,18 @@ import lombok.Getter;
|
||||
@Getter
|
||||
public class CurvePoint {
|
||||
/**
|
||||
* The x value of the curve point.
|
||||
* The acc at the curve point.
|
||||
* <p>
|
||||
* Acc is divided by 100 to get the actual value.
|
||||
* </p>
|
||||
*/
|
||||
private final double x;
|
||||
private final double acc;
|
||||
|
||||
/**
|
||||
* The y value of the curve point.
|
||||
* The multiplier of the curve point.
|
||||
* <p>
|
||||
* This is the multiplier for the pp calculation.
|
||||
* </p>
|
||||
*/
|
||||
private final double y;
|
||||
private final double multiplier;
|
||||
}
|
||||
|
@ -49,13 +49,24 @@ public abstract class Platform {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the curve points for a curve version.
|
||||
*
|
||||
* @param curveVersion the curve version to get the curve points for
|
||||
* @return the curve points
|
||||
*/
|
||||
public CurvePoint[] getCurve(int curveVersion) {
|
||||
this.checkCurveVersion(curveVersion);
|
||||
return curvePoints.get(curveVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the PP amount from the star count.
|
||||
*
|
||||
* @param stars the amount of stars
|
||||
* @return the pp amount
|
||||
*/
|
||||
public abstract double getPp(int curveVersion, double stars, double accuracy);
|
||||
public abstract double getPp(double stars, double accuracy);
|
||||
|
||||
/**
|
||||
* Called every 10 minutes to update
|
||||
|
@ -35,7 +35,7 @@ public class ScoreSaberPlatform extends Platform {
|
||||
/**
|
||||
* The base multiplier for stars.
|
||||
*/
|
||||
private final double starMultiplier = 42.11;
|
||||
private final double starMultiplier = 42.114296;
|
||||
|
||||
/**
|
||||
* The ScoreSaber service to use
|
||||
@ -66,42 +66,43 @@ public class ScoreSaberPlatform extends Platform {
|
||||
@NonNull TrackedScoreService trackedScoreService) {
|
||||
super(Platforms.SCORESABER, 1, Map.of(
|
||||
1, new CurvePoint[]{
|
||||
new CurvePoint(1.0, 5.367394282890631),
|
||||
new CurvePoint(0.9995, 5.019543595874787),
|
||||
new CurvePoint(0.999, 4.715470646416203),
|
||||
new CurvePoint(0.99825, 4.325027383589547),
|
||||
new CurvePoint(0.9975, 3.996793606763322),
|
||||
new CurvePoint(0.99625, 3.5526145337555373),
|
||||
new CurvePoint(0.995, 3.2022017597337955),
|
||||
new CurvePoint(0.99375, 2.9190155639254955),
|
||||
new CurvePoint(0.99125, 2.4902905794106913),
|
||||
new CurvePoint(0.99, 2.324506282149922),
|
||||
new CurvePoint(0.9875, 2.058947159052738),
|
||||
new CurvePoint(0.985, 1.8563887693647105),
|
||||
new CurvePoint(0.9825, 1.697536248647543),
|
||||
new CurvePoint(0.98, 1.5702410055532239),
|
||||
new CurvePoint(0.9775, 1.4664726399289512),
|
||||
new CurvePoint(0.975, 1.3807102743105126),
|
||||
new CurvePoint(0.9725, 1.3090333065057616),
|
||||
new CurvePoint(0.97, 1.2485807759957321),
|
||||
new CurvePoint(0.965, 1.1552120359501035),
|
||||
new CurvePoint(0.96, 1.0871883573850478),
|
||||
new CurvePoint(0.955, 1.0388633331418984),
|
||||
new CurvePoint(0.95, 1.0),
|
||||
new CurvePoint(0.94, 0.9417362980580238),
|
||||
new CurvePoint(0.93, 0.9039994071865736),
|
||||
new CurvePoint(0.92, 0.8728710341448851),
|
||||
new CurvePoint(0.91, 0.8488375988124467),
|
||||
new CurvePoint(0.9, 0.825756123560842),
|
||||
new CurvePoint(0.875, 0.7816934560296046),
|
||||
new CurvePoint(0.85, 0.7462290664143185),
|
||||
new CurvePoint(0.825, 0.7150465663454271),
|
||||
new CurvePoint(0.8, 0.6872268862950283),
|
||||
new CurvePoint(0.75, 0.6451808210101443),
|
||||
new CurvePoint(0.7, 0.6125565959114954),
|
||||
new CurvePoint(0.65, 0.5866010012767576),
|
||||
new CurvePoint(0, 0),
|
||||
new CurvePoint(0.6, 0.18223233667439062),
|
||||
new CurvePoint(0.0, 0.0)
|
||||
new CurvePoint(0.65, 0.5866010012767576),
|
||||
new CurvePoint(0.7, 0.6125565959114954),
|
||||
new CurvePoint(0.75, 0.6451808210101443),
|
||||
new CurvePoint(0.8, 0.6872268862950283),
|
||||
new CurvePoint(0.825, 0.7150465663454271),
|
||||
new CurvePoint(0.85, 0.7462290664143185),
|
||||
new CurvePoint(0.875, 0.7816934560296046),
|
||||
new CurvePoint(0.9, 0.825756123560842),
|
||||
new CurvePoint(0.91, 0.8488375988124467),
|
||||
new CurvePoint(0.92, 0.8728710341448851),
|
||||
new CurvePoint(0.93, 0.9039994071865736),
|
||||
new CurvePoint(0.94, 0.9417362980580238),
|
||||
new CurvePoint(0.95, 1),
|
||||
new CurvePoint(0.955, 1.0388633331418984),
|
||||
new CurvePoint(0.96, 1.0871883573850478),
|
||||
new CurvePoint(0.965, 1.1552120359501035),
|
||||
new CurvePoint(0.97, 1.2485807759957321),
|
||||
new CurvePoint(0.9725, 1.3090333065057616),
|
||||
new CurvePoint(0.975, 1.3807102743105126),
|
||||
new CurvePoint(0.9775, 1.4664726399289512),
|
||||
new CurvePoint(0.98, 1.5702410055532239),
|
||||
new CurvePoint(0.9825, 1.697536248647543),
|
||||
new CurvePoint(0.985, 1.8563887693647105),
|
||||
new CurvePoint(0.9875, 2.058947159052738),
|
||||
new CurvePoint(0.99, 2.324506282149922),
|
||||
new CurvePoint(0.99125, 2.4902905794106913),
|
||||
new CurvePoint(0.9925, 2.685667856592722),
|
||||
new CurvePoint(0.99375, 2.9190155639254955),
|
||||
new CurvePoint(0.995, 3.2022017597337955),
|
||||
new CurvePoint(0.99625, 3.5526145337555373),
|
||||
new CurvePoint(0.9975, 3.996793606763322),
|
||||
new CurvePoint(0.99825, 4.325027383589547),
|
||||
new CurvePoint(0.999, 4.715470646416203),
|
||||
new CurvePoint(0.9995, 5.019543595874787),
|
||||
new CurvePoint(1, 5.367394282890631),
|
||||
}
|
||||
));
|
||||
this.scoreSaberService = scoreSaberService;
|
||||
@ -116,26 +117,35 @@ public class ScoreSaberPlatform extends Platform {
|
||||
* @param accuracy The accuracy.
|
||||
* @return The modifier.
|
||||
*/
|
||||
public double getModifier(int curveVersion, double accuracy) {
|
||||
public double getModifier(double accuracy) {
|
||||
accuracy = MathUtils.clamp(accuracy, 0, 100) / 100;
|
||||
CurvePoint[] curve = this.getCurve(this.getCurrentCurveVersion());
|
||||
if (accuracy <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
CurvePoint prev = this.getCurvePoints().get(curveVersion)[1];
|
||||
for (CurvePoint point : this.getCurvePoints().get(curveVersion)) {
|
||||
if (point.getX() <= accuracy) {
|
||||
double distance = (prev.getX() - accuracy) / (prev.getX() - point.getX());
|
||||
return MathUtils.lerp(prev.getY(), point.getY(), distance);
|
||||
if (accuracy >= 1) {
|
||||
return curve[curve.length - 1].getMultiplier();
|
||||
}
|
||||
prev = point;
|
||||
|
||||
for (int i = 0; i < curve.length - 1; i++) {
|
||||
CurvePoint point = curve[i];
|
||||
CurvePoint nextPoint = curve[i + 1];
|
||||
if (accuracy >= point.getAcc() && accuracy <= nextPoint.getAcc()) {
|
||||
return MathUtils.lerp(point.getMultiplier(), nextPoint.getMultiplier(), (accuracy - point.getAcc()) / (nextPoint.getAcc() - point.getAcc()));
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getPp(int curveVersion, double stars, double accuracy) {
|
||||
this.checkCurveVersion(curveVersion); // Check if the curve version exists
|
||||
public double getPp(double stars, double accuracy) {
|
||||
if (accuracy <= 1) { // Convert the accuracy to a percentage
|
||||
accuracy *= 100;
|
||||
}
|
||||
double pp = stars * this.starMultiplier;
|
||||
double modifier = this.getModifier(curveVersion, accuracy);
|
||||
return modifier * pp;
|
||||
return this.getModifier(accuracy) * pp;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -201,13 +211,13 @@ public class ScoreSaberPlatform extends Platform {
|
||||
return false;
|
||||
}
|
||||
double oldPp = score.getPp();
|
||||
double pp = this.getPp(this.getCurrentCurveVersion(), leaderboard.getStars(), score.getAccuracy());
|
||||
double pp = this.getPp(leaderboard.getStars(), score.getAccuracy());
|
||||
log.info("Leaderboard: {}, Old PP: {}, New PP: {}", leaderboard.getSongName(), oldPp, pp);
|
||||
return pp != score.getPp(); // Check if the pp has changed
|
||||
}).toList();
|
||||
|
||||
for (TrackedScore score : toUpdate) { // Update the scores
|
||||
double pp = this.getPp(this.getCurrentCurveVersion(), leaderboard.getStars(), score.getAccuracy());
|
||||
double pp = this.getPp(leaderboard.getStars(), score.getAccuracy());
|
||||
score.setPp(pp);
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,6 @@ import cc.fascinated.model.token.ScoreSaberLeaderboardToken;
|
||||
import cc.fascinated.model.user.User;
|
||||
import cc.fascinated.repository.mongo.ScoreSaberLeaderboardRepository;
|
||||
import kong.unirest.core.HttpResponse;
|
||||
import kong.unirest.core.Unirest;
|
||||
import lombok.NonNull;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -10,10 +10,6 @@ import org.springframework.web.socket.WebSocketSession;
|
||||
import org.springframework.web.socket.client.standard.StandardWebSocketClient;
|
||||
import org.springframework.web.socket.handler.TextWebSocketHandler;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
/**
|
||||
* @author Fascinated (fascinated7)
|
||||
*/
|
||||
@ -35,31 +31,10 @@ public abstract class Websocket extends TextWebSocketHandler {
|
||||
*/
|
||||
private WebSocketSession webSocketSession;
|
||||
|
||||
/**
|
||||
* The last message received
|
||||
*/
|
||||
private Date lastMessage;
|
||||
|
||||
public Websocket(@NonNull String name, @NonNull String url) {
|
||||
this.name = name;
|
||||
this.url = url;
|
||||
connectWebSocket(); // Connect to the WebSocket.
|
||||
|
||||
new Timer().scheduleAtFixedRate(new TimerTask() {
|
||||
@Override @SneakyThrows
|
||||
public void run() {
|
||||
if (lastMessage == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
long difference = new Date().getTime() - lastMessage.getTime();
|
||||
if (difference > 10000) {
|
||||
log.error("The {} WebSocket has not received a message in over 10 seconds, reconnecting...", getName());
|
||||
webSocketSession.close(); // Close the WebSocket session.
|
||||
connectWebSocket(); // Reconnect to the WebSocket.
|
||||
}
|
||||
}
|
||||
}, 0, 5000);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -71,7 +46,6 @@ public abstract class Websocket extends TextWebSocketHandler {
|
||||
|
||||
@Override
|
||||
protected final void handleTextMessage(@NonNull WebSocketSession session, @NonNull TextMessage message) {
|
||||
this.lastMessage = new Date();
|
||||
this.handleMessage(message);
|
||||
}
|
||||
|
||||
@ -79,7 +53,7 @@ public abstract class Websocket extends TextWebSocketHandler {
|
||||
* Connects to the ScoreSaber WebSocket.
|
||||
*/
|
||||
@SneakyThrows
|
||||
private final void connectWebSocket() {
|
||||
private void connectWebSocket() {
|
||||
log.info("Connecting to the {}", this.getName());
|
||||
this.webSocketSession = new StandardWebSocketClient().execute(this, this.getUrl()).get();
|
||||
}
|
||||
|
Reference in New Issue
Block a user