#!/usr/bin/env python
import argparse
from Experiments import GridSearch, Datasets
from Utils import EnvDefault

"""Do experiment and build result file, optionally print report with results
"""


def parse_arguments():
    ap = argparse.ArgumentParser()
    ap.add_argument(
        "-s",
        "--score",
        action=EnvDefault,
        envvar="score",
        type=str,
        required=True,
        help="score name {accuracy, f1_macro, ...}",
    )
    ap.add_argument(
        "-P",
        "--platform",
        action=EnvDefault,
        envvar="platform",
        type=str,
        required=True,
        help="Platform where the test is run",
    )
    ap.add_argument(
        "-m",
        "--model",
        type=str,
        required=True,
        help="model name",
    )
    ap.add_argument(
        "-n",
        "--n_folds",
        action=EnvDefault,
        envvar="n_folds",
        type=int,
        required=True,
        help="number of folds",
    )
    ap.add_argument(
        "-q",
        "--quiet",
        type=bool,
        default=False,
        required=False,
        help="Wether to show progress bar or not",
    )
    ap.add_argument(
        "-t",
        "--stratified",
        action=EnvDefault,
        envvar="stratified",
        type=str,
        required=True,
        help="Stratified",
    )
    ap.add_argument(
        "-d",
        "--dataset",
        type=str,
        required=True,
        default=None,
        help="Gridsearch on this dataset",
    )
    args = ap.parse_args()
    return (
        args.stratified,
        args.score,
        args.model,
        args.n_folds,
        args.platform,
        args.quiet,
        args.dataset,
    )


(
    stratified,
    score,
    model,
    folds,
    platform,
    quiet,
    dataset,
) = parse_arguments()
job = GridSearch(
    score_name=score,
    model_name=model,
    stratified=stratified,
    datasets=Datasets(dataset=dataset),
    progress_bar=not quiet,
    platform=platform,
    folds=folds,
)
job.do_gridsearch()
