import json

import pandas as pd
from numpy import array, ndarray, vstack
from sklearn.datasets import load_breast_cancer as cancer
from sklearn.datasets import load_iris as iris
from sklearn.datasets import load_wine as wine


def get_bank_data(test=False):
    # Opening JSON file
    with open("data/big_data/bank.json") as json_file:
        data = json.load(json_file)
    if test:
        return array(data["Xtest"]), array(data["Ytest"])
    else:
        return array(data["Xtrain"]), array(data["Ytrain"])

def get_carbon_data():
    # Opening JSON file
    with open("data/regress/carbon.json") as json_file:
        data = json.load(json_file)
    return array(data["Xtrain"]), array(data["Ytrain"]), array(data["Xtest"]), array(data["Ytest"])

def get_casp_data():
    # Opening JSON file
    with open("data/regress/casp.json") as json_file:
        data = json.load(json_file)
    return array(data["Xtrain"]), array(data["Ytrain"]), array(data["Xtest"]), array(data["Ytest"])

def get_concrete_data():
    # Opening JSON file
    with open("data/regress/concrete.json") as json_file:
        data = json.load(json_file)
    return array(data["Xtrain"]), array(data["Ytrain"]), array(data["Xtest"]), array(data["Ytest"])

def get_energy_data():
    # Opening JSON file
    with open("data/regress/energy.json") as json_file:
        data = json.load(json_file)
    return array(data["Xtrain"]), array(data["Ytrain"]), array(data["Xtest"]), array(data["Ytest"])

def get_fish_data():
    # Opening JSON file
    with open("data/regress/fish.json") as json_file:
        data = json.load(json_file)
    return array(data["Xtrain"]), array(data["Ytrain"]), array(data["Xtest"]), array(data["Ytest"])

def get_gas_data():
    # Opening JSON file
    with open("data/regress/gas.json") as json_file:
        data = json.load(json_file)
    return array(data["Xtrain"]), array(data["Ytrain"]), array(data["Xtest"]), array(data["Ytest"])

def get_news_data():
    # Opening JSON file
    with open("data/regress/news.json") as json_file:
        data = json.load(json_file)
    return array(data["Xtrain"]), array(data["Ytrain"]), array(data["Xtest"]), array(data["Ytest"])

def get_wilt_data(test=False):
    # Opening JSON file
    with open("data/big_data/wilt.json") as json_file:
        data = json.load(json_file)
    if test:
        return array(data["Xtest"]), array(data["Ytest"])
    else:
        return array(data["Xtrain"]), array(data["Ytrain"])


def get_skin_data(test=False):
    # Opening JSON file
    with open("data/big_data/skin.json") as json_file:
        data = json.load(json_file)
    if test:
        return array(data["Xtest"]), array(data["Ytest"])
    else:
        return array(data["Xtrain"]), array(data["Ytrain"])


def get_segment_data(test=False):
    # Opening JSON file
    with open("data/big_data/segment.json") as json_file:
        data = json.load(json_file)
    if test:
        return array(data["Xtest"]), array(data["Ytest"])
    else:
        return array(data["Xtrain"]), array(data["Ytrain"])


def get_room_data(test=False):
    # Opening JSON file
    with open("data/big_data/room.json") as json_file:
        data = json.load(json_file)
    if test:
        return array(data["Xtest"]), array(data["Ytest"])
    else:
        return array(data["Xtrain"]), array(data["Ytrain"])


def get_rice_data(test=False):
    # Opening JSON file
    with open("data/big_data/rice.json") as json_file:
        data = json.load(json_file)
    if test:
        return array(data["Xtest"]), array(data["Ytest"])
    else:
        return array(data["Xtrain"]), array(data["Ytrain"])


def get_raisin_data(test=False):
    # Opening JSON file
    with open("data/big_data/raisin.json") as json_file:
        data = json.load(json_file)
    if test:
        return array(data["Xtest"]), array(data["Ytest"])
    else:
        return array(data["Xtrain"]), array(data["Ytrain"])


def get_magic_data(test=False):
    # Opening JSON file
    with open("data/big_data/magic.json") as json_file:
        data = json.load(json_file)
    if test:
        return array(data["Xtest"]), array(data["Ytest"])
    else:
        return array(data["Xtrain"]), array(data["Ytrain"])


def get_page_data(test=False):
    # Opening JSON file
    with open("data/big_data/page.json") as json_file:
        data = json.load(json_file)
    if test:
        return array(data["Xtest"]), array(data["Ytest"])
    else:
        return array(data["Xtrain"]), array(data["Ytrain"])


def get_htru_data(test=False):
    # Opening JSON file
    with open("data/big_data/htru.json") as json_file:
        data = json.load(json_file)
    if test:
        return array(data["Xtest"]), array(data["Ytest"])
    else:
        return array(data["Xtrain"]), array(data["Ytrain"])


def get_avila_data(test=False):
    # Opening JSON file
    with open("data/big_data/avila.json") as json_file:
        data = json.load(json_file)
    if test:
        return array(data["Xtest"]), array(data["Ytest"])
    else:
        return array(data["Xtrain"]), array(data["Ytrain"])


def get_occupancy_data(test=False):
    # Opening JSON file
    with open("data/big_data/occupancy.json") as json_file:
        data = json.load(json_file)
    if test:
        return array(data["Xtest"]), array(data["Ytest"])
    else:
        return array(data["Xtrain"]), array(data["Ytrain"])


def get_fault_data(test=False):
    # Opening JSON file
    with open("data/big_data/fault.json") as json_file:
        data = json.load(json_file)
    if test:
        return array(data["Xtest"]), array(data["Ytest"])
    else:
        return array(data["Xtrain"]), array(data["Ytrain"])


def get_eeg_data(test=False):
    # Opening JSON file
    with open("data/big_data/eeg.json") as json_file:
        data = json.load(json_file)
    if test:
        return array(data["Xtest"]), array(data["Ytest"])
    else:
        return array(data["Xtrain"]), array(data["Ytrain"])


def get_bidding_data(test=False):
    # Opening JSON file
    with open("data/big_data/bidding.json") as json_file:
        data = json.load(json_file)
    if test:
        return array(data["Xtest"]), array(data["Ytest"])
    else:
        return array(data["Xtrain"]), array(data["Ytrain"])


def get_bean_data(test=False):
    # Opening JSON file
    with open("data/big_data/bean.json") as json_file:
        data = json.load(json_file)
    if test:
        return array(data["Xtest"]), array(data["Ytest"])
    else:
        return array(data["Xtrain"]), array(data["Ytrain"])


def get_house_data(test=False):
    """
    load house-votes-84 dataset
    """
    df = pd.read_csv(
        "./data/small_data/house-votes-84/house-votes-84.data",
        header=None,
        delimiter=",",
    )
    for i in range(1, 17):
        df = df[df[i] != "?"]
    df = df.apply(lambda x: pd.factorize(x)[0])
    x, y = df[[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]], df[0]
    return array(x), array(y)


def get_iris_data():
    return iris(return_X_y=True)


def get_wine_data():
    return wine(return_X_y=True)


# def very_small_data():
#     S = [[0.2, 0.7], [0.3, 0.6], [0.9, 0.1]]
#     Y = [0, 1, 2]
#     return S, Y


def get_cancer_data():
    return cancer(return_X_y=True)
