# Path: lib/replay_memory.py
# class ReplayMemory(object):
#     def __init__(self, filepath, max_size, max_size_tolerance):
#     def create_instance_supervised(val=False):
#     def create_instance_reinforced(val=False):
#     def create_instance_by_config(cfg_name):
#     def add_states(self, states, shrink=True):
#     def add_state(self, state, commit=True, shrink=True):
#     def update_state(self, idx, state, commit=True):
#     def get_state_by_id(self, idx):
#     def get_states_by_ids(self, ids):
#     def get_random_states(self, count):
#     def get_states_range(self, pos_start, length):
#     def get_random_state_chain(self, length, from_pos_range=None):
#     def get_random_state_chain_timediff(self, length, max_timediff_ms=500, depth=50):
#     def update_caches(self):
#     def is_above_tolerance(self):
#     def shrink_to_max_size(self, force=False):
#     def commit(self):
#     def close(self):
#     def connect(self):
# 
# Path: lib/util.py
# def template_match(needle, haystack):
# def compress_to_jpg(img):
# def compress_img(img, method):
# def decompress_img(img_compressed):
# def draw_image(img, other_img, x, y, copy=True, raise_if_oob=False):
# def draw_point(img, y, x, size=5, color=[255, 0, 0], alpha=1.0, copy=True):
# def draw_line(img, y1, x1, y2, x2, color=[0, 255, 0], alpha=1.0, thickness=1, clip_result=True, copy=True):
# def draw_direction_circle(img, y, x, r_inner, r_outer, angle_start, angle_end, color_border=[0, 255, 0], color_fill=[0, 200, 0], alpha=1.0):
# def draw_text(img, y, x, text, color=[0, 255, 0], size=25):
# def to_variable(inputs, volatile=False, requires_grad=True):
# def to_variables(inputs, volatile=False, requires_grad=True):
# def to_cuda(inputs, gpu=Config.GPU):
# def to_numpy(var):
# def draw_heatmap_overlay(img, heatmap, alpha=0.5):
# def create_2d_gaussian_old(size, fwhm=3, center=None):
# def create_2d_gaussian(size, sigma):
# FONT_CACHE = dict()


import sys
import os
import train
import numpy as np
import cPickle as pickle
import gzip as gz
import random
from lib import replay_memory
from lib import util
    next_multiaction_vecs_avg = np.average(np.array(next_multiaction_vecs, dtype=np.float32), 0)

    ex = Example(state_idx, state.screenshot_rs_jpg)
    ex.previous_screenshots_rs_jpg = [states_past[len(states_past)-d].screenshot_rs_jpg for d in train.PREVIOUS_STATES_DISTANCES]
    ex.previous_multiaction_vec = previous_multiaction_vec
    ex.previous_multiaction_vecs_avg = previous_multiaction_vecs_avg
    ex.multiaction_vec = multiaction_vec
    ex.next_multiaction_vec = next_multiaction_vec
    ex.next_multiaction_vecs_avg = next_multiaction_vecs_avg

    return ex

def load_dataset_annotated():
    memory = replay_memory.ReplayMemory.create_instance_supervised(val=False)

    examples = dict()
    if not train.DEBUG:
        print("[load_dataset] Loading grids examples...")
        for (grid_key, fp) in train.ANNOTATIONS_GRIDS_FPS:
            if not os.path.isfile(fp):
                print("[WARNING] Could not find annotations (grids) file '%s'" % (fp,))
            else:
                dataset = pickle.load(open(fp, "r"))
                for key in dataset:
                    state_idx = dataset[key]["idx"]
                    from_datetime = dataset[key]["from_datetime"]
                    screenshot_rs = dataset[key]["screenshot_rs"]
                    grid = dataset[key][grid_key]
                    if not key in examples:
                        examples[key] = dataset_state_idx_to_example(state_idx, memory)

# Path: lib/replay_memory.py
# class ReplayMemory(object):
#     def __init__(self, filepath, max_size, max_size_tolerance):
#     def create_instance_supervised(val=False):
#     def create_instance_reinforced(val=False):
#     def create_instance_by_config(cfg_name):
#     def add_states(self, states, shrink=True):
#     def add_state(self, state, commit=True, shrink=True):
#     def update_state(self, idx, state, commit=True):
#     def get_state_by_id(self, idx):
#     def get_states_by_ids(self, ids):
#     def get_random_states(self, count):
#     def get_states_range(self, pos_start, length):
#     def get_random_state_chain(self, length, from_pos_range=None):
#     def get_random_state_chain_timediff(self, length, max_timediff_ms=500, depth=50):
#     def update_caches(self):
#     def is_above_tolerance(self):
#     def shrink_to_max_size(self, force=False):
#     def commit(self):
#     def close(self):
#     def connect(self):
# 
# Path: lib/util.py
# def template_match(needle, haystack):
# def compress_to_jpg(img):
# def compress_img(img, method):
# def decompress_img(img_compressed):
# def draw_image(img, other_img, x, y, copy=True, raise_if_oob=False):
# def draw_point(img, y, x, size=5, color=[255, 0, 0], alpha=1.0, copy=True):
# def draw_line(img, y1, x1, y2, x2, color=[0, 255, 0], alpha=1.0, thickness=1, clip_result=True, copy=True):
# def draw_direction_circle(img, y, x, r_inner, r_outer, angle_start, angle_end, color_border=[0, 255, 0], color_fill=[0, 200, 0], alpha=1.0):
# def draw_text(img, y, x, text, color=[0, 255, 0], size=25):
# def to_variable(inputs, volatile=False, requires_grad=True):
# def to_variables(inputs, volatile=False, requires_grad=True):
# def to_cuda(inputs, gpu=Config.GPU):
# def to_numpy(var):
# def draw_heatmap_overlay(img, heatmap, alpha=0.5):
# def create_2d_gaussian_old(size, fwhm=3, center=None):
# def create_2d_gaussian(size, sigma):
# FONT_CACHE = dict()


# Path: train_semisupervised/dataset.py
import sys
import os
import train
import numpy as np
import cPickle as pickle
import gzip as gz
import random
from lib import replay_memory
from lib import util

    next_multiaction_vecs_avg = np.average(np.array(next_multiaction_vecs, dtype=np.float32), 0)

    ex = Example(state_idx, state.screenshot_rs_jpg)
    ex.previous_screenshots_rs_jpg = [states_past[len(states_past)-d].screenshot_rs_jpg for d in train.PREVIOUS_STATES_DISTANCES]
    ex.previous_multiaction_vec = previous_multiaction_vec
    ex.previous_multiaction_vecs_avg = previous_multiaction_vecs_avg
    ex.multiaction_vec = multiaction_vec
    ex.next_multiaction_vec = next_multiaction_vec
    ex.next_multiaction_vecs_avg = next_multiaction_vecs_avg

    return ex

def load_dataset_annotated():
    memory = replay_memory.ReplayMemory.create_instance_supervised(val=False)

    examples = dict()
    if not train.DEBUG:
        print("[load_dataset] Loading grids examples...")
        for (grid_key, fp) in train.ANNOTATIONS_GRIDS_FPS:
            if not os.path.isfile(fp):
                print("[WARNING] Could not find annotations (grids) file '%s'" % (fp,))
            else:
                dataset = pickle.load(open(fp, "r"))
                for key in dataset:
                    state_idx = dataset[key]["idx"]
                    from_datetime = dataset[key]["from_datetime"]
                    screenshot_rs = dataset[key]["screenshot_rs"]
                    grid = dataset[key][grid_key]
                    if not key in examples:
                        examples[key] = dataset_state_idx_to_example(state_idx, memory)

                    examples[key].add_grid(grid_key, grid)