"""add view and camera id

Revision ID: 8febec5ed501
Revises: <PASSWORD>
Create Date: 2019-10-02 16:57:08.630098

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '8febec5ed501'
down_revision = '<PASSWORD>'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('video', sa.Column('camera_id', sa.Integer(), nullable=False))
    op.add_column('video', sa.Column('view_id', sa.Integer(), nullable=False))
    db = op.get_bind()
    video = sa.sql.table('video', sa.sql.column('id'), sa.sql.column('camera_id'),
            sa.sql.column('view_id'), sa.sql.column('url_part'), sa.sql.column('file_name'))
    for b in db.execute(video.select()):
        #print("Update video id: " + str(b.id))
        url_part = b.url_part
        file_name = b.file_name
        camera_id = -1
        view_id = -1
        if "clairton1" in url_part:
            camera_id = 0
            if "6304,964,6807,1467" in url_part or "6304,884,6807,1387" in url_part or "6304,944,6807,1447" in url_part or "6304,884,6807,1387" in url_part or "6282,1154,6769,1641" in url_part:
                view_id = 0
            elif "6007,1008,6509,1510" in url_part or "6007,928,6509,1430" in url_part or "6007,988,6509,1490" in url_part or "6007,928,6509,1430" in url_part or "5989,1127,6538,1675" in url_part:
                view_id = 1
            elif "5648,1004,6150,1506" in url_part or "5648,924,6150,1426" in url_part or "5648,1004,6150,1506" in url_part or "5648,924,6150,1426" in url_part or "5596,1165,6144,1714" in url_part:
                view_id = 2
            elif "5329,1033,5831,1535" in url_part or "5329,953,5831,1455" in url_part or "5329,1033,5831,1535" in url_part or "5329,953,5831,1455" in url_part or "5298,1167,5846,1715" in url_part:
                view_id = 3
            elif "4897,1034,5400,1537" in url_part or "4897,954,5400,1457" in url_part or "4897,1034,5400,1537" in url_part or "4897,954,5400,1457" in url_part or "4869,1126,5417,1674" in url_part:
                view_id = 4
            elif "4365,1074,4867,1576" in url_part or "4365,994,4867,1496" in url_part or "4365,1074,4867,1576" in url_part or "4365,994,4867,1496" in url_part or "4365,1130,4914,1678" in url_part:
                view_id = 5
            elif "3981,1084,4484,1587" in url_part or "3981,1004,4484,1507" in url_part or "3981,1084,4484,1587" in url_part or "3981,1004,4484,1507" in url_part or "3978,1166,4495,1683" in url_part:
                view_id = 6
            elif "3544,1009,4026,1491" in url_part or "3544,899,4026,1381" in url_part or "3544,1109,4026,1591" in url_part or "3544,899,4026,1381" in url_part or "3504,1067,4125,1688" in url_part:
                view_id = 7
            elif "3012,1145,3515,1648" in url_part or "3012,1045,3515,1548" in url_part or "3012,1145,3515,1648" in url_part or "3012,1045,3515,1548" in url_part or "3022,1135,3539,1652" in url_part:
                view_id = 8
            elif "3271,1116,3774,1619" in url_part or "3271,1016,3774,1519" in url_part or "3271,1116,3774,1619" in url_part or "3271,1016,3774,1519" in url_part or "3237,1143,3768,1674" in url_part:
                view_id = 9
            elif "2583,1111,3086,1614" in url_part or "2583,1011,3086,1514" in url_part or "2583,1211,3086,1714" in url_part or "2583,1011,3086,1514" in url_part or "2614,1123,3116,1625" in url_part:
                view_id = 10
            elif "2053,1123,2556,1626" in url_part or "2053,1023,2556,1526" in url_part or "2053,1173,2556,1676" in url_part or "2053,1023,2556,1526" in url_part or "2102,1101,2605,1603" in url_part:
                view_id = 11
            elif "1626,1115,2129,1618" in url_part or "1626,1015,2129,1518" in url_part or "1626,1265,2129,1768" in url_part or "1626,1015,2129,1518" in url_part or "1650,1074,2212,1636" in url_part:
                view_id = 12
            elif "1196,1135,1699,1638" in url_part or "1196,1035,1699,1538" in url_part or "1196,1205,1699,1708" in url_part or "1196,1035,1699,1538" in url_part or "1242,1084,1736,1578" in url_part:
                view_id = 13
            elif "763,1132,1265,1634" in url_part or "763,1032,1265,1534" in url_part or "763,1252,1265,1754" in url_part or "763,1032,1265,1534" in url_part or "814,1076,1308,1570" in url_part:
                view_id = 14
            file_name = file_name.replace("clairton1", str(camera_id) + "-" + str(view_id))
        elif "braddock1" in url_part:
            camera_id = 1
            if "3018,478,3536,996" in url_part:
                view_id = 0
            file_name = file_name.replace("braddock1", str(camera_id) + "-" + str(view_id))
        elif "westmifflin1" in url_part:
            camera_id = 2
            if "2617,1625,3124,2132" in url_part:
                view_id = 0
            elif "874,1602,1380,2108" in url_part:
                view_id = 1
            elif "488,1550,994,2056" in url_part:
                view_id = 2
            file_name = file_name.replace("westmifflin1", str(camera_id) + "-" + str(view_id))
        db.execute(video.update().where(video.c.id == b.id).values(camera_id=camera_id, view_id=view_id, file_name=file_name))
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('video', 'view_id')
    op.drop_column('video', 'camera_id')
    # ### end Alembic commands ###

"""add view and camera id

Revision ID: 8febec5ed501
Revises: <PASSWORD>
Create Date: 2019-10-02 16:57:08.630098

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '8febec5ed501'
down_revision = '<PASSWORD>'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('video', sa.Column('camera_id', sa.Integer(), nullable=False))
    op.add_column('video', sa.Column('view_id', sa.Integer(), nullable=False))
    db = op.get_bind()
    video = sa.sql.table('video', sa.sql.column('id'), sa.sql.column('camera_id'),
            sa.sql.column('view_id'), sa.sql.column('url_part'), sa.sql.column('file_name'))
    for b in db.execute(video.select()):
        #print("Update video id: " + str(b.id))
        url_part = b.url_part
        file_name = b.file_name
        camera_id = -1
        view_id = -1
        if "clairton1" in url_part:
            camera_id = 0
            if "6304,964,6807,1467" in url_part or "6304,884,6807,1387" in url_part or "6304,944,6807,1447" in url_part or "6304,884,6807,1387" in url_part or "6282,1154,6769,1641" in url_part:
                view_id = 0
            elif "6007,1008,6509,1510" in url_part or "6007,928,6509,1430" in url_part or "6007,988,6509,1490" in url_part or "6007,928,6509,1430" in url_part or "5989,1127,6538,1675" in url_part:
                view_id = 1
            elif "5648,1004,6150,1506" in url_part or "5648,924,6150,1426" in url_part or "5648,1004,6150,1506" in url_part or "5648,924,6150,1426" in url_part or "5596,1165,6144,1714" in url_part:
                view_id = 2
            elif "5329,1033,5831,1535" in url_part or "5329,953,5831,1455" in url_part or "5329,1033,5831,1535" in url_part or "5329,953,5831,1455" in url_part or "5298,1167,5846,1715" in url_part:
                view_id = 3
            elif "4897,1034,5400,1537" in url_part or "4897,954,5400,1457" in url_part or "4897,1034,5400,1537" in url_part or "4897,954,5400,1457" in url_part or "4869,1126,5417,1674" in url_part:
                view_id = 4
            elif "4365,1074,4867,1576" in url_part or "4365,994,4867,1496" in url_part or "4365,1074,4867,1576" in url_part or "4365,994,4867,1496" in url_part or "4365,1130,4914,1678" in url_part:
                view_id = 5
            elif "3981,1084,4484,1587" in url_part or "3981,1004,4484,1507" in url_part or "3981,1084,4484,1587" in url_part or "3981,1004,4484,1507" in url_part or "3978,1166,4495,1683" in url_part:
                view_id = 6
            elif "3544,1009,4026,1491" in url_part or "3544,899,4026,1381" in url_part or "3544,1109,4026,1591" in url_part or "3544,899,4026,1381" in url_part or "3504,1067,4125,1688" in url_part:
                view_id = 7
            elif "3012,1145,3515,1648" in url_part or "3012,1045,3515,1548" in url_part or "3012,1145,3515,1648" in url_part or "3012,1045,3515,1548" in url_part or "3022,1135,3539,1652" in url_part:
                view_id = 8
            elif "3271,1116,3774,1619" in url_part or "3271,1016,3774,1519" in url_part or "3271,1116,3774,1619" in url_part or "3271,1016,3774,1519" in url_part or "3237,1143,3768,1674" in url_part:
                view_id = 9
            elif "2583,1111,3086,1614" in url_part or "2583,1011,3086,1514" in url_part or "2583,1211,3086,1714" in url_part or "2583,1011,3086,1514" in url_part or "2614,1123,3116,1625" in url_part:
                view_id = 10
            elif "2053,1123,2556,1626" in url_part or "2053,1023,2556,1526" in url_part or "2053,1173,2556,1676" in url_part or "2053,1023,2556,1526" in url_part or "2102,1101,2605,1603" in url_part:
                view_id = 11
            elif "1626,1115,2129,1618" in url_part or "1626,1015,2129,1518" in url_part or "1626,1265,2129,1768" in url_part or "1626,1015,2129,1518" in url_part or "1650,1074,2212,1636" in url_part:
                view_id = 12
            elif "1196,1135,1699,1638" in url_part or "1196,1035,1699,1538" in url_part or "1196,1205,1699,1708" in url_part or "1196,1035,1699,1538" in url_part or "1242,1084,1736,1578" in url_part:
                view_id = 13
            elif "763,1132,1265,1634" in url_part or "763,1032,1265,1534" in url_part or "763,1252,1265,1754" in url_part or "763,1032,1265,1534" in url_part or "814,1076,1308,1570" in url_part:
                view_id = 14
            file_name = file_name.replace("clairton1", str(camera_id) + "-" + str(view_id))
        elif "braddock1" in url_part:
            camera_id = 1
            if "3018,478,3536,996" in url_part:
                view_id = 0
            file_name = file_name.replace("braddock1", str(camera_id) + "-" + str(view_id))
        elif "westmifflin1" in url_part:
            camera_id = 2
            if "2617,1625,3124,2132" in url_part:
                view_id = 0
            elif "874,1602,1380,2108" in url_part:
                view_id = 1
            elif "488,1550,994,2056" in url_part:
                view_id = 2
            file_name = file_name.replace("westmifflin1", str(camera_id) + "-" + str(view_id))
        db.execute(video.update().where(video.c.id == b.id).values(camera_id=camera_id, view_id=view_id, file_name=file_name))
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_column('video', 'view_id')
    op.drop_column('video', 'camera_id')
    # ### end Alembic commands ###

add view and camera id  Revision ID: 8febec5ed501 Revises: <PASSWORD> Create Date: 2019-10-02 16:57:08.630098 # revision identifiers, used by Alembic. # ### commands auto generated by Alembic - please adjust! ### #print("Update video id: " + str(b.id)) # ### end Alembic commands ### # ### commands auto generated by Alembic - please adjust! ### # ### end Alembic commands ###