import os, sys, inspect, json
import numpy as np

currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
parentdir = os.path.dirname(currentdir)
sys.path.insert(0, parentdir)

try:
    from ..bal import Bal
    from .util import trainTwo, filt, touchFilter
except Exception: #ImportError
    from bal import Bal
    from util import trainTwo, filt, touchFilter


# init training data
with open("./hand_som.somdata") as f:
    data = json.load(f)

labeled = [(np.array(i['pos']), np.array(i["touch"])) for i in data]
labeled = filt(labeled)

touchOnlyData = touchFilter(labeled)

vanila    = Bal(len(data[0]["pos"]), 180, len(data[0]["touch"]))
touchOnly = Bal(len(data[0]["pos"]), 180, len(data[0]["touch"]))

trainTwo(
    model1=vanila, train1=labeled, name1="processed",
    model2=touchOnly, train2=touchOnlyData, name2="touch only",
    epoch=1000
)