Commit e791ba4f authored by Guillaume HEUSCH's avatar Guillaume HEUSCH
Browse files

improved docstrings in query.py

parent 402a7416
......@@ -12,6 +12,22 @@ SQLITE_FILE = INFO.files()[0]
import bob.db.base
class Database(bob.db.base.SQLiteDatabase):
""" Class representing the database
See parent class `:py:class:bob.db.base.SQLiteDatabase` for more details ...
Attributes
----------
original_directory: str
Path where the database is stored
original_extension: str
Extension of files in the database
annotation_directory: str
Path where the annotations are stored
annotation_extension: str
Extension of anootation files
"""
def __init__(self,
original_directory=None,
......@@ -19,37 +35,55 @@ class Database(bob.db.base.SQLiteDatabase):
annotation_directory=None,
annotation_extension=None,
protocol='mc-rgb'):
super(Database, self).__init__(SQLITE_FILE, File, original_directory, original_extension)
""" Init function
Parameters
----------
original_directory: str
Path where the database is stored
original_extension: str
Extension of files in the database
annotation_directory: str
Path where the annotations are stored
annotation_extension: str
Extension of anootation files
"""
super(Database, self).__init__(SQLITE_FILE, File, original_directory, original_extension)
self.annotation_directory = annotation_directory
self.annotation_extension = annotation_extension
self.protocol = protocol
def groups(self, protocol=None):
"""Returns the names of all registered groups"""
"""Returns the names of all registered groups
Parameters
----------
protocol: str
ignored, since the group are the same across protocols.
"""
return ProtocolPurpose.group_choices
def clients(self, protocol=None, groups=None):
"""Returns a set of clients for the specific query by the user.
Keyword Parameters:
protocol
Parameters
----------
protocol: str
Ignored since the clients are identical for all protocols.
groups
groups: str or tuple of str
The groups to which the clients belong ('world', 'dev', 'eval').
Returns: A list containing all the clients which have the given properties.
Returns:
lst:
list containing clients which have the given properties.
"""
groups = self.check_parameters_for_validity(groups, "group", self.groups())
retval = []
# List of the clients
if "world" in groups:
q = self.query(Client).filter(Client.group == 'world')
retval += list(q)
......@@ -59,90 +93,112 @@ class Database(bob.db.base.SQLiteDatabase):
if 'eval' in groups:
q = self.query(Client).filter(Client.group == 'eval')
retval += list(q)
return retval
def models(self, protocol=None, groups=None):
"""Returns a set of models for the specific query by the user.
Keyword Parameters:
Parameters
----------
protocol
Ignored since the models are identical for all protocols.
groups
The groups to which the subjects attached to the models belong
Returns: A list containing all the models which have the given properties.
Returns
-------
lst:
A list containing all the models which have the given properties.
"""
return self.clients(protocol, groups)
def model_ids(self, protocol=None, groups=None):
"""Returns a set of models ids for the specific query by the user.
Keyword Parameters:
Parameters
----------
protocol
Ignored since the models are identical for all protocols.
groups
The groups to which the subjects attached to the models belong ('g1', 'g2', 'world')
Note that 'dev' is an alias to 'g1' and 'eval' an alias to 'g2'
The groups to which the subjects attached to the models belong
Returns: A list containing all the models ids which have the given properties.
Returns
-------
lst:
A list containing all the models ids which have the given properties.
"""
return [model.id for model in self.models(protocol, groups)]
def client(self, id):
"""Returns the client object in the database given a certain id. Raises
an error if that does not exist."""
def client(self, id):
"""Returns the client object of the specified id.
Parameters
----------
id: int
The client id.
Raises
------
Error:
if the client does not exist.
"""
return self.query(Client).filter(Client.id == id).one()
def protocol_names(self):
"""Returns all registered protocol names"""
"""Returns all registered protocol names
"""
l = self.protocols()
retval = [str(k.name) for k in l]
return retval
def protocols(self):
"""Returns all registered protocols"""
def protocols(self):
"""Returns all registered protocols
"""
return list(self.query(Protocol))
def purposes(self):
"""Returns purposes
"""
return ProtocolPurpose.purpose_choices
def objects(self, protocol=None, purposes=None, model_ids=None, groups=None):
"""Returns a set of Files for the specific query by the user.
Keyword Parameters:
protocol
Parameters
----------
protocol: str
One of the FARGO protocols.
purposes
purposes: str or tuple of str
The purposes required to be retrieved ('enroll', 'probe', 'train') or a tuple
with several of them. If 'None' is given (this is the default), it is
considered the same as a tuple with all possible values. This field is
ignored for the data from the "world" group.
model_ids
Only retrieves the files for the provided list of model ids (claimed
client id). If 'None' is given (this is the default), no filter over
the model_ids is performed.
groups
model_ids: int or tuple of int
Only retrieves the files for the provided list of model ids.
If 'None' is given, no filter over the model_ids is performed.
groups: str or tuple of str
One of the groups ('dev', 'eval', 'world') or a tuple with several of them.
If 'None' is given (this is the default), it is considered the same as a
tuple with all possible values.
Returns: A list of files which have the given properties.
Returns
-------
lst:
A list of files which have the given properties.
"""
#print("Protocol = {}, purpose = {}, model_ids = {}, groups = {}".format(protocol, purposes, model_ids, groups))
from sqlalchemy import and_
protocol = self.check_parameters_for_validity(protocol, "protocol", self.protocol_names())
......@@ -183,4 +239,3 @@ class Database(bob.db.base.SQLiteDatabase):
retval += list(q)
return list(set(retval)) # To remove duplicates
Supports Markdown
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