def predict_constants(html: str) -> ProblemConstantSet:
    try:
        yes_str, no_str = predict_yes_no(html)
    except YesNoPredictionFailedError:
        yes_str = no_str = None

    try:
        mod = predict_modulo(html)
    except MultipleModCandidatesError as e:
        logger.warning(
            "Modulo prediction failed -- "
            "two or more candidates {} are detected as modulo values".format(
                e.cands))
        mod = None

    try:
        judge = predict_judge_method(html)
    except MultipleModCandidatesError as e:
        logger.warning(
            "decimal prediction failed -- "
            "two or more candidates {} are detected as decimal values".format(
                e.cands))
        judge = NormalJudge()

    return ProblemConstantSet(mod=mod,
                              yes_str=yes_str,
                              no_str=no_str,
                              judge_method=judge)
Example #2
0
def get_metadata(metadata_file: str) -> Metadata:
    try:
        metadata = Metadata.load_from(metadata_file)
        return metadata
    except IOError:
        logger.warning("{} is not found. Default metadata is selected. ".format(
            metadata_file)
        )
        return Metadata.default_metadata()
Example #3
0
def get_sample_patterns(metadata_file: str) -> Tuple[str, str]:
    try:
        metadata = Metadata.load_from(metadata_file)
        return metadata.sample_in_pattern, metadata.sample_out_pattern
    except IOError:
        logger.warning(
            "{} is not found. Assume the example file name patterns are {} and {}"
            .format(metadata_file, DEFAULT_IN_EXAMPLE_PATTERN,
                    DEFAULT_OUT_EXAMPLE_PATTERN))
        return DEFAULT_IN_EXAMPLE_PATTERN, DEFAULT_OUT_EXAMPLE_PATTERN
Example #4
0
def infer_exec_file(filenames, exclude_exec_file):
    exec_files = [name for name in sorted(
        filenames) if is_executable_file(name) and (name not in exclude_exec_file)]

    if len(exec_files) == 0:
        raise NoExecutableFileError
    else:
        exec_file = exec_files[0]
    if len(exec_files) >= 2:
        logger.warning("{0}  {1}".format(
            "There're multiple executable files. '{exec_file}' is selected.".format(
                exec_file=exec_file),
            "The candidates were {exec_files}.".format(exec_files=exec_files)))
    return exec_file
Example #5
0
def prepare_contest(atcoder_client: AtCoderClient,
                    contest_id: str,
                    config: Config,
                    retry_delay_secs: float = 1.5,
                    retry_max_delay_secs: float = 60,
                    retry_max_tries: int = 10):
    attempt_count = 1
    while True:
        problem_list = atcoder_client.download_problem_list(
            Contest(contest_id=contest_id))
        if problem_list:
            break
        if 0 < retry_max_tries < attempt_count:
            raise EnvironmentInitializationError
        logger.warning(
            "Failed to fetch. Will retry in {} seconds. (Attempt {})".format(
                retry_delay_secs, attempt_count))
        time.sleep(retry_delay_secs)
        retry_delay_secs = min(retry_delay_secs * 2, retry_max_delay_secs)
        attempt_count += 1

    atcoder_client.download_contest_languages(problem_list)

    tasks = [(atcoder_client, problem, config) for problem in problem_list]

    output_splitter()

    if config.etc_config.parallel_download:
        thread_pool = Pool(processes=cpu_count())
        thread_pool.map(func, tasks)
    else:
        for argv in tasks:
            try:
                func(argv)
            except Exception:
                # Prevent the script from stopping
                print(traceback.format_exc(), file=sys.stderr)
                pass

    if config.postprocess_config.exec_cmd_on_contest_dir is not None:
        contest_dir_path = os.path.join(config.code_style_config.workspace_dir,
                                        contest_id)
        logger.info(
            _message_on_execution(
                contest_dir_path,
                config.postprocess_config.exec_cmd_on_contest_dir))
        config.postprocess_config.execute_on_contest_dir(contest_dir_path)
Example #6
0
def prepare_contest(atcoder_client: AtCoderClient,
                    contest_id: str,
                    config: Config):
    retry_duration = 1.5
    while True:
        problem_list = atcoder_client.download_problem_list(
            Contest(contest_id=contest_id))
        if problem_list:
            break
        sleep(retry_duration)
        logger.warning(
            "Failed to fetch. Will retry in {} seconds".format(retry_duration))

    tasks = [(atcoder_client,
              problem,
              config) for
             problem in problem_list]

    output_splitter()

    if config.etc_config.parallel_download:
        thread_pool = Pool(processes=cpu_count())
        thread_pool.map(func, tasks)
    else:
        for argv in tasks:
            try:
                func(argv)
            except Exception:
                # Prevent the script from stopping
                print(traceback.format_exc(), file=sys.stderr)
                pass

    if config.postprocess_config.exec_cmd_on_contest_dir is not None:
        contest_dir_path = os.path.join(
            config.code_style_config.workspace_dir, contest_id)
        logger.info(_message_on_execution(contest_dir_path,
                                          config.postprocess_config.exec_cmd_on_contest_dir))
        config.postprocess_config.execute_on_contest_dir(
            contest_dir_path)
Example #7
0
 def emit_warning(text):
     logger.warning(text)
Example #8
0
 def emit_warning(text):
     logger.warning("Problem {}: {}".format(pid, text))