<s> """<STR_LIT>""" <EOL> import logging <EOL> from os import makedirs <EOL> from os . path import ( join , <EOL> exists , <EOL> isfile , <EOL> dirname , <EOL> realpath , <EOL> basename , <EOL> splitext ) <EOL> from argparse import ( ArgumentParser , <EOL> ArgumentDefaultsHelpFormatter ) <EOL> from src import ( log_dir , <EOL> data_dir , <EOL> formatter , <EOL> reports_dir as default_reports_dir ) <EOL> logging_info = logging . INFO <EOL> logger = logging . getLogger ( '<STR_LIT>' ) <EOL> logger . setLevel ( logging_info ) <EOL> sh = logging . StreamHandler ( ) <EOL> sh . setLevel ( logging_info ) <EOL> logger . addHandler ( sh ) <EOL> loginfo = logger . info <EOL> logerr = logger . error <EOL> logwarn = logger . warning <EOL> def main ( ) : <EOL> parser = ArgumentParser ( usage = '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> description = '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> formatter_class = ArgumentDefaultsHelpFormatter ) <EOL> _add_arg = parser . add_argument <EOL> _add_arg ( '<STR_LIT>' , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> type = str , <EOL> required = True ) <EOL> _add_arg ( '<STR_LIT>' , '<STR_LIT>' , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> type = int , <EOL> default = <NUM_LIT> ) <EOL> _add_arg ( '<STR_LIT>' , '<STR_LIT>' , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> type = float , <EOL> default = <NUM_LIT> ) <EOL> _add_arg ( '<STR_LIT>' , '<STR_LIT>' , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> type = int , <EOL> required = False ) <EOL> _add_arg ( '<STR_LIT>' , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> type = float , <EOL> required = False ) <EOL> _add_arg ( '<STR_LIT>' , '<STR_LIT>' , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> default = False ) <EOL> _add_arg ( '<STR_LIT>' , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> action = '<STR_LIT:store_true>' , <EOL> default = False ) <EOL> _add_arg ( '<STR_LIT>' , <EOL> help = '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> type = str , <EOL> required = False ) <EOL> _add_arg ( '<STR_LIT>' , '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> type = str , <EOL> default = '<STR_LIT:localhost>' ) <EOL> _add_arg ( '<STR_LIT>' , '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> type = int , <EOL> default = <NUM_LIT> ) <EOL> _add_arg ( '<STR_LIT>' , '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> type = str , <EOL> default = join ( log_dir , '<STR_LIT>' ) ) <EOL> args = parser . parse_args ( ) <EOL> from os import listdir <EOL> from pymongo import MongoClient <EOL> from pymongo . errors import ConnectionFailure <EOL> from src import get_game_files <EOL> from src . mongodb import ( connect_to_db , <EOL> insert_train_test_reviews ) <EOL> game_files = args . game_files <EOL> max_size = args . max_size <EOL> percent_train = args . percent_train <EOL> convert_to_bins = args . convert_to_bins <EOL> bin_factor = args . bin_factor <EOL> make_reports = args . make_reports <EOL> just_describe = args . just_describe <EOL> reports_dir = args . reports_dir <EOL> mongodb_host = args . mongodb_host <EOL> mongodb_port = args . mongodb_port <EOL> log_file_path = realpath ( args . log_file_path ) <EOL> log_file_dir = dirname ( log_file_path ) <EOL> if not exists ( log_file_dir ) : <EOL> makedirs ( log_file_dir , exist_ok = True ) <EOL> fh = logging . FileHandler ( log_file_path ) <EOL> fh . setLevel ( logging_info ) <EOL> fh . setFormatter ( formatter ) <EOL> logger . addHandler ( fh ) <EOL> if convert_to_bins and convert_to_bins < <NUM_LIT:2> : <EOL> msg = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> logerr ( msg ) <EOL> raise ValueError ( msg ) <EOL> elif convert_to_bins : <EOL> bins = convert_to_bins <EOL> else : <EOL> bins = <NUM_LIT:0> <EOL> if bin_factor and not convert_to_bins : <EOL> msg = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> logerr ( msg ) <EOL> raise ValueError ( msg ) <EOL> loginfo ( '<STR_LIT>' <EOL> . format ( mongodb_host , mongodb_port ) ) <EOL> try : <EOL> reviewdb = connect_to_db ( host = mongodb_host , port = mongodb_port ) <EOL> except ConnectionFailure as e : <EOL> logerr ( '<STR_LIT>' ) <EOL> logerr ( e ) <EOL> raise e <EOL> reviewdb . write_concern [ '<STR_LIT:w>' ] = <NUM_LIT:0> <EOL> if reports_dir : <EOL> reports_dir = realpath ( reports_dir ) <EOL> if isfile ( reports_dir ) : <EOL> msg = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> logerr ( msg ) <EOL> raise ValueError ( msg ) <EOL> if not exists ( reports_dir ) : <EOL> makedirs ( reports_dir , exist_ok = True ) <EOL> if max_size < <NUM_LIT:50> : <EOL> msg = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> logerr ( msg ) <EOL> raise ValueError ( msg ) <EOL> if percent_train < <NUM_LIT:1.0> : <EOL> msg = ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> logerr ( msg ) <EOL> raise ValueError ( msg ) <EOL> if ( make_reports <EOL> and just_describe ) : <EOL> logwarn ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> elif reports_dir and ( make_reports or just_describe ) : <EOL> if not exists ( reports_dir ) : <EOL> logerr ( '<STR_LIT>' ) <EOL> exit ( <NUM_LIT:1> ) <EOL> game_files = get_game_files ( game_files , join ( dirname ( dirname ( __file__ ) ) , '<STR_LIT:data>' ) ) <EOL> loginfo ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> . format ( '<STR_LIT:U+002CU+0020>' . join ( [ splitext ( game ) [ <NUM_LIT:0> ] for game in game_files ] ) ) ) <EOL> loginfo ( '<STR_LIT>' <EOL> . format ( max_size ) ) <EOL> loginfo ( '<STR_LIT>' <EOL> . format ( percent_train , <NUM_LIT> - percent_train ) ) <EOL> if make_reports : <EOL> loginfo ( '<STR_LIT>' <EOL> . format ( reports_dir if reports_dir else default_reports_dir ) ) <EOL> if just_describe : <EOL> loginfo ( '<STR_LIT>' ) <EOL> if bins : <EOL> loginfo ( '<STR_LIT>' <EOL> '<STR_LIT>' . format ( bins , bin_factor ) ) <EOL> for game_file in game_files : <EOL> loginfo ( '<STR_LIT>' <EOL> . format ( splitext ( basename ( game_file ) ) [ <NUM_LIT:0> ] ) ) <EOL> insert_train_test_reviews ( reviewdb , realpath ( join ( data_dir , game_file ) ) , <EOL> max_size , percent_train , bins = bins , <EOL> bin_factor = bin_factor , describe = make_reports , <EOL> just_describe = just_describe , <EOL> reports_dir = reports_dir if reports_dir <EOL> else default_reports_dir ) <EOL> loginfo ( '<STR_LIT>' ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
