import unittest

from numpy.testing import assert_array_equal, assert_equal
from helix.constants.module_type import ModuleType

from helix.models.coordinate import Coordinate
from helix.models.panel import Panel
from helix.models.subarray import Subarray
from helix.presenters.panel_presenter import ProjectPresenter
from helix.constants.system_type import SystemType
from helix.constants.panel_type import PanelType


class PanelPresenterTest(unittest.TestCase):


    def test_get_table_data_single_tilt_96cell(self):
        self.subject = ProjectPresenter(SystemType.singleTilt, ModuleType.Cell96)
        panels = [
            Panel(wind_zone=0, subarray=1, panel_type=PanelType.Middle, coordinate=Coordinate(0, 2), pressure=1.17, ballast=20, presented_link_tray=2, cross_tray=1, wind_anchors=0, seismic_anchors=1, id=1),
            Panel(wind_zone=0, subarray=1, panel_type=PanelType.NorthSouth, coordinate=Coordinate(3, 1), pressure=1.17, ballast=17, presented_link_tray=2, cross_tray=1, wind_anchors=0, seismic_anchors=1, id=2),
            Panel(wind_zone=0, subarray=1, panel_type=PanelType.NorthSouth, coordinate=Coordinate(2, 1), pressure=1.17, ballast=0, presented_link_tray=0, cross_tray=0, wind_anchors=0, seismic_anchors=1, id=3),
            Panel(wind_zone=0, subarray=1, panel_type=PanelType.Corner, coordinate=Coordinate(1, 1), pressure=1.17, ballast=47, presented_link_tray=2, cross_tray=4, wind_anchors=0, seismic_anchors=1, id=4),
            Panel(wind_zone=0, subarray=1, panel_type=PanelType.EastWest, coordinate=Coordinate(0, 1), pressure=1.17, ballast=22, presented_link_tray=2, cross_tray=2, wind_anchors=0, seismic_anchors=1, id=5),
            Panel(wind_zone=0, subarray=1, panel_type=PanelType.EastWest, coordinate=Coordinate(3, 0), pressure=1.17, ballast=8, presented_link_tray=1, cross_tray=0, wind_anchors=0, seismic_anchors=1, id=6),
            Panel(wind_zone=0, subarray=1, panel_type=PanelType.EastWest, coordinate=Coordinate(2, 0), pressure=1.17, ballast=22, presented_link_tray=2, cross_tray=2, wind_anchors=0, seismic_anchors=1, id=7),
            Panel(wind_zone=0, subarray=1, panel_type=PanelType.Corner, coordinate=Coordinate(1, 0), pressure=1.17, ballast=22, presented_link_tray=2, cross_tray=2, wind_anchors=0, seismic_anchors=1, id=8),
            Panel(wind_zone=0, subarray=1, panel_type=PanelType.Corner, coordinate=Coordinate(0, 0), pressure=1.17, ballast=35, presented_link_tray=2, cross_tray=3, wind_anchors=0, seismic_anchors=1, id=9),

            Panel(wind_zone=3, subarray=2, panel_type=PanelType.Corner, coordinate=Coordinate(3, 1), pressure=2.56, ballast=20, presented_link_tray=2, cross_tray=1, wind_anchors=0, seismic_anchors=1, id=10),
            Panel(wind_zone=3, subarray=2, panel_type=PanelType.EastWest, coordinate=Coordinate(2, 1), pressure=2.56, ballast=17, presented_link_tray=2, cross_tray=1, wind_anchors=0, seismic_anchors=1, id=11),
            Panel(wind_zone=3, subarray=2, panel_type=PanelType.Middle, coordinate=Coordinate(1, 1), pressure=2.56, ballast=0, presented_link_tray=0, cross_tray=0, wind_anchors=0, seismic_anchors=1, id=12),
            Panel(wind_zone=3, subarray=2, panel_type=PanelType.Corner, coordinate=Coordinate(0, 1), pressure=2.56, ballast=47, presented_link_tray=2, cross_tray=4, wind_anchors=0, seismic_anchors=1, id=13),
            Panel(wind_zone=3, subarray=2, panel_type=PanelType.Corner, coordinate=Coordinate(3, 0), pressure=2.56, ballast=22, presented_link_tray=2, cross_tray=2, wind_anchors=0, seismic_anchors=1, id=14),
            Panel(wind_zone=3, subarray=2, panel_type=PanelType.Corner, coordinate=Coordinate(2, 0), pressure=2.56, ballast=8, presented_link_tray=1, cross_tray=0, wind_anchors=0, seismic_anchors=1, id=15),
            Panel(wind_zone=3, subarray=2, panel_type=PanelType.NorthSouth, coordinate=Coordinate(1, 0), pressure=2.56, ballast=35, presented_link_tray=2, cross_tray=3, wind_anchors=0, seismic_anchors=1, id=16)
        ]

        subarrays = [
            Subarray(subarray_number=1, origin=Coordinate(0, 0), start_row=0, size=9),
            Subarray(subarray_number=2, origin=Coordinate(0, 2), start_row=9, size=7)
        ]

        expected = [
            {'x': 0, 'y': 1, 'width': 1, 'height': 1, 'data': {'panel_id': 1, 'panel_type': 4, 'ballast': 20, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'A', 'cross_trays': 1, 'link_trays': 2, 'psf': 1.17, 'subarray': 1}},
            {'x': 3, 'y': 2, 'width': 1, 'height': 1, 'data': {'panel_id': 2, 'panel_type': 2, 'ballast': 17, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'A', 'cross_trays': 1, 'link_trays': 2, 'psf': 1.17, 'subarray': 1}},
            {'x': 2, 'y': 2, 'width': 1, 'height': 1, 'data': {'panel_id': 3, 'panel_type': 2, 'ballast':  0, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'A', 'cross_trays': 0, 'link_trays': 0, 'psf': 1.17, 'subarray': 1}},
            {'x': 1, 'y': 2, 'width': 1, 'height': 1, 'data': {'panel_id': 4, 'panel_type': 1, 'ballast': 47, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'A', 'cross_trays': 4, 'link_trays': 2, 'psf': 1.17, 'subarray': 1}},
            {'x': 0, 'y': 2, 'width': 1, 'height': 1, 'data': {'panel_id': 5, 'panel_type': 3, 'ballast': 22, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'A', 'cross_trays': 2, 'link_trays': 2, 'psf': 1.17, 'subarray': 1}},
            {'x': 3, 'y': 3, 'width': 1, 'height': 1, 'data': {'panel_id': 6, 'panel_type': 3, 'ballast':  8, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'A', 'cross_trays': 0, 'link_trays': 1, 'psf': 1.17, 'subarray': 1}},
            {'x': 2, 'y': 3, 'width': 1, 'height': 1, 'data': {'panel_id': 7, 'panel_type': 3, 'ballast': 22, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'A', 'cross_trays': 2, 'link_trays': 2, 'psf': 1.17, 'subarray': 1}},
            {'x': 1, 'y': 3, 'width': 1, 'height': 1, 'data': {'panel_id': 8, 'panel_type': 1, 'ballast': 22, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'A', 'cross_trays': 2, 'link_trays': 2, 'psf': 1.17, 'subarray': 1}},
            {'x': 0, 'y': 3, 'width': 1, 'height': 1, 'data': {'panel_id': 9, 'panel_type': 1, 'ballast': 35, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'A', 'cross_trays': 3, 'link_trays': 2, 'psf': 1.17, 'subarray': 1}},

            {'x': 3, 'y': 0, 'width': 1, 'height': 1, 'data': {'panel_id': 10, 'panel_type': 1, 'ballast': 20, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'D', 'cross_trays': 1, 'link_trays': 2, 'psf': 2.56, 'subarray': 2}},
            {'x': 2, 'y': 0, 'width': 1, 'height': 1, 'data': {'panel_id': 11, 'panel_type': 3, 'ballast': 17, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'D', 'cross_trays': 1, 'link_trays': 2, 'psf': 2.56, 'subarray': 2}},
            {'x': 1, 'y': 0, 'width': 1, 'height': 1, 'data': {'panel_id': 12, 'panel_type': 4, 'ballast':  0, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'D', 'cross_trays': 0, 'link_trays': 0, 'psf': 2.56, 'subarray': 2}},
            {'x': 0, 'y': 0, 'width': 1, 'height': 1, 'data': {'panel_id': 13, 'panel_type': 1, 'ballast': 47, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'D', 'cross_trays': 4, 'link_trays': 2, 'psf': 2.56, 'subarray': 2}},
            {'x': 3, 'y': 1, 'width': 1, 'height': 1, 'data': {'panel_id': 14, 'panel_type': 1, 'ballast': 22, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'D', 'cross_trays': 2, 'link_trays': 2, 'psf': 2.56, 'subarray': 2}},
            {'x': 2, 'y': 1, 'width': 1, 'height': 1, 'data': {'panel_id': 15, 'panel_type': 1, 'ballast':  8, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'D', 'cross_trays': 0, 'link_trays': 1, 'psf': 2.56, 'subarray': 2}},
            {'x': 1, 'y': 1, 'width': 1, 'height': 1, 'data': {'panel_id': 16, 'panel_type': 2, 'ballast': 35, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'D', 'cross_trays': 3, 'link_trays': 2, 'psf': 2.56, 'subarray': 2}},
        ]

        received = self.subject.get_panel_data(panels, subarrays)
        assert_array_equal(received, expected)

    def test_get_buildings_data(self):
        self.subject = ProjectPresenter(SystemType.singleTilt, ModuleType.Cell96)
        buildings = [ [ Coordinate(0,0), Coordinate(60,0), Coordinate(60,60), Coordinate(0,60)  ] ] # big square
        expected_buildings = [[         
          {'x': 0,  '_Coordinate__rounded_x': 0,  'y': 60,  '_Coordinate__rounded_y': 0, 'rotation': 0.0},
          {'x': 60, '_Coordinate__rounded_x': 60, 'y': 60,  '_Coordinate__rounded_y': 0, 'rotation': 0.0},
          {'x': 60, '_Coordinate__rounded_x': 60, 'y': 0, '_Coordinate__rounded_y': 60,  'rotation': 0.0},
          {'x': 0,  '_Coordinate__rounded_x': 0,  'y': 0, '_Coordinate__rounded_y': 60,  'rotation': 0.0}
        ]]
        actual_buildings = self.subject.get_buildings(buildings,60)
        assert_array_equal(actual_buildings,expected_buildings)

    def test_get_max_y(self):
        self.subject = ProjectPresenter(SystemType.singleTilt, ModuleType.Cell96)
        panels = [
            Panel(wind_zone=0, subarray=1, panel_type=PanelType.Middle, coordinate=Coordinate(0, 2), pressure=1.17, ballast=20, presented_link_tray=2, cross_tray=1, wind_anchors=0, seismic_anchors=1, id=1),
            Panel(wind_zone=0, subarray=1, panel_type=PanelType.NorthSouth, coordinate=Coordinate(3, 1), pressure=1.17, ballast=17, presented_link_tray=2, cross_tray=1, wind_anchors=0, seismic_anchors=1, id=2),
        ]
        buildings = [ [ Coordinate(-60,-60), Coordinate(60,-60), Coordinate(60,60), Coordinate(-60,60)  ] ] # big square
        expected_max_y = 60
        actual_max_y = self.subject.get_max_y(buildings,panels)
        assert_equal(actual_max_y, expected_max_y)

        expected_max_y = 2
        actual_max_y = self.subject.get_max_y([],panels)
        assert_equal(actual_max_y, expected_max_y)




    def test_get_table_data_single_tilt_128cell(self):
        self.subject = ProjectPresenter(SystemType.singleTilt, ModuleType.Cell128)
        panels = [
            Panel(wind_zone=0, subarray=1, panel_type=PanelType.Middle, coordinate=Coordinate(0, 2), pressure=1.17, ballast=20, presented_link_tray=2, cross_tray=1, wind_anchors=0, seismic_anchors=1, id=1),
            Panel(wind_zone=0, subarray=1, panel_type=PanelType.NorthSouth, coordinate=Coordinate(3, 1), pressure=1.17, ballast=17, presented_link_tray=2, cross_tray=1, wind_anchors=0, seismic_anchors=1, id=2),
            Panel(wind_zone=0, subarray=1, panel_type=PanelType.NorthSouth, coordinate=Coordinate(2, 1), pressure=1.17, ballast=0, presented_link_tray=0, cross_tray=0, wind_anchors=0, seismic_anchors=1, id=3),
            Panel(wind_zone=0, subarray=1, panel_type=PanelType.Corner, coordinate=Coordinate(1, 1), pressure=1.17, ballast=47, presented_link_tray=2, cross_tray=4, wind_anchors=0, seismic_anchors=1, id=4),
            Panel(wind_zone=0, subarray=1, panel_type=PanelType.EastWest, coordinate=Coordinate(0, 1), pressure=1.17, ballast=22, presented_link_tray=2, cross_tray=2, wind_anchors=0, seismic_anchors=1, id=5),
            Panel(wind_zone=0, subarray=1, panel_type=PanelType.EastWest, coordinate=Coordinate(3, 0), pressure=1.17, ballast=8, presented_link_tray=1, cross_tray=0, wind_anchors=0, seismic_anchors=1, id=6),
            Panel(wind_zone=0, subarray=1, panel_type=PanelType.EastWest, coordinate=Coordinate(2, 0), pressure=1.17, ballast=22, presented_link_tray=2, cross_tray=2, wind_anchors=0, seismic_anchors=1, id=7),
            Panel(wind_zone=0, subarray=1, panel_type=PanelType.Corner, coordinate=Coordinate(1, 0), pressure=1.17, ballast=22, presented_link_tray=2, cross_tray=2, wind_anchors=0, seismic_anchors=1, id=8),
            Panel(wind_zone=0, subarray=1, panel_type=PanelType.Corner, coordinate=Coordinate(0, 0), pressure=1.17, ballast=35, presented_link_tray=2, cross_tray=3, wind_anchors=0, seismic_anchors=1, id=9),

            Panel(wind_zone=3, subarray=2, panel_type=PanelType.Corner, coordinate=Coordinate(3, 1), pressure=2.56, ballast=20, presented_link_tray=2, cross_tray=1, wind_anchors=0, seismic_anchors=1, id=10),
            Panel(wind_zone=3, subarray=2, panel_type=PanelType.EastWest, coordinate=Coordinate(2, 1), pressure=2.56, ballast=17, presented_link_tray=2, cross_tray=1, wind_anchors=0, seismic_anchors=1, id=11),
            Panel(wind_zone=3, subarray=2, panel_type=PanelType.Middle, coordinate=Coordinate(1, 1), pressure=2.56, ballast=0, presented_link_tray=0, cross_tray=0, wind_anchors=0, seismic_anchors=1, id=12),
            Panel(wind_zone=3, subarray=2, panel_type=PanelType.Corner, coordinate=Coordinate(0, 1), pressure=2.56, ballast=47, presented_link_tray=2, cross_tray=4, wind_anchors=0, seismic_anchors=1, id=13),
            Panel(wind_zone=3, subarray=2, panel_type=PanelType.Corner, coordinate=Coordinate(3, 0), pressure=2.56, ballast=22, presented_link_tray=2, cross_tray=2, wind_anchors=0, seismic_anchors=1, id=14),
            Panel(wind_zone=3, subarray=2, panel_type=PanelType.Corner, coordinate=Coordinate(2, 0), pressure=2.56, ballast=8, presented_link_tray=1, cross_tray=0, wind_anchors=0, seismic_anchors=1, id=15),
            Panel(wind_zone=3, subarray=2, panel_type=PanelType.NorthSouth, coordinate=Coordinate(1, 0), pressure=2.56, ballast=35, presented_link_tray=2, cross_tray=3, wind_anchors=0, seismic_anchors=1, id=16)
        ]

        subarrays= [
            Subarray(subarray_number=1, origin=Coordinate(0, 0), start_row=0, size=9),
            Subarray(subarray_number=2, origin=Coordinate(0, 2), start_row=9, size=7)
        ]

        expected = [
            {'x': 0.0, 'y': 1, 'width': 1.5, 'height': 1, 'data': {'panel_id': 1, 'panel_type': 4, 'ballast': 20, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'A', 'cross_trays': 1, 'link_trays': 2, 'psf': 1.17, 'subarray': 1}},
            {'x': 4.5, 'y': 2, 'width': 1.5, 'height': 1, 'data': {'panel_id': 2, 'panel_type': 2, 'ballast': 17, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'A', 'cross_trays': 1, 'link_trays': 2, 'psf': 1.17, 'subarray': 1}},
            {'x': 3.0, 'y': 2, 'width': 1.5, 'height': 1, 'data': {'panel_id': 3, 'panel_type': 2, 'ballast':  0, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'A', 'cross_trays': 0, 'link_trays': 0, 'psf': 1.17, 'subarray': 1}},
            {'x': 1.5, 'y': 2, 'width': 1.5, 'height': 1, 'data': {'panel_id': 4, 'panel_type': 1, 'ballast': 47, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'A', 'cross_trays': 4, 'link_trays': 2, 'psf': 1.17, 'subarray': 1}},
            {'x': 0.0, 'y': 2, 'width': 1.5, 'height': 1, 'data': {'panel_id': 5, 'panel_type': 3, 'ballast': 22, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'A', 'cross_trays': 2, 'link_trays': 2, 'psf': 1.17, 'subarray': 1}},
            {'x': 4.5, 'y': 3, 'width': 1.5, 'height': 1, 'data': {'panel_id': 6, 'panel_type': 3, 'ballast':  8, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'A', 'cross_trays': 0, 'link_trays': 1, 'psf': 1.17, 'subarray': 1}},
            {'x': 3.0, 'y': 3, 'width': 1.5, 'height': 1, 'data': {'panel_id': 7, 'panel_type': 3, 'ballast': 22, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'A', 'cross_trays': 2, 'link_trays': 2, 'psf': 1.17, 'subarray': 1}},
            {'x': 1.5, 'y': 3, 'width': 1.5, 'height': 1, 'data': {'panel_id': 8, 'panel_type': 1, 'ballast': 22, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'A', 'cross_trays': 2, 'link_trays': 2, 'psf': 1.17, 'subarray': 1}},
            {'x': 0.0, 'y': 3, 'width': 1.5, 'height': 1, 'data': {'panel_id': 9, 'panel_type': 1, 'ballast': 35, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'A', 'cross_trays': 3, 'link_trays': 2, 'psf': 1.17, 'subarray': 1}},

            {'x': 4.5, 'y': 0, 'width': 1.5, 'height': 1, 'data': {'panel_id': 10, 'panel_type': 1, 'ballast': 20, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'D', 'cross_trays': 1, 'link_trays': 2, 'psf': 2.56, 'subarray': 2}},
            {'x': 3.0, 'y': 0, 'width': 1.5, 'height': 1, 'data': {'panel_id': 11, 'panel_type': 3, 'ballast': 17, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'D', 'cross_trays': 1, 'link_trays': 2, 'psf': 2.56, 'subarray': 2}},
            {'x': 1.5, 'y': 0, 'width': 1.5, 'height': 1, 'data': {'panel_id': 12, 'panel_type': 4, 'ballast':  0, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'D', 'cross_trays': 0, 'link_trays': 0, 'psf': 2.56, 'subarray': 2}},
            {'x': 0.0, 'y': 0, 'width': 1.5, 'height': 1, 'data': {'panel_id': 13, 'panel_type': 1, 'ballast': 47, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'D', 'cross_trays': 4, 'link_trays': 2, 'psf': 2.56, 'subarray': 2}},
            {'x': 4.5, 'y': 1, 'width': 1.5, 'height': 1, 'data': {'panel_id': 14, 'panel_type': 1, 'ballast': 22, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'D', 'cross_trays': 2, 'link_trays': 2, 'psf': 2.56, 'subarray': 2}},
            {'x': 3.0, 'y': 1, 'width': 1.5, 'height': 1, 'data': {'panel_id': 15, 'panel_type': 1, 'ballast':  8, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'D', 'cross_trays': 0, 'link_trays': 1, 'psf': 2.56, 'subarray': 2}},
            {'x': 1.5, 'y': 1, 'width': 1.5, 'height': 1, 'data': {'panel_id': 16, 'panel_type': 2, 'ballast': 35, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'D', 'cross_trays': 3, 'link_trays': 2, 'psf': 2.56, 'subarray': 2}},
        ]

        received = self.subject.get_panel_data(panels, subarrays)
        assert_array_equal(received, expected)

    def test_get_table_data_dual_tilt_96cell(self):
        self.subject = ProjectPresenter(SystemType.dualTilt, ModuleType.Cell96)

        panels =[
            Panel(wind_zone=4, subarray=1, panel_type=PanelType.Middle, coordinate=Coordinate(0, 2), pressure=1.23, ballast=20, presented_link_tray=2, cross_tray=1, wind_anchors=0, seismic_anchors=1, id=1),
            Panel(wind_zone=4, subarray=1, panel_type=PanelType.NorthSouth, coordinate=Coordinate(3, 1), pressure=1.23, ballast=17, presented_link_tray=2, cross_tray=1, wind_anchors=0, seismic_anchors=1, id=2),
            Panel(wind_zone=4, subarray=1, panel_type=PanelType.NorthSouth, coordinate=Coordinate(2, 1), pressure=1.23, ballast=0, presented_link_tray=0, cross_tray=0, wind_anchors=0, seismic_anchors=1, id=3),
            Panel(wind_zone=4, subarray=1, panel_type=PanelType.Corner, coordinate=Coordinate(1, 1), pressure=1.23, ballast=47, presented_link_tray=2, cross_tray=4, wind_anchors=0, seismic_anchors=1, id=4),
            Panel(wind_zone=4, subarray=1, panel_type=PanelType.EastWest, coordinate=Coordinate(0, 1), pressure=1.23, ballast=22, presented_link_tray=2, cross_tray=2, wind_anchors=0, seismic_anchors=1, id=5),
            Panel(wind_zone=4, subarray=1, panel_type=PanelType.EastWest, coordinate=Coordinate(3, 0), pressure=1.23, ballast=8, presented_link_tray=1, cross_tray=0, wind_anchors=0, seismic_anchors=1, id=6),
            Panel(wind_zone=4, subarray=1, panel_type=PanelType.EastWest, coordinate=Coordinate(2, 0), pressure=1.23, ballast=22, presented_link_tray=2, cross_tray=2, wind_anchors=0, seismic_anchors=1, id=7),
            Panel(wind_zone=4, subarray=1, panel_type=PanelType.Corner, coordinate=Coordinate(1, 0), pressure=1.23, ballast=22, presented_link_tray=2, cross_tray=2, wind_anchors=0, seismic_anchors=1, id=8),
            Panel(wind_zone=4, subarray=1, panel_type=PanelType.Corner, coordinate=Coordinate(0, 0), pressure=1.23, ballast=35, presented_link_tray=2, cross_tray=3, wind_anchors=0, seismic_anchors=1, id=9),

            Panel(wind_zone=1, subarray=2, panel_type=PanelType.Corner, coordinate=Coordinate(3, 1), pressure=3.14, ballast=20, presented_link_tray=2, cross_tray=1, wind_anchors=0, seismic_anchors=1, id=10),
            Panel(wind_zone=1, subarray=2, panel_type=PanelType.EastWest, coordinate=Coordinate(2, 1), pressure=3.14, ballast=17, presented_link_tray=2, cross_tray=1, wind_anchors=0, seismic_anchors=1, id=11),
            Panel(wind_zone=1, subarray=2, panel_type=PanelType.Middle, coordinate=Coordinate(1, 1), pressure=3.14, ballast=0, presented_link_tray=0, cross_tray=0, wind_anchors=0, seismic_anchors=1, id=12),
            Panel(wind_zone=1, subarray=2, panel_type=PanelType.Corner, coordinate=Coordinate(0, 1), pressure=3.14, ballast=47, presented_link_tray=2, cross_tray=4, wind_anchors=0, seismic_anchors=1, id=13),
            Panel(wind_zone=1, subarray=2, panel_type=PanelType.Corner, coordinate=Coordinate(3, 0), pressure=3.14, ballast=22, presented_link_tray=2, cross_tray=2, wind_anchors=0, seismic_anchors=1, id=14),
            Panel(wind_zone=1, subarray=2, panel_type=PanelType.Corner, coordinate=Coordinate(2, 0), pressure=3.14, ballast=8, presented_link_tray=1, cross_tray=0, wind_anchors=0, seismic_anchors=1, id=15),
            Panel(wind_zone=1, subarray=2, panel_type=PanelType.NorthSouth, coordinate=Coordinate(1, 0), pressure=3.14, ballast=35, presented_link_tray=2, cross_tray=3, wind_anchors=0, seismic_anchors=1, id=16)
        ]

        subarrays = [
            Subarray(subarray_number=1, origin=Coordinate(0, 0), start_row=0, size=9),
            Subarray(subarray_number=2, origin=Coordinate(0, 2), start_row=9, size=7)
        ]

        expected = [
            {'x': 0.0, 'y': 1, 'width': 1.5, 'height': 1, 'data': {'panel_id': 1, 'panel_type': 4, 'ballast': 20, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'E', 'cross_trays': 1, 'link_trays': 2, 'psf': 1.23, 'subarray': 1}},
            {'x': 4.5, 'y': 2, 'width': 1.5, 'height': 1, 'data': {'panel_id': 2, 'panel_type': 2, 'ballast': 17, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'E', 'cross_trays': 1, 'link_trays': 2, 'psf': 1.23, 'subarray': 1}},
            {'x': 3.0, 'y': 2, 'width': 1.5, 'height': 1, 'data': {'panel_id': 3, 'panel_type': 2, 'ballast':  0, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'E', 'cross_trays': 0, 'link_trays': 0, 'psf': 1.23, 'subarray': 1}},
            {'x': 1.5, 'y': 2, 'width': 1.5, 'height': 1, 'data': {'panel_id': 4, 'panel_type': 1, 'ballast': 47, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'E', 'cross_trays': 4, 'link_trays': 2, 'psf': 1.23, 'subarray': 1}},
            {'x': 0.0, 'y': 2, 'width': 1.5, 'height': 1, 'data': {'panel_id': 5, 'panel_type': 3, 'ballast': 22, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'E', 'cross_trays': 2, 'link_trays': 2, 'psf': 1.23, 'subarray': 1}},
            {'x': 4.5, 'y': 3, 'width': 1.5, 'height': 1, 'data': {'panel_id': 6, 'panel_type': 3, 'ballast':  8, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'E', 'cross_trays': 0, 'link_trays': 1, 'psf': 1.23, 'subarray': 1}},
            {'x': 3.0, 'y': 3, 'width': 1.5, 'height': 1, 'data': {'panel_id': 7, 'panel_type': 3, 'ballast': 22, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'E', 'cross_trays': 2, 'link_trays': 2, 'psf': 1.23, 'subarray': 1}},
            {'x': 1.5, 'y': 3, 'width': 1.5, 'height': 1, 'data': {'panel_id': 8, 'panel_type': 1, 'ballast': 22, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'E', 'cross_trays': 2, 'link_trays': 2, 'psf': 1.23, 'subarray': 1}},
            {'x': 0.0, 'y': 3, 'width': 1.5, 'height': 1, 'data': {'panel_id': 9, 'panel_type': 1, 'ballast': 35, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'E', 'cross_trays': 3, 'link_trays': 2, 'psf': 1.23, 'subarray': 1}},

            {'x': 4.5, 'y': 0, 'width': 1.5, 'height': 1, 'data': {'panel_id': 10, 'panel_type': 1, 'ballast': 20, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'B', 'cross_trays': 1, 'link_trays': 2, 'psf': 3.14, 'subarray': 2}},
            {'x': 3.0, 'y': 0, 'width': 1.5, 'height': 1, 'data': {'panel_id': 11, 'panel_type': 3, 'ballast': 17, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'B', 'cross_trays': 1, 'link_trays': 2, 'psf': 3.14, 'subarray': 2}},
            {'x': 1.5, 'y': 0, 'width': 1.5, 'height': 1, 'data': {'panel_id': 12, 'panel_type': 4, 'ballast':  0, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'B', 'cross_trays': 0, 'link_trays': 0, 'psf': 3.14, 'subarray': 2}},
            {'x': 0.0, 'y': 0, 'width': 1.5, 'height': 1, 'data': {'panel_id': 13, 'panel_type': 1, 'ballast': 47, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'B', 'cross_trays': 4, 'link_trays': 2, 'psf': 3.14, 'subarray': 2}},
            {'x': 4.5, 'y': 1, 'width': 1.5, 'height': 1, 'data': {'panel_id': 14, 'panel_type': 1, 'ballast': 22, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'B', 'cross_trays': 2, 'link_trays': 2, 'psf': 3.14, 'subarray': 2}},
            {'x': 3.0, 'y': 1, 'width': 1.5, 'height': 1, 'data': {'panel_id': 15, 'panel_type': 1, 'ballast':  8, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'B', 'cross_trays': 0, 'link_trays': 1, 'psf': 3.14, 'subarray': 2}},
            {'x': 1.5, 'y': 1, 'width': 1.5, 'height': 1, 'data': {'panel_id': 16, 'panel_type': 2, 'ballast': 35, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'B', 'cross_trays': 3, 'link_trays': 2, 'psf': 3.14, 'subarray': 2}},
        ]

        received = self.subject.get_panel_data(panels, subarrays)
        assert_array_equal(received, expected)

    def test_get_table_data_dual_tilt_128cell(self):
        self.subject = ProjectPresenter(SystemType.dualTilt, ModuleType.Cell128)
        panels =[
            Panel(wind_zone=4, subarray=1, panel_type=PanelType.Middle, coordinate=Coordinate(0, 2), pressure=1.23, ballast=20, presented_link_tray=2, cross_tray=1, wind_anchors=0, seismic_anchors=1, id=1),
            Panel(wind_zone=4, subarray=1, panel_type=PanelType.NorthSouth, coordinate=Coordinate(3, 1), pressure=1.23, ballast=17, presented_link_tray=2, cross_tray=1, wind_anchors=0, seismic_anchors=1, id=2),
            Panel(wind_zone=4, subarray=1, panel_type=PanelType.NorthSouth, coordinate=Coordinate(2, 1), pressure=1.23, ballast=0, presented_link_tray=0, cross_tray=0, wind_anchors=0, seismic_anchors=1, id=3),
            Panel(wind_zone=4, subarray=1, panel_type=PanelType.Corner, coordinate=Coordinate(1, 1), pressure=1.23, ballast=47, presented_link_tray=2, cross_tray=4, wind_anchors=0, seismic_anchors=1, id=4),
            Panel(wind_zone=4, subarray=1, panel_type=PanelType.EastWest, coordinate=Coordinate(0, 1), pressure=1.23, ballast=22, presented_link_tray=2, cross_tray=2, wind_anchors=0, seismic_anchors=1, id=5),
            Panel(wind_zone=4, subarray=1, panel_type=PanelType.EastWest, coordinate=Coordinate(3, 0), pressure=1.23, ballast=8, presented_link_tray=1, cross_tray=0, wind_anchors=0, seismic_anchors=1, id=6),
            Panel(wind_zone=4, subarray=1, panel_type=PanelType.EastWest, coordinate=Coordinate(2, 0), pressure=1.23, ballast=22, presented_link_tray=2, cross_tray=2, wind_anchors=0, seismic_anchors=1, id=7),
            Panel(wind_zone=4, subarray=1, panel_type=PanelType.Corner, coordinate=Coordinate(1, 0), pressure=1.23, ballast=22, presented_link_tray=2, cross_tray=2, wind_anchors=0, seismic_anchors=1, id=8),
            Panel(wind_zone=4, subarray=1, panel_type=PanelType.Corner, coordinate=Coordinate(0, 0), pressure=1.23, ballast=35, presented_link_tray=2, cross_tray=3, wind_anchors=0, seismic_anchors=1, id=9),

            Panel(wind_zone=1, subarray=2, panel_type=PanelType.Corner, coordinate=Coordinate(3, 1), pressure=3.14, ballast=20, presented_link_tray=2, cross_tray=1, wind_anchors=0, seismic_anchors=1, id=10),
            Panel(wind_zone=1, subarray=2, panel_type=PanelType.EastWest, coordinate=Coordinate(2, 1), pressure=3.14, ballast=17, presented_link_tray=2, cross_tray=1, wind_anchors=0, seismic_anchors=1, id=11),
            Panel(wind_zone=1, subarray=2, panel_type=PanelType.Middle, coordinate=Coordinate(1, 1), pressure=3.14, ballast=0, presented_link_tray=0, cross_tray=0, wind_anchors=0, seismic_anchors=1, id=12),
            Panel(wind_zone=1, subarray=2, panel_type=PanelType.Corner, coordinate=Coordinate(0, 1), pressure=3.14, ballast=47, presented_link_tray=2, cross_tray=4, wind_anchors=0, seismic_anchors=1, id=13),
            Panel(wind_zone=1, subarray=2, panel_type=PanelType.Corner, coordinate=Coordinate(3, 0), pressure=3.14, ballast=22, presented_link_tray=2, cross_tray=2, wind_anchors=0, seismic_anchors=1, id=14),
            Panel(wind_zone=1, subarray=2, panel_type=PanelType.Corner, coordinate=Coordinate(2, 0), pressure=3.14, ballast=8, presented_link_tray=1, cross_tray=0, wind_anchors=0, seismic_anchors=1, id=15),
            Panel(wind_zone=1, subarray=2, panel_type=PanelType.NorthSouth, coordinate=Coordinate(1, 0), pressure=3.14, ballast=35, presented_link_tray=2, cross_tray=3, wind_anchors=0, seismic_anchors=1, id=16)
        ]

        subarrays = [
            Subarray(subarray_number=1, origin=Coordinate(0, 0), start_row=0, size=9),
            Subarray(subarray_number=2, origin=Coordinate(0, 2), start_row=9, size=7)
        ]

        expected = [
            {'x': 0.0, 'y': 1.5, 'width': 1.5, 'height': 1.5, 'data': {'panel_id': 1, 'panel_type': 4, 'ballast': 20, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'E', 'cross_trays': 1, 'link_trays': 2, 'psf': 1.23, 'subarray': 1}},
            {'x': 4.5, 'y': 3.0, 'width': 1.5, 'height': 1.5, 'data': {'panel_id': 2, 'panel_type': 2, 'ballast': 17, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'E', 'cross_trays': 1, 'link_trays': 2, 'psf': 1.23, 'subarray': 1}},
            {'x': 3.0, 'y': 3.0, 'width': 1.5, 'height': 1.5, 'data': {'panel_id': 3, 'panel_type': 2, 'ballast':  0, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'E', 'cross_trays': 0, 'link_trays': 0, 'psf': 1.23, 'subarray': 1}},
            {'x': 1.5, 'y': 3.0, 'width': 1.5, 'height': 1.5, 'data': {'panel_id': 4, 'panel_type': 1, 'ballast': 47, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'E', 'cross_trays': 4, 'link_trays': 2, 'psf': 1.23, 'subarray': 1}},
            {'x': 0.0, 'y': 3.0, 'width': 1.5, 'height': 1.5, 'data': {'panel_id': 5, 'panel_type': 3, 'ballast': 22, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'E', 'cross_trays': 2, 'link_trays': 2, 'psf': 1.23, 'subarray': 1}},
            {'x': 4.5, 'y': 4.5, 'width': 1.5, 'height': 1.5, 'data': {'panel_id': 6, 'panel_type': 3, 'ballast':  8, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'E', 'cross_trays': 0, 'link_trays': 1, 'psf': 1.23, 'subarray': 1}},
            {'x': 3.0, 'y': 4.5, 'width': 1.5, 'height': 1.5, 'data': {'panel_id': 7, 'panel_type': 3, 'ballast': 22, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'E', 'cross_trays': 2, 'link_trays': 2, 'psf': 1.23, 'subarray': 1}},
            {'x': 1.5, 'y': 4.5, 'width': 1.5, 'height': 1.5, 'data': {'panel_id': 8, 'panel_type': 1, 'ballast': 22, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'E', 'cross_trays': 2, 'link_trays': 2, 'psf': 1.23, 'subarray': 1}},
            {'x': 0.0, 'y': 4.5, 'width': 1.5, 'height': 1.5, 'data': {'panel_id': 9, 'panel_type': 1, 'ballast': 35, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'E', 'cross_trays': 3, 'link_trays': 2, 'psf': 1.23, 'subarray': 1}},

            {'x': 4.5, 'y': 0.0, 'width': 1.5, 'height': 1.5, 'data': {'panel_id': 10, 'panel_type': 1, 'ballast': 20, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'B', 'cross_trays': 1, 'link_trays': 2, 'psf': 3.14, 'subarray': 2}},
            {'x': 3.0, 'y': 0.0, 'width': 1.5, 'height': 1.5, 'data': {'panel_id': 11, 'panel_type': 3, 'ballast': 17, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'B', 'cross_trays': 1, 'link_trays': 2, 'psf': 3.14, 'subarray': 2}},
            {'x': 1.5, 'y': 0.0, 'width': 1.5, 'height': 1.5, 'data': {'panel_id': 12, 'panel_type': 4, 'ballast':  0, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'B', 'cross_trays': 0, 'link_trays': 0, 'psf': 3.14, 'subarray': 2}},
            {'x': 0.0, 'y': 0.0, 'width': 1.5, 'height': 1.5, 'data': {'panel_id': 13, 'panel_type': 1, 'ballast': 47, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'B', 'cross_trays': 4, 'link_trays': 2, 'psf': 3.14, 'subarray': 2}},
            {'x': 4.5, 'y': 1.5, 'width': 1.5, 'height': 1.5, 'data': {'panel_id': 14, 'panel_type': 1, 'ballast': 22, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'B', 'cross_trays': 2, 'link_trays': 2, 'psf': 3.14, 'subarray': 2}},
            {'x': 3.0, 'y': 1.5, 'width': 1.5, 'height': 1.5, 'data': {'panel_id': 15, 'panel_type': 1, 'ballast':  8, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'B', 'cross_trays': 0, 'link_trays': 1, 'psf': 3.14, 'subarray': 2}},
            {'x': 1.5, 'y': 1.5, 'width': 1.5, 'height': 1.5, 'data': {'panel_id': 16, 'panel_type': 2, 'ballast': 35, 'wind_anchors': 0, 'seismic_anchors': 1, 'wind_zones': 'B', 'cross_trays': 3, 'link_trays': 2, 'psf': 3.14, 'subarray': 2}},
        ]

        received = self.subject.get_panel_data(panels, subarrays)
        assert_array_equal(received, expected)
