naiveBayes_intep.classify(trainPath, testPath, resultFile,
                                              0.1)
                else:
                    naiveBayesNPP_prior.classify(trainPath, testPath,
                                                 resultFile, city_format_file,
                                                 0.1)

            except Exception as e:
                print("got error: ", e)
                continue
#-----merge_results-----

print("nb_type x = ", nb_type)
if nb_type == "intep":
    merge_result_intep.merge_results(expFol, str(time_window + 1), data_type,
                                     final_output)
else:
    merge_results.merge_results(expFol, str(time_window + 1), data_type,
                                final_output)
#----delete folds to save space----

import shutil

if delete_folds:
    print("deleting...")
    for i in range(1, 11):
        print("deleting fold..", i)
        shutil.rmtree(expFol + '/fold' + str(i))

print("Done")
Beispiel #2
0
def run_module(
    module,
    preserve_tmp_clones=False,
    capture_output=True,
    shell=False,
    ports=None,
):
    module = Path(module).absolute().resolve()
    runs_path = get_runs_clone(module)

    if capture_output:
        runner_logs_dir = runs_path / LOGS_DIR / RUNNER_LOGS_DIR / now_str
        runner_logs_dir.mkdir(parents=True)
        stdout_path = runner_logs_dir / RUNNER_STDOUT_BASENAME
        stderr_path = runner_logs_dir / RUNNER_STDERR_BASENAME

        print('Redirecting stdout/stderr to %s, %s' % (stdout_path, stderr_path))
        original_stdout = sys.stdout
        original_stderr = sys.stderr
        sys.stdout = stdout_path.open('w')
        sys.stderr = stderr_path.open('w')

    print('%s: module %s starting' % (now_str, module))

    try:
        dir = TemporaryDirectory(prefix='gismo_')

        if preserve_tmp_clones:
            from contextlib import nullcontext
            ctx = nullcontext()
        else:
            ctx = dir

        with ctx:
            dir = Path(dir.name)

            with cd(module):

                config = load_config()
                name = get_name(config)
                dockerfile_src, cmd = make_cmd(config, dir, shell=shell, ports=ports)
                run([ 'git', 'clone', module, dir ])

                dockerfile = dir / DOCKERFILE_PATH
                print('Installing Dockerfile %s in temporary clone: %s' % (dockerfile_src, dockerfile))
                dockerfile_src.rename(dockerfile)

                git.set_user_configs(name)

                with cd(dir):
                    run([ 'docker', 'build', '-t', name, '-f', dockerfile, '.' ])
                    remote = git.remote()

                    # if not upstream_branch:
                    # upstream_branch = DEFAULT_UPSTREAM_BRANCH
                    [ _remote, upstream_branch ] = line(['git','rev-parse','--abbrev-ref','--symbolic-full-name','@{u}']).split('/')
                    assert _remote == remote
                    upstream_remote_branch = '%s/%s' % (remote, upstream_branch)

                    original_upstream_sha = git.sha(upstream_remote_branch)
                    print('Working from upstream branch %s (%s)' % (upstream_remote_branch, original_upstream_sha))

                    base_sha = git.sha()
                    if original_upstream_sha != base_sha:
                        print('Overriding cloned HEAD %s to start from upstream %s (%s)' % (base_sha, upstream_remote_branch, original_upstream_sha))
                        git.checkout(upstream_remote_branch)
                        base_sha = original_upstream_sha

                    run(cmd)

                    if shell: return

                    run_sha, msg = make_run_commit(config)

                    merge_results(
                        module,
                        runs_path=runs_path,
                        config=config,
                        base_sha=base_sha,
                        run_sha=run_sha,
                        msg=msg,
                        original_upstream_sha=original_upstream_sha,
                        remote=remote,
                        upstream_branch=upstream_branch,
                        now_str=now_str,
                    )
    finally:
        if capture_output:
            print('Restoring stdout, stderr')
            sys.stdout.close()
            sys.stderr.close()
            sys.stdout = original_stdout
            sys.stderr = original_stderr