Commit cd691561 authored by Amir Mohammadi's avatar Amir Mohammadi Committed by GitHub

Merge pull request #6 from bioidiap/refactoring_2016

Refactoring 2016
parents af4dcda7 6151d0e0
...@@ -19,32 +19,32 @@ ...@@ -19,32 +19,32 @@
"""Table models and functionality for the Mobio database. """Table models and functionality for the Mobio database.
""" """
import os, numpy
import bob.db.base.utils import bob.db.base.utils
from sqlalchemy import Table, Column, Integer, String, ForeignKey, or_, and_, not_ from sqlalchemy import Table, Column, Integer, String, ForeignKey
from bob.db.base.sqlalchemy_migration import Enum, relationship from bob.db.base.sqlalchemy_migration import Enum, relationship
from sqlalchemy.orm import backref from sqlalchemy.orm import backref
from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.ext.declarative import declarative_base
import bob.db.verification.utils import bob.db.base
Base = declarative_base() Base = declarative_base()
subworld_client_association = Table('subworld_client_association', Base.metadata, subworld_client_association = Table('subworld_client_association', Base.metadata,
Column('subworld_id', Integer, ForeignKey('subworld.id')), Column('subworld_id', Integer, ForeignKey('subworld.id')),
Column('client_id', Integer, ForeignKey('client.id'))) Column('client_id', Integer, ForeignKey('client.id')))
subworld_file_association = Table('subworld_file_association', Base.metadata, subworld_file_association = Table('subworld_file_association', Base.metadata,
Column('subworld_id', Integer, ForeignKey('subworld.id')), Column('subworld_id', Integer, ForeignKey('subworld.id')),
Column('file_id', Integer, ForeignKey('file.id'))) Column('file_id', Integer, ForeignKey('file.id')))
tmodel_file_association = Table('tmodel_file_association', Base.metadata, tmodel_file_association = Table('tmodel_file_association', Base.metadata,
Column('tmodel_id', String, ForeignKey('tmodel.id')), Column('tmodel_id', String, ForeignKey('tmodel.id')),
Column('file_id', Integer, ForeignKey('file.id'))) Column('file_id', Integer, ForeignKey('file.id')))
protocolPurpose_file_association = Table('protocolPurpose_file_association', Base.metadata, protocolPurpose_file_association = Table('protocolPurpose_file_association', Base.metadata,
Column('protocolPurpose_id', Integer, ForeignKey('protocolPurpose.id')), Column('protocolPurpose_id', Integer, ForeignKey('protocolPurpose.id')),
Column('file_id', Integer, ForeignKey('file.id'))) Column('file_id', Integer, ForeignKey('file.id')))
class Client(Base): class Client(Base):
"""Database clients, marked by an integer identifier and the group they belong to""" """Database clients, marked by an integer identifier and the group they belong to"""
...@@ -54,11 +54,11 @@ class Client(Base): ...@@ -54,11 +54,11 @@ class Client(Base):
# Key identifier for the client # Key identifier for the client
id = Column(Integer, primary_key=True) id = Column(Integer, primary_key=True)
# Gender to which the client belongs to # Gender to which the client belongs to
gender_choices = ('female','male') gender_choices = ('female', 'male')
gender = Column(Enum(*gender_choices)) gender = Column(Enum(*gender_choices))
# Group to which the client belongs to # Group to which the client belongs to
group_choices = ('dev','eval','world') group_choices = ('dev', 'eval', 'world')
sgroup = Column(Enum(*group_choices)) # do NOT use group (SQL keyword) sgroup = Column(Enum(*group_choices)) # do NOT use group (SQL keyword)
# Institute to which the client belongs to # Institute to which the client belongs to
institute_choices = ('idiap', 'manchester', 'surrey', 'oulu', 'brno', 'avignon') institute_choices = ('idiap', 'manchester', 'surrey', 'oulu', 'brno', 'avignon')
institute = Column(Enum(*institute_choices)) institute = Column(Enum(*institute_choices))
...@@ -72,6 +72,7 @@ class Client(Base): ...@@ -72,6 +72,7 @@ class Client(Base):
def __repr__(self): def __repr__(self):
return "Client('%d', '%s')" % (self.id, self.sgroup) return "Client('%d', '%s')" % (self.id, self.sgroup)
class Subworld(Base): class Subworld(Base):
"""Database clients belonging to the world group are split in subsets""" """Database clients belonging to the world group are split in subsets"""
...@@ -93,6 +94,7 @@ class Subworld(Base): ...@@ -93,6 +94,7 @@ class Subworld(Base):
def __repr__(self): def __repr__(self):
return "Subworld('%s')" % (self.name) return "Subworld('%s')" % (self.name)
class TModel(Base): class TModel(Base):
"""T-Norm models""" """T-Norm models"""
...@@ -102,8 +104,8 @@ class TModel(Base): ...@@ -102,8 +104,8 @@ class TModel(Base):
id = Column(Integer, primary_key=True) id = Column(Integer, primary_key=True)
# Model id (only unique for a given protocol) # Model id (only unique for a given protocol)
mid = Column(String(9)) mid = Column(String(9))
client_id = Column(Integer, ForeignKey('client.id')) # for SQL client_id = Column(Integer, ForeignKey('client.id')) # for SQL
protocol_id = Column(Integer, ForeignKey('protocol.id')) # for SQL protocol_id = Column(Integer, ForeignKey('protocol.id')) # for SQL
# for Python: A direct link to the client # for Python: A direct link to the client
client = relationship("Client", backref=backref("tmodels", order_by=id)) client = relationship("Client", backref=backref("tmodels", order_by=id))
...@@ -120,7 +122,8 @@ class TModel(Base): ...@@ -120,7 +122,8 @@ class TModel(Base):
def __repr__(self): def __repr__(self):
return "TModel('%s', '%s')" % (self.mid, self.protocol_id) return "TModel('%s', '%s')" % (self.mid, self.protocol_id)
class File(Base, bob.db.verification.utils.File):
class File(Base, bob.db.base.File):
"""Generic file container""" """Generic file container"""
__tablename__ = 'file' __tablename__ = 'file'
...@@ -128,13 +131,13 @@ class File(Base, bob.db.verification.utils.File): ...@@ -128,13 +131,13 @@ class File(Base, bob.db.verification.utils.File):
# Key identifier for the file # Key identifier for the file
id = Column(Integer, primary_key=True) id = Column(Integer, primary_key=True)
# Key identifier of the client associated with this file # Key identifier of the client associated with this file
client_id = Column(Integer, ForeignKey('client.id')) # for SQL client_id = Column(Integer, ForeignKey('client.id')) # for SQL
# Unique path to this file inside the database # Unique path to this file inside the database
path = Column(String(100), unique=True) path = Column(String(100), unique=True)
# Identifier of the session # Identifier of the session
session_id = Column(Integer) session_id = Column(Integer)
# Speech type # Speech type
speech_type_choices = ('p','l','r','f') speech_type_choices = ('p', 'l', 'r', 'f')
speech_type = Column(Enum(*speech_type_choices)) speech_type = Column(Enum(*speech_type_choices))
# Identifier of the shot # Identifier of the shot
shot_id = Column(Integer) shot_id = Column(Integer)
...@@ -152,7 +155,7 @@ class File(Base, bob.db.verification.utils.File): ...@@ -152,7 +155,7 @@ class File(Base, bob.db.verification.utils.File):
def __init__(self, client_id, path, session_id, speech_type, shot_id, environment, device, channel_id): def __init__(self, client_id, path, session_id, speech_type, shot_id, environment, device, channel_id):
# call base class constructor # call base class constructor
bob.db.verification.utils.File.__init__(self, client_id = client_id, path = path) bob.db.base.File.__init__(self, client_id=client_id, path=path)
# fill the remaining bits of the file information # fill the remaining bits of the file information
self.session_id = session_id self.session_id = session_id
...@@ -162,6 +165,7 @@ class File(Base, bob.db.verification.utils.File): ...@@ -162,6 +165,7 @@ class File(Base, bob.db.verification.utils.File):
self.device = device self.device = device
self.channel_id = channel_id self.channel_id = channel_id
class Protocol(Base): class Protocol(Base):
"""MOBIO protocols""" """MOBIO protocols"""
...@@ -171,7 +175,7 @@ class Protocol(Base): ...@@ -171,7 +175,7 @@ class Protocol(Base):
id = Column(Integer, primary_key=True) id = Column(Integer, primary_key=True)
# Name of the protocol associated with this object # Name of the protocol associated with this object
name = Column(String(20), unique=True) name = Column(String(20), unique=True)
gender_choices = ('female','male') gender_choices = ('female', 'male')
gender = Column(Enum(*gender_choices)) gender = Column(Enum(*gender_choices))
def __init__(self, name, gender): def __init__(self, name, gender):
...@@ -181,6 +185,7 @@ class Protocol(Base): ...@@ -181,6 +185,7 @@ class Protocol(Base):
def __repr__(self): def __repr__(self):
return "Protocol('%s','%s')" % (self.name, self.gender) return "Protocol('%s','%s')" % (self.name, self.gender)
class ProtocolPurpose(Base): class ProtocolPurpose(Base):
"""MOBIO protocol purposes""" """MOBIO protocol purposes"""
...@@ -189,7 +194,7 @@ class ProtocolPurpose(Base): ...@@ -189,7 +194,7 @@ class ProtocolPurpose(Base):
# Unique identifier for this protocol purpose object # Unique identifier for this protocol purpose object
id = Column(Integer, primary_key=True) id = Column(Integer, primary_key=True)
# Id of the protocol associated with this protocol purpose object # Id of the protocol associated with this protocol purpose object
protocol_id = Column(Integer, ForeignKey('protocol.id')) # for SQL protocol_id = Column(Integer, ForeignKey('protocol.id')) # for SQL
# Group associated with this protocol purpose object # Group associated with this protocol purpose object
group_choices = Client.group_choices group_choices = Client.group_choices
sgroup = Column(Enum(*group_choices)) sgroup = Column(Enum(*group_choices))
......
This diff is collapsed.
...@@ -13,7 +13,6 @@ develop = src/bob.extension ...@@ -13,7 +13,6 @@ develop = src/bob.extension
src/bob.core src/bob.core
src/bob.io.base src/bob.io.base
src/bob.db.base src/bob.db.base
src/bob.db.verification.utils
. .
; options for bob.buildout extension ; options for bob.buildout extension
...@@ -27,7 +26,6 @@ bob.blitz = git https://github.com/bioidiap/bob.blitz ...@@ -27,7 +26,6 @@ bob.blitz = git https://github.com/bioidiap/bob.blitz
bob.core = git https://github.com/bioidiap/bob.core bob.core = git https://github.com/bioidiap/bob.core
bob.io.base = git https://github.com/bioidiap/bob.io.base bob.io.base = git https://github.com/bioidiap/bob.io.base
bob.db.base = git https://github.com/bioidiap/bob.db.base bob.db.base = git https://github.com/bioidiap/bob.db.base
bob.db.verification.utils = git https://github.com/bioidiap/bob.db.verification.utils
[scripts] [scripts]
recipe = bob.buildout:scripts recipe = bob.buildout:scripts
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment