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

import com.google.common.base.Charsets;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicates;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Ordering;
import com.google.common.collect.Sets;
import com.google.common.io.CharSink;
import com.google.common.io.Files;
import com.ljs.ifootballmanager.ai.formation.Formation;
import com.ljs.ifootballmanager.ai.formation.SelectionCriteria;
import com.ljs.ifootballmanager.ai.formation.score.DefaultScorer;
import com.ljs.ifootballmanager.ai.formation.score.FormationScorer;
import com.ljs.ifootballmanager.ai.league.EliteFootballLeague;
import com.ljs.ifootballmanager.ai.league.Ffo;
import com.ljs.ifootballmanager.ai.league.League;
import com.ljs.ifootballmanager.ai.league.LeagueHolder;
import com.ljs.ifootballmanager.ai.league.Ssl;
import com.ljs.ifootballmanager.ai.math.Maths;
import com.ljs.ifootballmanager.ai.player.Player;
import com.ljs.ifootballmanager.ai.player.Squad;
import com.ljs.ifootballmanager.ai.player.SquadHolder;
import com.ljs.ifootballmanager.ai.report.ReplacementLevelReport;
import com.ljs.ifootballmanager.ai.report.Report;
import com.ljs.ifootballmanager.ai.report.Reports;
import com.ljs.ifootballmanager.ai.report.SkillByAge;
import com.ljs.ifootballmanager.ai.report.SquadReport;
import com.ljs.ifootballmanager.ai.report.SquadSummaryReport;
import com.ljs.ifootballmanager.ai.report.TeamSheet;
import com.ljs.ifootballmanager.ai.selection.Bench;
import com.ljs.ifootballmanager.ai.selection.ChangePlan;
import com.ljs.ifootballmanager.ai.selection.FirstXI;
import com.ljs.ifootballmanager.ai.selection.RestPlan;
import com.ljs.ifootballmanager.ai.value.NowValue;
import com.ljs.ifootballmanager.ai.value.OverallValue;
import com.ljs.ifootballmanager.ai.value.ReplacementLevel;
import com.ljs.ifootballmanager.ai.value.ReplacementLevelHolder;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.Set;

/** Hello world! */
public class Main {

  private static final ImmutableMap<String, League> SITES =
      ImmutableMap.<String, League>builder()
          .put("EFL_TTH", EliteFootballLeague.create())
          .put("FFO_CSK", Ffo.create())
          //.put("IFM_LIV", IFootballManager.create("liv"))
          //.put("IFM_ NOR", IFootballManager.create("nor"))
          //.put("IFM - DER", IFootballManager.create("der"))
          //.put("IFM - Holland", IFootballManager.create("hol"))
          //.put("JAFL_GLI", Jafl.get())
          .put("SSL_MIS", Ssl.create("mis", "msy"))
          //.put("SSL - ARG", Ssl.create("arg"))
          .build();

  public static void main(String[] args) throws IOException {
    new Main().run();
  }

  public void run() throws IOException {
    String site = System.getenv("ESMSAI_SITE");

    Preconditions.checkNotNull(site, "ESMSAI_SITE must be provided");

    run(SITES.get(site));
  }

  private void run(League league) throws IOException {
    try (Writer w = output(league).openStream();
        PrintWriter p = new PrintWriter(w); ) {

      run(league, p);

      p.flush();
    }
  }

  private CharSink output(League league) {
    File baseDir = Config.get().getDataDirectory();
    return Files.asCharSink(new File(baseDir, league.getTeam() + "ovr.txt"), Charsets.ISO_8859_1);
  }

  public void run(League league, PrintWriter w) throws IOException {
    System.out.println("Running for: " + league.getTeam());

    Context ctx = new Context();

    ctx.setLeague(league);
    LeagueHolder.set(league);

    Squad squad = Squad.load(league);
    ctx.setSquad(squad);
    SquadHolder.set(squad);

    ctx.setFirstXI(FirstXI.select(ctx));

    Set<Player> allFirstXI = ctx.getFirstXI().getPlayers();

    Formation bestXI = ctx.getFirstXI().best();

    ReplacementLevelHolder.set(ReplacementLevel.create(ctx));
    ctx.setReplacementLevel(ReplacementLevelHolder.get());

    SkillByAge sba = SkillByAge.create(ctx);

    ctx.setSkillByAge(sba);

    print(w, SquadReport.create(ctx, bestXI.getTactic(), squad.players()).sortByValue());

    print(w, sba);

    ctx.getFirstXI().getFormations().forEach(f -> print(w, "1st XI", f));

    Set<Player> remaining =
        Sets.newHashSet(
            Sets.difference(
                ImmutableSet.copyOf(squad.players()), ImmutableSet.copyOf(bestXI.players())));

    Set<Player> reservesSquad = Sets.newHashSet();
    Formation reservesXI = null;
    Set<Player> allReservesXI = Sets.newHashSet();
    if (league.getReserveTeam().isPresent()) {
      ImmutableList<Formation> reserveXICandiates =
          Formation.select(
              league,
              SelectionCriteria.create(ImmutableSet.<Player>of(), squad.reserves(league)),
              DefaultScorer.get());
      reservesXI = reserveXICandiates.get(0);

      for (Formation f : reserveXICandiates) {
        allReservesXI.addAll(f.players());
      }

      print(w, "Reserves XI", reservesXI);
      for (Player p : allReservesXI) {
        reservesSquad.add(squad.findPlayer(p.getName()));
      }
    }

    Set<Player> desiredSquad = Sets.newHashSet();
    desiredSquad.addAll(allFirstXI);

    Set<Player> firstSquad = Sets.newHashSet();

    for (Player p : desiredSquad) {
      if (p.isReserves()) {<commit_msg>Change to remove allFirstXI from remaining<commit_after>package com.ljs.ifootballmanager.ai;

import com.google.common.base.Charsets;
import com.google.common.base.Preconditions;
import com.google.common.base.Predicates;
import com.google.common.collect.FluentIterable;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterables;
import com.google.common.collect.Ordering;
import com.google.common.collect.Sets;
import com.google.common.io.CharSink;
import com.google.common.io.Files;
import com.ljs.ifootballmanager.ai.formation.Formation;
import com.ljs.ifootballmanager.ai.formation.SelectionCriteria;
import com.ljs.ifootballmanager.ai.formation.score.DefaultScorer;
import com.ljs.ifootballmanager.ai.formation.score.FormationScorer;
import com.ljs.ifootballmanager.ai.league.EliteFootballLeague;
import com.ljs.ifootballmanager.ai.league.Ffo;
import com.ljs.ifootballmanager.ai.league.League;
import com.ljs.ifootballmanager.ai.league.LeagueHolder;
import com.ljs.ifootballmanager.ai.league.Ssl;
import com.ljs.ifootballmanager.ai.math.Maths;
import com.ljs.ifootballmanager.ai.player.Player;
import com.ljs.ifootballmanager.ai.player.Squad;
import com.ljs.ifootballmanager.ai.player.SquadHolder;
import com.ljs.ifootballmanager.ai.report.ReplacementLevelReport;
import com.ljs.ifootballmanager.ai.report.Report;
import com.ljs.ifootballmanager.ai.report.Reports;
import com.ljs.ifootballmanager.ai.report.SkillByAge;
import com.ljs.ifootballmanager.ai.report.SquadReport;
import com.ljs.ifootballmanager.ai.report.SquadSummaryReport;
import com.ljs.ifootballmanager.ai.report.TeamSheet;
import com.ljs.ifootballmanager.ai.selection.Bench;
import com.ljs.ifootballmanager.ai.selection.ChangePlan;
import com.ljs.ifootballmanager.ai.selection.FirstXI;
import com.ljs.ifootballmanager.ai.selection.RestPlan;
import com.ljs.ifootballmanager.ai.value.NowValue;
import com.ljs.ifootballmanager.ai.value.OverallValue;
import com.ljs.ifootballmanager.ai.value.ReplacementLevel;
import com.ljs.ifootballmanager.ai.value.ReplacementLevelHolder;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.Set;

/** Hello world! */
public class Main {

  private static final ImmutableMap<String, League> SITES =
      ImmutableMap.<String, League>builder()
          .put("EFL_TTH", EliteFootballLeague.create())
          .put("FFO_CSK", Ffo.create())
          //.put("IFM_LIV", IFootballManager.create("liv"))
          //.put("IFM_ NOR", IFootballManager.create("nor"))
          //.put("IFM - DER", IFootballManager.create("der"))
          //.put("IFM - Holland", IFootballManager.create("hol"))
          //.put("JAFL_GLI", Jafl.get())
          .put("SSL_MIS", Ssl.create("mis", "msy"))
          //.put("SSL - ARG", Ssl.create("arg"))
          .build();

  public static void main(String[] args) throws IOException {
    new Main().run();
  }

  public void run() throws IOException {
    String site = System.getenv("ESMSAI_SITE");

    Preconditions.checkNotNull(site, "ESMSAI_SITE must be provided");

    run(SITES.get(site));
  }

  private void run(League league) throws IOException {
    try (Writer w = output(league).openStream();
        PrintWriter p = new PrintWriter(w); ) {

      run(league, p);

      p.flush();
    }
  }

  private CharSink output(League league) {
    File baseDir = Config.get().getDataDirectory();
    return Files.asCharSink(new File(baseDir, league.getTeam() + "ovr.txt"), Charsets.ISO_8859_1);
  }

  public void run(League league, PrintWriter w) throws IOException {
    System.out.println("Running for: " + league.getTeam());

    Context ctx = new Context();

    ctx.setLeague(league);
    LeagueHolder.set(league);

    Squad squad = Squad.load(league);
    ctx.setSquad(squad);
    SquadHolder.set(squad);

    ctx.setFirstXI(FirstXI.select(ctx));

    Set<Player> allFirstXI = ctx.getFirstXI().getPlayers();

    Formation bestXI = ctx.getFirstXI().best();

    ReplacementLevelHolder.set(ReplacementLevel.create(ctx));
    ctx.setReplacementLevel(ReplacementLevelHolder.get());

    SkillByAge sba = SkillByAge.create(ctx);

    ctx.setSkillByAge(sba);

    print(w, SquadReport.create(ctx, bestXI.getTactic(), squad.players()).sortByValue());

    print(w, sba);

    ctx.getFirstXI().getFormations().forEach(f -> print(w, "1st XI", f));

    Set<Player> remaining =
        Sets.newHashSet(
            Sets.difference(
                ImmutableSet.copyOf(squad.players()), allFirstXI));

    Set<Player> reservesSquad = Sets.newHashSet();
    Formation reservesXI = null;
    Set<Player> allReservesXI = Sets.newHashSet();
    if (league.getReserveTeam().isPresent()) {
      ImmutableList<Formation> reserveXICandiates =
          Formation.select(
              league,
              SelectionCriteria.create(ImmutableSet.<Player>of(), squad.reserves(league)),
              DefaultScorer.get());
      reservesXI = reserveXICandiates.get(0);

      for (Formation f : reserveXICandiates) {
        allReservesXI.addAll(f.players());
      }

      print(w, "Reserves XI", reservesXI);
      for (Player p : allReservesXI) {
        reservesSquad.add(squad.findPlayer(p.getName()));
      }
    }

    Set<Player> desiredSquad = Sets.newHashSet();
    desiredSquad.addAll(allFirstXI);

    Set<Player> firstSquad = Sets.newHashSet();

    for (Player p : desiredSquad) {
      if (p.isReserves()) {
{'fraction_non_alphanumeric': 0.13375451263537907, 'fraction_numerical': 0.001263537906137184, 'mean_word_length': 4.004968383017164, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 25, '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': '2885777', 'n_tokens_mistral': 3767, 'n_tokens_neox': 3613, 'n_words': 567}