# Path: rlvision/grid.py
# def create_train_grid28(db_name, save_dir, num_samples=0):
#     """Create training dataset for 28x28 grid.
#     Parameters
#     ----------
#     db_name : str
#         the name of dataset
#     save_dir : str
#         the directory of the output path (must exist)
#     """
#     db = utils.init_h5_db(db_name+".h5", save_dir)
# 
#     # collect data
#     for split in xrange(5):
#         dc_tot = None
#         vc_tot = None
#         spc_tot = []
#         ptc_tot = []
#         gpc_tot = []
#         for idx in xrange(split*4+1, split*4+5):
#             (data_collector, value_collector, start_pos_collector,
#              pos_traj_collector, goal_pos_collector) = sample_data_grid28(
#                 idx, num_samples)
#             if dc_tot is None:
#                 dc_tot = data_collector
#             else:
#                 dc_tot = np.vstack((dc_tot, data_collector))
#             if vc_tot is None:
#                 vc_tot = value_collector
#             else:
#                 vc_tot = np.vstack((vc_tot, value_collector))
#             spc_tot += start_pos_collector
#             ptc_tot += pos_traj_collector
#             gpc_tot += goal_pos_collector
#         group_name = "grid_data_split_"+str(split+1)
#         utils.add_h5_group(group_name, db)
#         utils.add_h5_ds(dc_tot, "data", db, group_name)
#         utils.add_h5_ds(vc_tot, "value", db, group_name)
#         with open(os.path.join(save_dir, db_name+"_start_%i.pkl" % (split+1)),
#                   "w") as f:
#             pickle.dump(spc_tot, f,
#                         protocol=pickle.HIGHEST_PROTOCOL)
#             f.close()
# 
#         with open(os.path.join(save_dir, db_name+"_traj_%i.pkl" % (split+1)),
#                   "w") as f:
#             pickle.dump(ptc_tot, f,
#                         protocol=pickle.HIGHEST_PROTOCOL)
#             f.close()
# 
#         with open(os.path.join(save_dir, db_name+"_goal_%i.pkl" % (split+1)),
#                   "w") as f:
#             pickle.dump(gpc_tot, f,
#                         protocol=pickle.HIGHEST_PROTOCOL)
#             f.close()
#         print ("[MESSAGE] Save dataset %i at %s" % (split+1, save_dir))
# 
#     db.flush()
#     db.close()
#     print ("[MESSAGE] Save dataset at %s" % (save_dir))


import os
import rlvision
from rlvision.grid import create_train_grid28
"""Sample Train and test dataset.

Sample 6000 samples for training and testing.

Author: Yuhuang Hu
Email : duguyue100@gmail.com
"""
from __future__ import print_function


data_path = os.path.join(rlvision.RLVISION_DATA, "train", "gridworld_28")
if not os.path.isdir(data_path):
    os.makedirs(data_path)


# Path: rlvision/grid.py
# def create_train_grid28(db_name, save_dir, num_samples=0):
#     """Create training dataset for 28x28 grid.
#     Parameters
#     ----------
#     db_name : str
#         the name of dataset
#     save_dir : str
#         the directory of the output path (must exist)
#     """
#     db = utils.init_h5_db(db_name+".h5", save_dir)
# 
#     # collect data
#     for split in xrange(5):
#         dc_tot = None
#         vc_tot = None
#         spc_tot = []
#         ptc_tot = []
#         gpc_tot = []
#         for idx in xrange(split*4+1, split*4+5):
#             (data_collector, value_collector, start_pos_collector,
#              pos_traj_collector, goal_pos_collector) = sample_data_grid28(
#                 idx, num_samples)
#             if dc_tot is None:
#                 dc_tot = data_collector
#             else:
#                 dc_tot = np.vstack((dc_tot, data_collector))
#             if vc_tot is None:
#                 vc_tot = value_collector
#             else:
#                 vc_tot = np.vstack((vc_tot, value_collector))
#             spc_tot += start_pos_collector
#             ptc_tot += pos_traj_collector
#             gpc_tot += goal_pos_collector
#         group_name = "grid_data_split_"+str(split+1)
#         utils.add_h5_group(group_name, db)
#         utils.add_h5_ds(dc_tot, "data", db, group_name)
#         utils.add_h5_ds(vc_tot, "value", db, group_name)
#         with open(os.path.join(save_dir, db_name+"_start_%i.pkl" % (split+1)),
#                   "w") as f:
#             pickle.dump(spc_tot, f,
#                         protocol=pickle.HIGHEST_PROTOCOL)
#             f.close()
# 
#         with open(os.path.join(save_dir, db_name+"_traj_%i.pkl" % (split+1)),
#                   "w") as f:
#             pickle.dump(ptc_tot, f,
#                         protocol=pickle.HIGHEST_PROTOCOL)
#             f.close()
# 
#         with open(os.path.join(save_dir, db_name+"_goal_%i.pkl" % (split+1)),
#                   "w") as f:
#             pickle.dump(gpc_tot, f,
#                         protocol=pickle.HIGHEST_PROTOCOL)
#             f.close()
#         print ("[MESSAGE] Save dataset %i at %s" % (split+1, save_dir))
# 
#     db.flush()
#     db.close()
#     print ("[MESSAGE] Save dataset at %s" % (save_dir))


# Path: rlvision/tests/sample_train_ds.py
import os
import rlvision
from rlvision.grid import create_train_grid28

"""Sample Train and test dataset.

Sample 6000 samples for training and testing.

Author: Yuhuang Hu
Email : duguyue100@gmail.com
"""
from __future__ import print_function


data_path = os.path.join(rlvision.RLVISION_DATA, "train", "gridworld_28")
if not os.path.isdir(data_path):
    os.makedirs(data_path)


create_train_grid28("gridworld_28", data_path, 250)