# Path: whyattend/model.py
# def init_db():
#     def __init__(self, wot_id, openid, member_since, name, clan, role, locked=False):
#     def is_recruit(self):
#     def battles_played(self):
#     def battles_reserve(self):
#     def __repr__(self):
#     def to_dict(self):
#     def player_role_value(self):
#     def __init__(self, player, battle, reserve=False):
#     def __init__(self, date, clan, enemy_clan, victory, draw, creator, battle_commander, map_name, map_province,
#                  duration, description='', paid=False):
#     def outcome_str(self):
#     def outcome_repr(self):
#     def has_player(self, player):
#     def has_reserve(self, player):
#     def get_players(self):
#     def get_reserve_players(self):
#     def __str__(self):
#     def __init__(self, title, description, clan, date):
#     def get_players(self):
#     def get_reserves(self):
#     def get_final_battle(self):
#     def get_representative_battle(self):
#     def __init__(self, replay_blob, replay_pickle):
#     def unpickle(self):
#     def get(cls):
# class Player(Base):
# class BattleAttendance(Base):
# class Battle(Base):
# class BattleGroup(Base):
# class Replay(Base):
# class WebappData(Base):
# 
# Path: whyattend/replays.py
# def parse_replay(replay_blob):
# def players_list(replay_json, team):
# def player_won(replay_json):
# def get_own_team(replay_json):
# def player_team(replay_json):
# def is_stronghold(replay_json):
# def is_cw(replay_json):
# def guess_clan(replay_json):
# def guess_enemy_clan(replay_json):
# def score(replay_json):
# def resources_earned(json_second, player_id):
# def player_performance(json_second, vehicles, players):


from alembic import op
from whyattend.model import Base, Battle, db_session
from whyattend import replays
import sqlalchemy as sa
"""Tank scores for battles

Revision ID: 37000801b290
Revises: 533b503ed449
Create Date: 2014-05-06 21:03:28.609214

"""

# revision identifiers, used by Alembic.
revision = '37000801b290'
down_revision = '533b503ed449'


Base.metadata.bind = op.get_bind()


def upgrade():
    op.add_column('battle', sa.Column('score_enemy_team', sa.Integer(), nullable=True))
    op.add_column('battle', sa.Column('score_own_team', sa.Integer(), nullable=True))
    for battle in Battle.query.all():
        replay = battle.replay
        if replay and replay.replay_pickle:
            try:
                battle.score_own_team, battle.score_enemy_team = replays.score(replay.unpickle())
            except Exception as e:
                print "Error parsing pickle of battle " + str(battle.id), e
                pass

# Path: whyattend/model.py
# def init_db():
#     def __init__(self, wot_id, openid, member_since, name, clan, role, locked=False):
#     def is_recruit(self):
#     def battles_played(self):
#     def battles_reserve(self):
#     def __repr__(self):
#     def to_dict(self):
#     def player_role_value(self):
#     def __init__(self, player, battle, reserve=False):
#     def __init__(self, date, clan, enemy_clan, victory, draw, creator, battle_commander, map_name, map_province,
#                  duration, description='', paid=False):
#     def outcome_str(self):
#     def outcome_repr(self):
#     def has_player(self, player):
#     def has_reserve(self, player):
#     def get_players(self):
#     def get_reserve_players(self):
#     def __str__(self):
#     def __init__(self, title, description, clan, date):
#     def get_players(self):
#     def get_reserves(self):
#     def get_final_battle(self):
#     def get_representative_battle(self):
#     def __init__(self, replay_blob, replay_pickle):
#     def unpickle(self):
#     def get(cls):
# class Player(Base):
# class BattleAttendance(Base):
# class Battle(Base):
# class BattleGroup(Base):
# class Replay(Base):
# class WebappData(Base):
# 
# Path: whyattend/replays.py
# def parse_replay(replay_blob):
# def players_list(replay_json, team):
# def player_won(replay_json):
# def get_own_team(replay_json):
# def player_team(replay_json):
# def is_stronghold(replay_json):
# def is_cw(replay_json):
# def guess_clan(replay_json):
# def guess_enemy_clan(replay_json):
# def score(replay_json):
# def resources_earned(json_second, player_id):
# def player_performance(json_second, vehicles, players):


# Path: whyattend/alembic/versions/37000801b290_tank_scores_for_battles.py
from alembic import op
from whyattend.model import Base, Battle, db_session
from whyattend import replays
import sqlalchemy as sa

"""Tank scores for battles

Revision ID: 37000801b290
Revises: 533b503ed449
Create Date: 2014-05-06 21:03:28.609214

"""

# revision identifiers, used by Alembic.
revision = '37000801b290'
down_revision = '533b503ed449'


Base.metadata.bind = op.get_bind()


def upgrade():
    op.add_column('battle', sa.Column('score_enemy_team', sa.Integer(), nullable=True))
    op.add_column('battle', sa.Column('score_own_team', sa.Integer(), nullable=True))
    for battle in Battle.query.all():
        replay = battle.replay
        if replay and replay.replay_pickle:
            try:
                battle.score_own_team, battle.score_enemy_team = replays.score(replay.unpickle())
            except Exception as e:
                print "Error parsing pickle of battle " + str(battle.id), e
                pass

    db_session.commit()