<s> revision = '<STR_LIT>' <EOL> down_revision = '<STR_LIT:5>' <EOL> from alembic import op <EOL> import sqlalchemy as sa <EOL> from sqlalchemy . ext . declarative import declarative_base <EOL> from sqlalchemy . orm import sessionmaker <EOL> import json <EOL> def upgrade ( ) : <EOL> op . add_column ( '<STR_LIT>' , sa . Column ( '<STR_LIT>' , sa . Float ( ) , nullable = True ) ) <EOL> changeActivity ( old = '<STR_LIT>' , new = '<STR_LIT>' ) <EOL> def downgrade ( ) : <EOL> op . drop_column ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def changeActivity ( old , new ) : <EOL> Base = declarative_base ( ) <EOL> Session = sessionmaker ( bind = op . get_bind ( ) ) <EOL> class Move ( Base ) : <EOL> __tablename__ = '<STR_LIT>' <EOL> id = sa . Column ( sa . Integer , name = "<STR_LIT:id>" , primary_key = True ) <EOL> activity = sa . Column ( sa . String , name = "<STR_LIT>" ) <EOL> strokeCount = sa . Column ( sa . Integer , name = '<STR_LIT>' ) <EOL> class Sample ( Base ) : <EOL> __tablename__ = '<STR_LIT>' <EOL> id = sa . Column ( sa . Integer , name = "<STR_LIT:id>" , primary_key = True ) <EOL> moveId = sa . Column ( sa . Integer , sa . ForeignKey ( Move . id ) , name = "<STR_LIT>" , nullable = False ) <EOL> move = sa . orm . relationship ( Move , backref = sa . orm . backref ( '<STR_LIT>' , lazy = '<STR_LIT>' ) ) <EOL> events = sa . Column ( sa . String , name = '<STR_LIT>' ) <EOL> session = Session ( ) <EOL> for move in session . query ( Move ) : <EOL> strokeCount = <NUM_LIT:0> <EOL> for eventData , in session . query ( Sample . events ) . filter ( Sample . move == move , Sample . events != None ) : <EOL> events = json . loads ( eventData ) <EOL> if '<STR_LIT>' in events and events [ '<STR_LIT>' ] [ '<STR_LIT:type>' ] == '<STR_LIT>' : <EOL> strokeCount += <NUM_LIT:1> <EOL> if '<STR_LIT>' in move . activity : <EOL> assert strokeCount > <NUM_LIT:0> <EOL> if strokeCount > <NUM_LIT:0> : <EOL> move . strokeCount = strokeCount <EOL> session . commit ( ) </s>
