<s> import random <EOL> import struct <EOL> import datetime <EOL> from flask . ext . sqlalchemy import SQLAlchemy <EOL> from sqlalchemy import Column , String , Text , Integer , Float , DateTime , Boolean , ForeignKey , create_engine , types <EOL> from sqlalchemy . orm import sessionmaker , relationship <EOL> from sqlalchemy . ext . declarative import declarative_base <EOL> from sqlalchemy . dialects . mysql . base import MSBinary <EOL> db = SQLAlchemy ( ) <EOL> class UUID ( types . TypeDecorator ) : <EOL> impl = MSBinary <EOL> def __init__ ( self ) : <EOL> self . impl . length = <NUM_LIT:16> <EOL> types . TypeDecorator . __init__ ( self , length = self . impl . length ) <EOL> def process_bind_param ( self , value , dialect = None ) : <EOL> if value is not None : <EOL> value = int ( value ) <EOL> return struct . pack ( '<STR_LIT>' , ( value >> <NUM_LIT:64> ) , value & ( ( <NUM_LIT:1> << <NUM_LIT:64> ) - <NUM_LIT:1> ) ) <EOL> else : <EOL> return None <EOL> def process_result_value ( self , value , dialect = None ) : <EOL> if value : <EOL> ( upper , lower ) = struct . unpack ( '<STR_LIT>' , value ) <EOL> return ( upper << <NUM_LIT:64> ) | lower <EOL> else : <EOL> return None <EOL> def is_mutable ( self ) : <EOL> return False <EOL> class User ( db . Model ) : <EOL> __tablename__ = '<STR_LIT:user>' <EOL> id = Column ( UUID , primary_key = True ) <EOL> email = Column ( String ( <NUM_LIT> ) ) <EOL> name = Column ( String ( <NUM_LIT> ) ) <EOL> avatar = Column ( String ( <NUM_LIT> ) ) <EOL> transcriptions = relationship ( '<STR_LIT>' , backref = "<STR_LIT:user>" ) <EOL> admin = Column ( Boolean ) <EOL> def is_authenticated ( self ) : <EOL> return True <EOL> def is_active ( self ) : <EOL> return True <EOL> def is_anonymous ( self ) : <EOL> return False <EOL> def get_id ( self ) : <EOL> return unicode ( self . id ) <EOL> class WorkerType ( db . Model ) : <EOL> __tablename__ = '<STR_LIT>' <EOL> id = Column ( String ( <NUM_LIT:32> ) , primary_key = True ) <EOL> lang = Column ( String ( <NUM_LIT:10> ) ) <EOL> name = Column ( String ( <NUM_LIT> ) ) <EOL> description = Column ( Text ) <EOL> visible = Column ( Boolean , default = False ) <EOL> language_models = relationship ( '<STR_LIT>' ) <EOL> recordings = relationship ( '<STR_LIT>' ) <EOL> class LanguageModel ( db . Model ) : <EOL> __tablename__ = '<STR_LIT>' <EOL> id = Column ( Integer , primary_key = True ) <EOL> key = Column ( String ( <NUM_LIT:32> ) ) <EOL> name = Column ( String ( <NUM_LIT:32> ) ) <EOL> worker_type = Column ( String ( <NUM_LIT:32> ) , ForeignKey ( '<STR_LIT>' ) ) <EOL> class Recording ( db . Model ) : <EOL> __tablename__ = '<STR_LIT>' <EOL> id = Column ( UUID , primary_key = True ) <EOL> uuid = Column ( UUID ) <EOL> part = Column ( Integer ) <EOL> model = Column ( String ( <NUM_LIT:32> ) , ForeignKey ( '<STR_LIT>' ) ) <EOL> path = Column ( String ( <NUM_LIT> ) ) <EOL> url = Column ( String ( <NUM_LIT> ) ) <EOL> best_transcription = Column ( Text ) <EOL> score = Column ( Float ) <EOL> created = Column ( DateTime , default = datetime . datetime . utcnow ) <EOL> hypotheses = relationship ( '<STR_LIT>' ) <EOL> transcriptions = relationship ( '<STR_LIT>' ) <EOL> class Hypothesis ( db . Model ) : <EOL> __tablename__ = '<STR_LIT>' <EOL> id = Column ( Integer , primary_key = True ) <EOL> recording_id = Column ( UUID , ForeignKey ( '<STR_LIT>' ) ) <EOL> text = Column ( Text ) <EOL> confidence = Column ( Float ) <EOL> class Transcription ( db . Model ) : <EOL> __tablename__ = '<STR_LIT>' <EOL> id = Column ( Integer , primary_key = True ) <EOL> recording_id = Column ( UUID , ForeignKey ( '<STR_LIT>' ) ) <EOL> user_id = Column ( UUID , ForeignKey ( '<STR_LIT>' ) , nullable = True ) <EOL> text = Column ( Text ) <EOL> created = Column ( DateTime , default = datetime . datetime . utcnow ) <EOL> has_been_played = Column ( Boolean ) <EOL> native_speaker = Column ( Boolean ) <EOL> offensive_language = Column ( Boolean ) <EOL> not_a_speech = Column ( Boolean ) </s>
