# Path: hyperengine/base/util.py
# def str_to_dict(s):
#   return ast.literal_eval(s)
# 
# def smart_str(val):
#   if type(val) in [float, np.float32, np.float64] and val:
#     return '%.6f' % val if abs(val) > 1e-6 else '%e' % val
#   if type(val) == dict:
#     return '{%s}' % ', '.join(['%s: %s' % (repr(k), smart_str(val[k])) for k in sorted(val.keys())])
#   if type(val) in [list, tuple]:
#     return '[%s]' % ', '.join(['%s' % smart_str(i) for i in val])
#   return repr(val)
# 
# def random_id(size=6, chars=string.ascii_uppercase + string.digits):
#   return ''.join(random.choice(chars) for _ in range(size))


import datetime
import os
import numpy as np
from .logging import *
from .util import str_to_dict, smart_str, random_id

  def load(self):
    directory = self.load_dir
    if not directory is None:
      destination = os.path.join(directory, self.filename)
      if os.path.exists(destination):
        data = DefaultIO._load_dict(destination)
        if is_debug_logged():
          debug('Loaded data: %s from %s' % (smart_str(data), destination))
        self.serializable.import_from(data)
        return
    self.serializable.import_from({})

  def save(self):
    directory = self.save_dir
    if not DefaultIO._prepare(directory):
      return
    destination = os.path.join(directory, self.filename)
    with open(destination, 'w') as file_:
      data = smart_str(self.serializable.export_to())
      vlog('Exported data:', data)
      file_.write(data)
      debug('Data saved to:', destination)


def _format_path(directory):
  if directory and '{' in directory and '}' in directory:
    now = datetime.datetime.now()
    return directory.format(date=now.strftime('%Y-%m-%d'),
                            time=now.strftime('%H-%M-%S'),

# Path: hyperengine/base/util.py
# def str_to_dict(s):
#   return ast.literal_eval(s)
# 
# def smart_str(val):
#   if type(val) in [float, np.float32, np.float64] and val:
#     return '%.6f' % val if abs(val) > 1e-6 else '%e' % val
#   if type(val) == dict:
#     return '{%s}' % ', '.join(['%s: %s' % (repr(k), smart_str(val[k])) for k in sorted(val.keys())])
#   if type(val) in [list, tuple]:
#     return '[%s]' % ', '.join(['%s' % smart_str(i) for i in val])
#   return repr(val)
# 
# def random_id(size=6, chars=string.ascii_uppercase + string.digits):
#   return ''.join(random.choice(chars) for _ in range(size))


# Path: hyperengine/base/base_io.py
import datetime
import os
import numpy as np
from .logging import *
from .util import str_to_dict, smart_str, random_id


  def load(self):
    directory = self.load_dir
    if not directory is None:
      destination = os.path.join(directory, self.filename)
      if os.path.exists(destination):
        data = DefaultIO._load_dict(destination)
        if is_debug_logged():
          debug('Loaded data: %s from %s' % (smart_str(data), destination))
        self.serializable.import_from(data)
        return
    self.serializable.import_from({})

  def save(self):
    directory = self.save_dir
    if not DefaultIO._prepare(directory):
      return
    destination = os.path.join(directory, self.filename)
    with open(destination, 'w') as file_:
      data = smart_str(self.serializable.export_to())
      vlog('Exported data:', data)
      file_.write(data)
      debug('Data saved to:', destination)


def _format_path(directory):
  if directory and '{' in directory and '}' in directory:
    now = datetime.datetime.now()
    return directory.format(date=now.strftime('%Y-%m-%d'),
                            time=now.strftime('%H-%M-%S'),

                            random_id=random_id())