<commit_before>package com.ljs.ifootballmanager.ai.report;

import com.ljs.ifootballmanager.ai.Context;
import com.ljs.ifootballmanager.ai.player.Player;
import com.ljs.ifootballmanager.ai.value.NowValue;
import java.io.PrintWriter;
import java.util.OptionalDouble;

public class SkillByAge implements Report {

  private Context ctx;

  private SkillByAge(Context ctx) {
    this.ctx = ctx;
  }

  private int getMinAge() {
    return Player.byAge().min(ctx.getSquad().players()).getAge();
  }

  private int getMaxAge() {
    return Player.byAge().max(ctx.getSquad().players()).getAge();
  }

  private OptionalDouble getAvgNowValue(int age) {
    return ctx.getSquad()
        .players()
        .stream()
        .filter(p -> p.getAge() == age)
        .mapToDouble(p -> NowValue.bestVsReplacement(ctx, p).getScore())
        .average();
  }

  private OptionalDouble getThreeYearAverage(int age) {
    if (age == getMinAge() || age == getMaxAge()) {
      return OptionalDouble.empty();
    }

    return ctx.getSquad()
        .players()
        .stream()
        .filter(p -> p.getAge() >= age - 1 && p.getAge() <= age + 1)
        .mapToDouble(p -> NowValue.bestVsReplacement(ctx, p).getScore())
        .average();
  }

  public double getAverageForComparison(int age) {
    if (age < getMinAge()) {
      return getAverageForComparison(getMinAge());
    }
    if (age > getMaxAge()) {
      return getAverageForComparison(getMaxAge());
    }

    double result = 0.0;
    for (int a = getMinAge(); a <= age; a++) {
      double current = getThreeYearAverage(a).orElseGet(() -> getAvgNowValue(age).orElse(0.0));

      result = Math.max(current, result);
    }

    return result;
  }

  public void print(PrintWriter w) {
    for (int age = getMinAge(); age <= getMaxAge(); age++) {
      w.format("%3d", age);
    }
<commit_msg>Fix SkillByAge calculation<commit_after>package com.ljs.ifootballmanager.ai.report;

import com.ljs.ifootballmanager.ai.Context;
import com.ljs.ifootballmanager.ai.player.Player;
import com.ljs.ifootballmanager.ai.value.NowValue;
import java.io.PrintWriter;
import java.util.OptionalDouble;

public class SkillByAge implements Report {

  private Context ctx;

  private SkillByAge(Context ctx) {
    this.ctx = ctx;
  }

  private int getMinAge() {
    return Player.byAge().min(ctx.getSquad().players()).getAge();
  }

  private int getMaxAge() {
    return Player.byAge().max(ctx.getSquad().players()).getAge();
  }

  private OptionalDouble getAvgNowValue(int age) {
    return ctx.getSquad()
        .players()
        .stream()
        .filter(p -> p.getAge() == age)
        .mapToDouble(p -> NowValue.bestVsReplacement(ctx, p).getScore())
        .average();
  }

  private OptionalDouble getThreeYearAverage(int age) {
    if (age == getMinAge() || age == getMaxAge()) {
      return OptionalDouble.empty();
    }

    return ctx.getSquad()
        .players()
        .stream()
        .filter(p -> p.getAge() >= age - 1 && p.getAge() <= age + 1)
        .mapToDouble(p -> NowValue.bestVsReplacement(ctx, p).getScore())
        .average();
  }

  public double getAverageForComparison(int age) {
    if (age < getMinAge()) {
      return getAverageForComparison(getMinAge());
    }
    if (age > getMaxAge()) {
      return getAverageForComparison(getMaxAge());
    }

    double result = 0.0;
    for (int a = getMinAge(); a <= age; a++) {
      double now = getAvgNowValue(a).orElse(0.0);
      double current = getThreeYearAverage(a).orElse(now);

      result = Math.max(current, result);
    }

    return result;
  }

  public void print(PrintWriter w) {
    for (int age = getMinAge(); age <= getMaxAge(); age++) {
      w.format("%3d", age);
    }

{'fraction_non_alphanumeric': 0.15010799136069114, 'fraction_numerical': 0.003779697624190065, 'mean_word_length': 2.975321888412017, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1693373', 'n_tokens_mistral': 1304, 'n_tokens_neox': 1210, 'n_words': 248}