예제 #1
0
    def test_should_add_object_when_object_within_bounds(self):  # noqa: D102
        grid = TetrisGrid(10)
        # Single element at (5, 5) should fit within wall bounds
        layout = Layout([Position(0, 0)])
        object = TetrisPiece(layout, Position(5, 5))

        grid.add_object(object)
예제 #2
0
    def test_should_should_raise_conflict_exception_when_attempting_to_add_overlapping_object(
            self):  # noqa: D102
        grid = TetrisGrid(10)
        layout = Layout([Position(0, 0)])
        object = TetrisPiece(layout, Position(5, 5))

        grid.add_object(object)
        with self.assertRaises(ElementConflictException):
            grid.add_object(object)
예제 #3
0
    def test_should_should_raise_out_of_bounds_exception_when_attempting_to_add_object_overlapping_wall(
            self):  # noqa: D102
        grid = TetrisGrid(10)
        # Single element at (0, 0) overlaps with floor
        layout = Layout([Position(0, 0)])
        object = TetrisPiece(layout, Position(0, 0))

        with self.assertRaises(ElementOutOfBoundsException):
            grid.add_object(object)
예제 #4
0
    def test_grid_should_allow_adding_object_when_object_within_bounds(
            self):  # noqa: D102
        grid = TetrisGrid(10)
        # Single element at (5, 5) should fit within wall bounds
        layout = Layout([Position(0, 0)])
        object = TetrisPiece(layout, Position(5, 5))

        can_add_object = grid.can_add_object(object)

        self.assertTrue(can_add_object)
예제 #5
0
def main():

    file_path = './data/test_1.json'
    out_path = './out/'
    if not os.path.exists(out_path):
        os.makedirs(out_path)
    with open(file_path, 'r', encoding='utf8') as fp:
        description = json.load(fp)

    ins_layout = Layout(description, config_dict)
    image = ins_layout.render()

    filename = get_file_name(file_path)
    save_path = out_path + filename.replace('json', 'jpg')
    cv2.imshow('canvas', image)
    cv2.imwrite(save_path, image)
    cv2.waitKey(0)

    pass
예제 #6
0
    def test_object_should_have_valid_move(self):  # noqa: D102
        grid = TetrisGrid(10)
        layout = Layout(
            [Position(0, 0),
             Position(1, 0),
             Position(0, 1),
             Position(1, 1)])
        object = TetrisPiece(layout, Position(4, 8))

        has_valid_move = grid.object_has_valid_move(object)

        self.assertTrue(has_valid_move)
예제 #7
0
    def test_object_should_not_have_valid_move_when_already_on_floor(
            self):  # noqa: D102
        grid = TetrisGrid(10)
        layout = Layout(
            [Position(0, 0),
             Position(1, 0),
             Position(0, 1),
             Position(1, 1)])
        object = TetrisPiece(layout, Position(5, 0))

        has_valid_move = grid.object_has_valid_move(object)

        self.assertFalse(has_valid_move)
예제 #8
0
    def test_should_move_right(self):  # noqa: D102
        layout = Layout([
            Position(0, 1),
            Position(1, 0),
            Position(1, 1),
        ])
        position = Position(5, 5)
        piece = TetrisPiece(layout, position)

        new_piece = piece.moved(MovementType.RIGHT)

        self.assertEquals(Position(5 + MOVE_UNITS, 5), new_piece.position)
        self.assertEquals(Position(6 + MOVE_UNITS, 6),
                          new_piece.elements[2].position)
예제 #9
0
    def test_should_move_down(self):  # noqa: D102
        layout = Layout([
            Position(0, 1),
            Position(1, 0),
            Position(1, 1),
        ])
        position = Position(5, 5)
        piece = TetrisPiece(layout, position)

        new_piece = piece.moved_down()

        self.assertEquals(Position(5, 5 - MOVE_UNITS), new_piece.position)
        self.assertEquals(Position(6, 6 - MOVE_UNITS),
                          new_piece.elements[2].position)
예제 #10
0
    def test_should_rotate_anticlockwise(self):  # noqa: D102
        layout = Layout([
            Position(0, 1),
            Position(1, 0),
            Position(1, 1),
        ])
        position = Position(5, 5)
        piece = TetrisPiece(layout, position)

        new_piece = piece.moved(MovementType.ROTATE_ANTICLOCKWISE)

        self.assertEquals(Position(5, 5), new_piece.position)
        self.assertEquals(Position(4, 5), new_piece.elements[0].position)
        self.assertEquals(Position(5, 6), new_piece.elements[1].position)
        self.assertEquals(Position(4, 6), new_piece.elements[2].position)
예제 #11
0
    def test_should_initialise_elements_in_positions_according_to_layout(
            self):  # noqa: D102
        layout = Layout([
            # Absolute position = (5, 6)
            Position(0, 1),
            # Absolute position = (6, 5)
            Position(1, 0),
            # Absolute position = (6, 6)
            Position(1, 1),
        ])
        position = Position(5, 5)
        piece = TetrisPiece(layout, position)

        self.assertEquals(3, len(piece.elements))
        self.assertEquals(Position(5, 6), piece.elements[0].position)
        self.assertEquals(Position(6, 5), piece.elements[1].position)
        self.assertEquals(Position(6, 6), piece.elements[2].position)
예제 #12
0
storage = Storage.connect(
    dbname=cfg.PG_NAME,
    user=cfg.PG_USER,
    password=cfg.PG_PASS,
    host=cfg.PG_HOST,
    port=cfg.PG_PORT)

posts = storage.get_posts()
groups = storage.get_groups()
entities = storage.get_entities()

posts_df = TextProcessor.parse_posts(posts)
groups_df = TextProcessor.parse_groups(groups)
entities_df = TextProcessor.parse_entities(entities)

layout = Layout(groups=list(groups_df['name'].values), data_update_interval=cfg.DATA_UPDATING_INTERVAL)

app.layout = html.Div([
    layout.Navbar,
    dbc.Row([
        dbc.Col([
            layout.GroupCard,
            layout.NewsCard
        ],
            md=2),
        dbc.Col(layout.GroupStatPlots,
                md=5,
                style={
                    # 'margin-left': '1vh',
                    'margin-top': '1vh'
                }