Sueta

RankingLib

1.0.1

Using this libraries to get the rank of players with normalization!

·Plugin

Using this libraries to calculate the rank with customizable method!

This plugin is for developer use only. If you want to try the calculation with normalized data, you can check out this.

About Maven

<repository>
            <id>xuan</id>
            <url>http://xuan.nctu.me:8081/repository/Maven/</url>
</repository>

<dependency>
  <groupId>com.ericlam.mc</groupId>
  <artifactId>RankingLib</artifactId>
  <version>1.0.0</version>
</dependency>

Example
The implementation example is in here.

Tutorial
First, hooking the RankingLib.jar into your project.

And then you would like to call the API as below

RankLibAPI api = RankingLib.getRankAPI();

In general, RankingLib has provided two default calculators inside(z_score and min max, both are normalization) . However, if you wish to create your own calculation method, you can create as below
For example, I wanna create a calculation method named "z-score"

api.registerCalculator("z-score", (playerData, ladderRanks, arrayData) -> {
            double v = playerData.getScore();
            double result = AdvMath.round(2, (v - arrayData.getMean()) / arrayData.getSd());
            int minScore = (int) -Math.floor((int) (ladderRanks.size() / 2));
            int scoreIndex = ((int) result) - minScore;
            if (scoreIndex < 0) {
                return ladderRanks.get(0);
            } else if (scoreIndex > ladderRanks.size()) {
                return ladderRanks.get(ladderRanks.size() - 1);
            }
            RankDataImpl rank = (RankDataImpl) ladderRanks.get(scoreIndex);
            rank.setnScore(result);
            rank.setOrigScore(v);
            return rank;
        });


After that, you need to call a factory and put all of your player data and rank data to build the RankDataManager:

RankDataManager manager = api.getFactory().addPlayers(dataList).registerRanks(rankData).build();

dataList = List<PlayerData>
rankData = TreeSet<RankData>

These two need to create by your own.

You may need to register the saving mechanic if you want to save the player data.

To do calculate, you would like to use the method as below:

manager.doCalculate("z-score").whenComplete((map, ex) -> {
            if (ex != null) {
                ex.printStackTrace();
            }
        });

Then the result has generated.

You can use other method to do what you want!

Check out the other method in RankDataManager from here

Similar projects

Plugin →