# Path: automlk/store.py
# def get_key_store(key):
#     """
#     retieves value from key in store
# 
#     :param key: key of the data
#     :return: value of the data
#     """
#     if get_use_redis():
#         return json.loads(rds.get(str(key)))
#     else:
#         try:
#             if exists_key_store(key):
#                 return json.load(open(store_folder + '/' + __clean_key(key) + '.json', 'r'))
#             else:
#                 return None
#         except:
#             return None
# 
# def list_key_store(key):
#     """
#     returns the complete list of values
# 
#     :param key: key of the data
#     :return: list
#     """
#     if get_use_redis():
#         return [json.loads(x) for x in rds.lrange(key, 0, -1)]
#     else:
#         l = get_key_store(key)
#         if l != None:
#             return l
#         else:
#             return []
# 
# def lpush_key_store(key, value):
#     """
#     add value to the beginning of a list of key in store
# 
#     :param key: key of the data
#     :return: value of the data
#     :return: None
#     """
#     if get_use_redis():
#         rds.lpush(str(key), json.dumps(value))
#     else:
#         if exists_key_store(key):
#             l = get_key_store(key)
#             if isinstance(l, list):
#                 set_key_store(key, [value] + l)
#             else:
#                 set_key_store(key, [value])
#         else:
#             set_key_store(key, [value])


from automlk.store import get_key_store, list_key_store, lpush_key_store
from automlk.config import *

dataset_id = '42'
round_id = 1

results = list_key_store('dataset:%s:rounds' % dataset_id)

for r in results:
    if r['round_id'] == round_id:
        # print(r)
        # reinject this round in another dataset experiment
        msg_search = {'dataset_id': '47', 'round_id': 107, 'solution': r['solution'], 'level': 1,
         'ensemble_depth': 0, 'model_name': r['model_name'], 'model_params': r['model_params'], 'pipeline': r['pipeline'],
         'threshold': 0, 'time_limit': 10000}

        print('sending %s' % msg_search)

# Path: automlk/store.py
# def get_key_store(key):
#     """
#     retieves value from key in store
# 
#     :param key: key of the data
#     :return: value of the data
#     """
#     if get_use_redis():
#         return json.loads(rds.get(str(key)))
#     else:
#         try:
#             if exists_key_store(key):
#                 return json.load(open(store_folder + '/' + __clean_key(key) + '.json', 'r'))
#             else:
#                 return None
#         except:
#             return None
# 
# def list_key_store(key):
#     """
#     returns the complete list of values
# 
#     :param key: key of the data
#     :return: list
#     """
#     if get_use_redis():
#         return [json.loads(x) for x in rds.lrange(key, 0, -1)]
#     else:
#         l = get_key_store(key)
#         if l != None:
#             return l
#         else:
#             return []
# 
# def lpush_key_store(key, value):
#     """
#     add value to the beginning of a list of key in store
# 
#     :param key: key of the data
#     :return: value of the data
#     :return: None
#     """
#     if get_use_redis():
#         rds.lpush(str(key), json.dumps(value))
#     else:
#         if exists_key_store(key):
#             l = get_key_store(key)
#             if isinstance(l, list):
#                 set_key_store(key, [value] + l)
#             else:
#                 set_key_store(key, [value])
#         else:
#             set_key_store(key, [value])


# Path: tests/test_inject.py
from automlk.store import get_key_store, list_key_store, lpush_key_store
from automlk.config import *


dataset_id = '42'
round_id = 1

results = list_key_store('dataset:%s:rounds' % dataset_id)

for r in results:
    if r['round_id'] == round_id:
        # print(r)
        # reinject this round in another dataset experiment
        msg_search = {'dataset_id': '47', 'round_id': 107, 'solution': r['solution'], 'level': 1,
         'ensemble_depth': 0, 'model_name': r['model_name'], 'model_params': r['model_params'], 'pipeline': r['pipeline'],
         'threshold': 0, 'time_limit': 10000}

        print('sending %s' % msg_search)

        lpush_key_store(SEARCH_QUEUE, msg_search)