# Path: jubakit/_cli/service/generic.py
# class GenericCLI(BaseRpcCLI):
#   """
#   Base CLI implementation for all other services.
#   """
# 
#   def __init__(self, *args, **kwargs):
#     super(GenericCLI, self).__init__(*args, **kwargs)
#     self._clear_cache()
# 
#   @classmethod
#   def _name(cls):
#     return 'generic'
# 
#   def _clear_cache(self):
#     """
#     Subclasses using cache must override this method; initialize or invalidate
#     cache when this method is called.
#     """
#     pass
# 
#   def _print_status(self, status):
#     """
#     Pretty-print the status structure.
#     """
#     for (host_port, status) in status.items():
#       print("Server {0}:{1}".format(*(host_port.split('_'))))
#       for key in sorted(status.keys()):
#         print("  {0}: {1}".format(key, status[key]))
# 
#   @Arguments()
#   def do_get_config(self):
#     """Syntax: get_config
#     Display algorithm and converter configuration set in server.
#     """
#     config = self.client.get_config()
#     print(json.dumps(json.loads(config), sort_keys=True, indent=4))
# 
#   @Arguments(str)
#   def do_save(self, model_id):
#     """Syntax: save model_id
#     Save the model.
#     """
#     result = self.client.save(model_id)
#     if result:
#       for (server_id, path) in result.items():
#         print("{0}:\t{1}".format(server_id, path))
#     else:
#       print("Failed")
# 
#   @Arguments()
#   def do_clear(self):
#     """Syntax: clear
#     Clear the model.
#     """
#     result = self.client.clear()
#     if not result:
#       print("Failed")
#     self._clear_cache()
# 
#   @Arguments(str)
#   def do_load(self, model_id):
#     """Syntax: load model_id
#     Load the given model.
#     """
#     result = self.client.load(model_id)
#     if not result:
#       print("Failed")
# 
#   @Arguments()
#   def do_get_status(self):
#     """Syntax: get_status
#     Displays status of servers.
#     """
#     status = self.client.get_status()
#     self._print_status(status)
# 
#   @Arguments()
#   def do_get_proxy_status(self):
#     """Syntax: get_proxy_status
#     Displays status of the proxy.
#     Available only when connected to proxies.
#     """
#     status = self.client.get_proxy_status()
#     self._print_status(status)
# 
#   @Arguments()
#   def do_do_mix(self):
#     """Syntax: do_mix
#     Trigger MIX.
#     Available only when connected to servers.
#     """
#     result = self.client.do_mix()
#     if not result:
#       print("Failed")
# 
# Path: jubakit/_cli/args.py
# def Arguments(*expected_types):
#   def wrap_by_preprocessor(func):
#     assert len(inspect.getargspec(func).args) == (len(expected_types) + 1)
# 
#     def preprocessor(self, line):
#       params = shell_split(line)
#       types = []
#       (min_count, max_count) = (0, 0)
# 
#       for t in expected_types:
#         if not isinstance(t, Requirement):
#           t = Mandatory(t)
#         types.append(t)
#         (t_min, t_max) = t.min_max()
#         min_count += t_min
#         if t_max is None:
#           max_count = None
#         elif max_count is not None:
#           max_count += t_max
# 
#       params_len = len(params)
#       if params_len < min_count:
#         raise ValueError('Too few arguments ({0} required at least, only got {1})'.format(min_count, params_len))
#       if max_count is not None and max_count < params_len:
#         raise ValueError('Too many arguments ({0} required at most, got {1})'.format(max_count, params_len))
# 
#       index = 0
#       argv = []
#       for t in types:
#         try:
#           (consumed, value) = t.convert(params[index:])
#         except ValueError as e:
#           raise ValueError('argument {0}: {1}'.format(index + 1, e))
#         argv.append(value)
#         index += consumed
#       return func(self, *argv)
#     preprocessor.__doc__ = func.__doc__
#     return preprocessor
#   return wrap_by_preprocessor
# 
# class TDatum(Type):
#   def convert(self, args):
#     if len(args) % 2 != 0:
#       raise ValueError('value for the last datum key ({0}) is missing'.format(args[len(args) - 1]))
# 
#     d = Datum()
#     for i in range(int(len(args) / 2)):
#       feat_key = args[i*2]
#       feat_val = args[i*2+1]
#       try:
#         d.add_number(feat_key, float(feat_val))
#       except ValueError:
#         d.add_string(feat_key, feat_val)
#     return (len(args), d)
# 
#   def min_max(self):
#     return (0, None)
# 
# Path: jubakit/_stdio.py
# @classmethod
# def print(cls, *args, **kwargs):
#   builtins.print(file=cls.stdout, *args, **kwargs)


from jubatus.regression.types import *
from .generic import GenericCLI
from ..args import Arguments, TDatum
from ..util import *
from ..._stdio import print
# -*- coding: utf-8 -*-

from __future__ import absolute_import, division, print_function, unicode_literals



class RegressionCLI(GenericCLI):
  @classmethod
  def _name(cls):
    return 'regression'

  @Arguments(float, TDatum)
  def do_train(self, score, d):
    """Syntax: train score datum_key datum_value [datum_key datum_value ...]
    Trains the model with given score and datum.
    Bulk training is not supported on the command line.
    """
    self._verbose("datum = {0}".format(d))
    result = self.client.train([ScoredDatum(score, d)])
    if result != 1:

# Path: jubakit/_cli/service/generic.py
# class GenericCLI(BaseRpcCLI):
#   """
#   Base CLI implementation for all other services.
#   """
# 
#   def __init__(self, *args, **kwargs):
#     super(GenericCLI, self).__init__(*args, **kwargs)
#     self._clear_cache()
# 
#   @classmethod
#   def _name(cls):
#     return 'generic'
# 
#   def _clear_cache(self):
#     """
#     Subclasses using cache must override this method; initialize or invalidate
#     cache when this method is called.
#     """
#     pass
# 
#   def _print_status(self, status):
#     """
#     Pretty-print the status structure.
#     """
#     for (host_port, status) in status.items():
#       print("Server {0}:{1}".format(*(host_port.split('_'))))
#       for key in sorted(status.keys()):
#         print("  {0}: {1}".format(key, status[key]))
# 
#   @Arguments()
#   def do_get_config(self):
#     """Syntax: get_config
#     Display algorithm and converter configuration set in server.
#     """
#     config = self.client.get_config()
#     print(json.dumps(json.loads(config), sort_keys=True, indent=4))
# 
#   @Arguments(str)
#   def do_save(self, model_id):
#     """Syntax: save model_id
#     Save the model.
#     """
#     result = self.client.save(model_id)
#     if result:
#       for (server_id, path) in result.items():
#         print("{0}:\t{1}".format(server_id, path))
#     else:
#       print("Failed")
# 
#   @Arguments()
#   def do_clear(self):
#     """Syntax: clear
#     Clear the model.
#     """
#     result = self.client.clear()
#     if not result:
#       print("Failed")
#     self._clear_cache()
# 
#   @Arguments(str)
#   def do_load(self, model_id):
#     """Syntax: load model_id
#     Load the given model.
#     """
#     result = self.client.load(model_id)
#     if not result:
#       print("Failed")
# 
#   @Arguments()
#   def do_get_status(self):
#     """Syntax: get_status
#     Displays status of servers.
#     """
#     status = self.client.get_status()
#     self._print_status(status)
# 
#   @Arguments()
#   def do_get_proxy_status(self):
#     """Syntax: get_proxy_status
#     Displays status of the proxy.
#     Available only when connected to proxies.
#     """
#     status = self.client.get_proxy_status()
#     self._print_status(status)
# 
#   @Arguments()
#   def do_do_mix(self):
#     """Syntax: do_mix
#     Trigger MIX.
#     Available only when connected to servers.
#     """
#     result = self.client.do_mix()
#     if not result:
#       print("Failed")
# 
# Path: jubakit/_cli/args.py
# def Arguments(*expected_types):
#   def wrap_by_preprocessor(func):
#     assert len(inspect.getargspec(func).args) == (len(expected_types) + 1)
# 
#     def preprocessor(self, line):
#       params = shell_split(line)
#       types = []
#       (min_count, max_count) = (0, 0)
# 
#       for t in expected_types:
#         if not isinstance(t, Requirement):
#           t = Mandatory(t)
#         types.append(t)
#         (t_min, t_max) = t.min_max()
#         min_count += t_min
#         if t_max is None:
#           max_count = None
#         elif max_count is not None:
#           max_count += t_max
# 
#       params_len = len(params)
#       if params_len < min_count:
#         raise ValueError('Too few arguments ({0} required at least, only got {1})'.format(min_count, params_len))
#       if max_count is not None and max_count < params_len:
#         raise ValueError('Too many arguments ({0} required at most, got {1})'.format(max_count, params_len))
# 
#       index = 0
#       argv = []
#       for t in types:
#         try:
#           (consumed, value) = t.convert(params[index:])
#         except ValueError as e:
#           raise ValueError('argument {0}: {1}'.format(index + 1, e))
#         argv.append(value)
#         index += consumed
#       return func(self, *argv)
#     preprocessor.__doc__ = func.__doc__
#     return preprocessor
#   return wrap_by_preprocessor
# 
# class TDatum(Type):
#   def convert(self, args):
#     if len(args) % 2 != 0:
#       raise ValueError('value for the last datum key ({0}) is missing'.format(args[len(args) - 1]))
# 
#     d = Datum()
#     for i in range(int(len(args) / 2)):
#       feat_key = args[i*2]
#       feat_val = args[i*2+1]
#       try:
#         d.add_number(feat_key, float(feat_val))
#       except ValueError:
#         d.add_string(feat_key, feat_val)
#     return (len(args), d)
# 
#   def min_max(self):
#     return (0, None)
# 
# Path: jubakit/_stdio.py
# @classmethod
# def print(cls, *args, **kwargs):
#   builtins.print(file=cls.stdout, *args, **kwargs)


# Path: jubakit/_cli/service/regression.py
from jubatus.regression.types import *
from .generic import GenericCLI
from ..args import Arguments, TDatum
from ..util import *
from ..._stdio import print

# -*- coding: utf-8 -*-

from __future__ import absolute_import, division, print_function, unicode_literals



class RegressionCLI(GenericCLI):
  @classmethod
  def _name(cls):
    return 'regression'

  @Arguments(float, TDatum)
  def do_train(self, score, d):
    """Syntax: train score datum_key datum_value [datum_key datum_value ...]
    Trains the model with given score and datum.
    Bulk training is not supported on the command line.
    """
    self._verbose("datum = {0}".format(d))
    result = self.client.train([ScoredDatum(score, d)])
    if result != 1:

      print("Failed")