<commit_before>from pymongo import MongoClient

from chess import uci

from modules.fishnet.fishnet import stockfish_command

from modules.core.Game import GameDB
from modules.core.GameAnalysis import GameAnalysisDB
from modules.core.Player import PlayerDB

from modules.Api import Api

from modules.irwin.Irwin import Irwin
from modules.irwin.TrainingStats import TrainingStatsDB
from modules.irwin.FalseReports import FalseReportsDB
from modules.irwin.GameAnalysisPlayerPivot import GameAnalysisPlayerPivotDB
from modules.irwin.ConfidentGameAnalysisPivot import ConfidentGameAnalysisPivotDB
from modules.irwin.PlayerGameActivations import PlayerGameActivationsDB
from modules.irwin.PlayerGameWords import PlayerGameWordsDB

class Env:
  def __init__(self, settings):
    self.settings = settings

    self.engine = uci.popen_engine(stockfish_command(settings['stockfish']['update']))
    self.engine.setoption({'Threads': settings['stockfish']['threads'], 'Hash': settings['stockfish']['memory']})
    self.engine.uci()
    self.infoHandler = uci.InfoHandler()
    self.engine.info_handlers.append(self.infoHandler)

    self.api = Api(settings['api']['url'], settings['api']['token'])

    # Set up mongodb
    self.client = MongoClient(settings['db']['host'])
    self.db = self.client.irwin
    if settings['db']['authenticate']:
      self.db.authenticate(
        settings['db']['authentication']['username'],
        settings['db']['authentication']['password'], mechanism='MONGODB-CR')

    # Colls
    self.playerColl = self.db.player
    self.gameColl = self.db.game
    self.gameAnalysisColl = self.db.gameAnalysis

    self.gameAnalysisPlayerPivotColl = self.db.gameAnalysisPlayerPivot
    self.confidentGameAnalysisPivotColl = self.db.confidentGameAnalysisPivot
    self.playerGameActivationsColl = self.db.playerGameActivations
    self.playerGameWordsColl = self.db.playerGameWords

    # database abstraction
    self.playerDB = PlayerDB(self.playerColl)
    self.gameDB = GameDB(self.gameColl)
    self.gameAnalysisDB = GameAnalysisDB(self.gameAnalysisColl)

    self.gameAnalysisPlayerPivotDB = GameAnalysisPlayerPivotDB(self.gameAnalysisPlayerPivotColl)
    self.confidentGameAnalysisPivotDB = ConfidentGameAnalysisPivotDB(self.confidentGameAnalysisPivotColl)
    self.playerGameActivationsDB = PlayerGameActivationsDB(self.playerGameActivationsColl)
    self.playerGameWordsDB = PlayerGameWordsDB(self.playerGameWordsColl)

    # Irwin
    self.irwin = Irwin(self, settings['irwin'])

  def __del__(self):
    print("Removing Env")<commit_msg>cleanup env better<commit_after>from pymongo import MongoClient

from chess import uci

from modules.fishnet.fishnet import stockfish_command

from modules.core.Game import GameDB
from modules.core.GameAnalysis import GameAnalysisDB
from modules.core.Player import PlayerDB

from modules.Api import Api

from modules.irwin.Irwin import Irwin
from modules.irwin.TrainingStats import TrainingStatsDB
from modules.irwin.FalseReports import FalseReportsDB
from modules.irwin.GameAnalysisPlayerPivot import GameAnalysisPlayerPivotDB
from modules.irwin.ConfidentGameAnalysisPivot import ConfidentGameAnalysisPivotDB
from modules.irwin.PlayerGameActivations import PlayerGameActivationsDB
from modules.irwin.PlayerGameWords import PlayerGameWordsDB

class Env:
  def __init__(self, settings):
    self.settings = settings

    self.engine = uci.popen_engine(stockfish_command(settings['stockfish']['update']))
    self.engine.setoption({'Threads': settings['stockfish']['threads'], 'Hash': settings['stockfish']['memory']})
    self.engine.uci()
    self.infoHandler = uci.InfoHandler()
    self.engine.info_handlers.append(self.infoHandler)

    self.api = Api(settings['api']['url'], settings['api']['token'])

    # Set up mongodb
    self.client = MongoClient(settings['db']['host'])
    self.db = self.client.irwin
    if settings['db']['authenticate']:
      self.db.authenticate(
        settings['db']['authentication']['username'],
        settings['db']['authentication']['password'], mechanism='MONGODB-CR')

    # Colls
    self.playerColl = self.db.player
    self.gameColl = self.db.game
    self.gameAnalysisColl = self.db.gameAnalysis

    self.gameAnalysisPlayerPivotColl = self.db.gameAnalysisPlayerPivot
    self.confidentGameAnalysisPivotColl = self.db.confidentGameAnalysisPivot
    self.playerGameActivationsColl = self.db.playerGameActivations
    self.playerGameWordsColl = self.db.playerGameWords

    # database abstraction
    self.playerDB = PlayerDB(self.playerColl)
    self.gameDB = GameDB(self.gameColl)
    self.gameAnalysisDB = GameAnalysisDB(self.gameAnalysisColl)

    self.gameAnalysisPlayerPivotDB = GameAnalysisPlayerPivotDB(self.gameAnalysisPlayerPivotColl)
    self.confidentGameAnalysisPivotDB = ConfidentGameAnalysisPivotDB(self.confidentGameAnalysisPivotColl)
    self.playerGameActivationsDB = PlayerGameActivationsDB(self.playerGameActivationsColl)
    self.playerGameWordsDB = PlayerGameWordsDB(self.playerGameWordsColl)

    # Irwin
    self.irwin = Irwin(self, settings['irwin'])

  def __del__(self):
    print("Removing Env")
    self.engine.kill()
{'fraction_non_alphanumeric': 0.09968968192397207, 'fraction_numerical': 0.0, 'mean_word_length': 5.478643216080402, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '7066097', 'n_tokens_mistral': 1515, 'n_tokens_neox': 1468, 'n_words': 258}