-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
104 additions
and
52 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...src/main/java/me/caseload/knockbacksync/listener/bukkit/BukkitPlayerJoinQuitListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
common/src/main/java/me/caseload/knockbacksync/listener/PlayerDamageListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
common/src/main/java/me/caseload/knockbacksync/listener/PlayerJoinQuitListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
common/src/main/java/me/caseload/knockbacksync/manager/PlayerDataManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
common/src/main/java/me/caseload/knockbacksync/player/JitterCalculator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package me.caseload.knockbacksync.player; | ||
|
||
import lombok.Getter; | ||
|
||
import java.util.*; | ||
import java.util.stream.Collectors; | ||
|
||
public class JitterCalculator { | ||
private final int SAMPLE_SIZE = 15; | ||
private final Queue<Long> pings = new LinkedList<>(); | ||
@Getter | ||
private long sequenceNumber = 0; | ||
|
||
public void addPing(long pingTime, long receivedSequence) { | ||
pings.offer(pingTime); | ||
if (pings.size() > SAMPLE_SIZE) { | ||
pings.poll(); | ||
} | ||
|
||
// Check for out-of-order packets | ||
if (receivedSequence < sequenceNumber) { | ||
// Handle out-of-order packet | ||
} | ||
sequenceNumber = receivedSequence; | ||
} | ||
|
||
public double calculateJitter() { | ||
if (pings.size() < 2) return 0; | ||
|
||
List<Long> sortedPings = new ArrayList<>(pings); | ||
Collections.sort(sortedPings); | ||
|
||
// Calculate IQR | ||
int q1Index = sortedPings.size() / 4; | ||
int q3Index = q1Index * 3; | ||
long q1 = sortedPings.get(q1Index); | ||
long q3 = sortedPings.get(q3Index); | ||
long iqr = q3 - q1; | ||
|
||
// Filter outliers | ||
double lowerBound = q1 - 1.5 * iqr; | ||
double upperBound = q3 + 1.5 * iqr; | ||
List<Long> filteredPings = sortedPings.stream() | ||
.filter(p -> p >= lowerBound && p <= upperBound) | ||
.toList(); | ||
|
||
// Calculate standard deviation | ||
double mean = filteredPings.stream().mapToLong(Long::longValue).average().orElse(0); | ||
double variance = filteredPings.stream() | ||
.mapToDouble(p -> Math.pow(p - mean, 2)) | ||
.average().orElse(0); | ||
double stdDev = Math.sqrt(variance); | ||
|
||
// Calculate mean jitter | ||
double meanJitter = 0; | ||
Long prevPing = null; | ||
for (Long ping : filteredPings) { | ||
if (prevPing != null) { | ||
meanJitter += Math.abs(ping - prevPing); | ||
} | ||
prevPing = ping; | ||
} | ||
meanJitter /= (filteredPings.size() - 1); | ||
|
||
// You can return different jitter metrics based on your needs | ||
return stdDev; // or meanJitter, or both | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 1 addition & 2 deletions
3
common/src/main/java/me/caseload/knockbacksync/stats/custom/PlayerVersionsPie.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...src/main/java/me/caseload/knockbacksync/listener/fabric/FabricPlayerJoinQuitListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters