#!/usr/bin/env python3
import click
import os
import sys

path = os.path.dirname(os.path.abspath(__file__)).strip("bin")
sys.path.append(path)
from ml4chem.visualization import read_log, plot_atomic_features


@click.command()
@click.option("--plot", default=None, help="Plot information from file.")
@click.option(
    "--backend",
    default="seaborn",
    help='Select backed to plot, supported "plotly", and "seaborn". Default is "searborn".',
)
@click.option("--file", default=None, help="Path to log file or database.")
@click.option(
    "--refresh",
    default=None,
    type=float,
    help="Useful for sleeping before reading log files.",
)
def main(**args):
    """ML4Chem command line tool"""
    training_plots = ["training", "loss", "test", "combined"]
    dim_visualization = ["pca", "tsne"]

    _file = args["file"]

    if args["plot"] is not None:
        if args["plot"] in training_plots:
            metric = args["plot"]
            refresh = args["refresh"]
            plt = read_log(_file, metric=metric, refresh=refresh)

        elif args["plot"].lower() in dim_visualization:
            method = args["plot"]
            backend = args["backend"]
            plot_atomic_features(_file, method=method, backend=backend)

        else: 
            raise NotImplementedError(f"Supported values are {training_plots}")

if __name__ == "__main__":
    main()
