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()
def upgrade(): op.add_column('battle', sa.Column('duration', sa.Integer, default=0, nullable=True)) # Parse battle duration from existing replay pickles for battle in Battle.query.all(): replay = battle.replay if replay and replay.replay_pickle: try: replay_data = replay.unpickle() pickle = replay_data['pickle'] battle.duration = int(pickle['common']['duration']) except Exception as e: print "Error parsing pickle of battle " + str(battle.id), e pass db_session.commit()
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()
if not replay['first'] or not replay['second']: print "Skipping incomplete replay " + file continue if not replays.is_cw(replay): print "Skipping non-CW-replay " + file continue date = datetime.datetime.strptime(replay['first']['dateTime'], '%d.%m.%Y %H:%M:%S') clan = replays.guess_clan(replay) enemy_clan = replays.guess_enemy_clan(replay) battle = Battle.query.filter_by(clan=clan, enemy_clan=enemy_clan, date=date).first() if not battle: print "Could not find matching battle for file " + file continue if battle.replay.replay_blob: print "Skipping battle " + str(battle.id) + " that already has a replay blob" continue battle.replay.replay_blob = replay_blob print "Adding replay " + file + " for battle " + str(battle.id) + " " + battle.enemy_clan db_session.add(battle.replay) db_session.commit() except Exception as e: print "Error processing " + file + " " + str(e)
replay = replays.parse_replay(replay_blob) if not replay['first'] or not replay['second']: print "Skipping incomplete replay " + file continue if not replays.is_cw(replay): print "Skipping non-CW-replay " + file continue date = datetime.datetime.strptime(replay['first']['dateTime'], '%d.%m.%Y %H:%M:%S') clan = replays.guess_clan(replay) enemy_clan = replays.guess_enemy_clan(replay) battle = Battle.query.filter_by(clan=clan, enemy_clan=enemy_clan, date=date).first() if not battle: print "Could not find matching battle for file " + file continue if battle.replay.replay_blob: print "Skipping battle " + str( battle.id) + " that already has a replay blob" continue battle.replay.replay_blob = replay_blob print "Adding replay " + file + " for battle " + str( battle.id) + " " + battle.enemy_clan db_session.add(battle.replay) db_session.commit() except Exception as e: print "Error processing " + file + " " + str(e)