# Path: ifcb/tests/data/fileset_info.py
# def list_test_bins():
#     return list(_dd())
# 
# Path: ifcb/viz/mosaic.py
# class Mosaic(object):
#     def __init__(self, the_bin, shape=(600, 800), scale=0.33, bg_color=200, coordinates=None):
#         self.bin = the_bin
#         self.shape = shape
#         self.bg_color = bg_color
#         self.scale = scale
#         self.coordinates = coordinates
#     @lru_cache()
#     def _shapes(self):
#         hs, ws, ix = [], [], []
#         with self.bin:
#             ii = InfilledImages(self.bin)
#             for target_number in ii:
#                 h, w = ii.shape(target_number)
#                 hs.append(math.floor(h * self.scale))
#                 ws.append(math.floor(w * self.scale))
#                 ix.append(target_number)
#         return zip(hs, ws, ix)
#     def pack(self, max_pages=20):
#         if self.coordinates is not None:
#             return self.coordinates
#         page_h, page_w = self.shape
#         pages = [(page_h - 1, page_w - 1) for _ in range(max_pages)]
#         packer = newPacker(sort_algo=SORT_AREA, rotation=False, pack_algo=GuillotineBafSlas)
#         for r in self._shapes():
#             packer.add_rect(*r)
#         for p in pages:
#             packer.add_bin(*p)
#         packer.pack()
#         COLS = ['page', 'y', 'x', 'h', 'w', 'roi_number']
#         self.coordinates = pd.DataFrame(packer.rect_list(), columns=COLS)
#         return self.coordinates
#     def page(self, page=0):
#         df = self.pack()
#         page_h, page_w = self.shape
#         page_image = np.zeros((page_h, page_w), dtype=np.uint8) + self.bg_color
#         sdf = df[df.page == page]
#         with self.bin:
#             if self.bin.schema == SCHEMA_VERSION_1:
#                 ii = InfilledImages(self.bin)
#             else:
#                 ii = self.bin.images
#             for index, row in sdf.iterrows():
#                 y, x = row.y, row.x
#                 h, w = row.h, row.w
#                 unscaled_image = ii[row.roi_number]
#                 scaled_image = resize(unscaled_image, (h, w), mode='reflect', preserve_range=True)
#                 page_image[y:y+h, x:x+w] = scaled_image
#         return page_image


import unittest
import numpy as np
from ifcb.tests.data.fileset_info import list_test_bins
from ifcb.viz.mosaic import Mosaic




PACKED = {
    'IFCB5_2012_028_081515': {
        'y': [0, 0, 137, 182, 182],
        'x': [0, 238, 0, 0, 105],
        'roi_number': [2, 3, 6, 5, 1]
    },
    'D20130526T095207_IFCB013': {
        'y': [0, 89, 171, 237, 295, 337, 403, 453, 494, 237, 171, 337, 379, 527, 453, 527, 561, 561, 595],
        'x': [0, 0, 0, 0, 0, 0, 0, 0, 0, 112, 104, 96, 96, 0, 112, 88, 0, 72, 0],
        'roi_number': [114, 61, 11, 78, 47, 73, 66, 21, 54, 49, 32, 33, 68, 7, 13, 80, 92, 102, 99]
    }
}

class TestMosaic(unittest.TestCase):
    def test_pack(self):

# Path: ifcb/tests/data/fileset_info.py
# def list_test_bins():
#     return list(_dd())
# 
# Path: ifcb/viz/mosaic.py
# class Mosaic(object):
#     def __init__(self, the_bin, shape=(600, 800), scale=0.33, bg_color=200, coordinates=None):
#         self.bin = the_bin
#         self.shape = shape
#         self.bg_color = bg_color
#         self.scale = scale
#         self.coordinates = coordinates
#     @lru_cache()
#     def _shapes(self):
#         hs, ws, ix = [], [], []
#         with self.bin:
#             ii = InfilledImages(self.bin)
#             for target_number in ii:
#                 h, w = ii.shape(target_number)
#                 hs.append(math.floor(h * self.scale))
#                 ws.append(math.floor(w * self.scale))
#                 ix.append(target_number)
#         return zip(hs, ws, ix)
#     def pack(self, max_pages=20):
#         if self.coordinates is not None:
#             return self.coordinates
#         page_h, page_w = self.shape
#         pages = [(page_h - 1, page_w - 1) for _ in range(max_pages)]
#         packer = newPacker(sort_algo=SORT_AREA, rotation=False, pack_algo=GuillotineBafSlas)
#         for r in self._shapes():
#             packer.add_rect(*r)
#         for p in pages:
#             packer.add_bin(*p)
#         packer.pack()
#         COLS = ['page', 'y', 'x', 'h', 'w', 'roi_number']
#         self.coordinates = pd.DataFrame(packer.rect_list(), columns=COLS)
#         return self.coordinates
#     def page(self, page=0):
#         df = self.pack()
#         page_h, page_w = self.shape
#         page_image = np.zeros((page_h, page_w), dtype=np.uint8) + self.bg_color
#         sdf = df[df.page == page]
#         with self.bin:
#             if self.bin.schema == SCHEMA_VERSION_1:
#                 ii = InfilledImages(self.bin)
#             else:
#                 ii = self.bin.images
#             for index, row in sdf.iterrows():
#                 y, x = row.y, row.x
#                 h, w = row.h, row.w
#                 unscaled_image = ii[row.roi_number]
#                 scaled_image = resize(unscaled_image, (h, w), mode='reflect', preserve_range=True)
#                 page_image[y:y+h, x:x+w] = scaled_image
#         return page_image


# Path: ifcb/tests/viz/test_mosaic.py
import unittest
import numpy as np
from ifcb.tests.data.fileset_info import list_test_bins
from ifcb.viz.mosaic import Mosaic





PACKED = {
    'IFCB5_2012_028_081515': {
        'y': [0, 0, 137, 182, 182],
        'x': [0, 238, 0, 0, 105],
        'roi_number': [2, 3, 6, 5, 1]
    },
    'D20130526T095207_IFCB013': {
        'y': [0, 89, 171, 237, 295, 337, 403, 453, 494, 237, 171, 337, 379, 527, 453, 527, 561, 561, 595],
        'x': [0, 0, 0, 0, 0, 0, 0, 0, 0, 112, 104, 96, 96, 0, 112, 88, 0, 72, 0],
        'roi_number': [114, 61, 11, 78, 47, 73, 66, 21, 54, 49, 32, 33, 68, 7, 13, 80, 92, 102, 99]
    }
}

class TestMosaic(unittest.TestCase):
    def test_pack(self):

        for b in list_test_bins():