#!/usr/bin/env python3

import argparse
import json

import ossml.costs

parser = argparse.ArgumentParser(description='Trains and predicts costs', prog='ossml')
commands = parser.add_subparsers(help='command', dest='command')
commands.required = True

parser_train = commands.add_parser('train')
parser_train.add_argument('json', type=argparse.FileType('r'), help='file with feature description in JSON format')
parser_train.add_argument('output', type=str)
parser_train.add_argument('--n-jobs', '-j', type=int)

parser_predict = commands.add_parser('predict')
parser_predict.add_argument('json', type=argparse.FileType('r'), help='file with feature description in JSON format')
parser_predict.add_argument('model', type=str)
parser_predict.add_argument('--n-jobs', '-j', type=int)

args = parser.parse_args()

if args.command == 'train':
    ossml.costs.run_train(json.loads(args.json.read()), args.output)

elif args.command == 'predict':
    ossml.costs.run_predict(json.loads(args.json.read()), args.model)
