LearnData.java 文件源码

java
阅读 29 收藏 0 点赞 0 评论 0

项目:Crescent 作者:
public void storeNewData(Learn learn, KnownCheating knownCheating) {
    final FileConfiguration fc = getConfig();

    // Generate a UUID for this check (its identifier).
    UUID uuid = UUID.randomUUID();

    while (fc.isConfigurationSection(uuid.toString())) {
        uuid = UUID.randomUUID();
    }

    // The path to put the data in the file.
    String cheatPath = getCheatPath(knownCheating);

    // Get general values.
    final double currentMean = fc.getDouble(cheatPath + "CurrentMean");
    final double currentLowRange = fc.getDouble(cheatPath + "CurrentLowRange");
    final double currentHighRange = fc.getDouble(cheatPath + "CurrentHighRange");
    final long totalSamples = fc.getLong(cheatPath + "TotalSamples");

    if (currentLowRange == 0.0 || learn.getValue() < currentLowRange) {
        fc.set(cheatPath + "CurrentLowRange", learn.getValue());
    } else if (learn.getValue() > currentHighRange) {
        fc.set(cheatPath + "CurrentHighRange", learn.getValue());
    }

    // Calculate the new average.
    double updateMean = (currentMean + learn.getValue()) / 2.0;

    fc.set(cheatPath + "CurrentMean", updateMean);
    fc.set(cheatPath + "TotalSamples", totalSamples + 1);

    // Save the file.
    save(fc);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号