Skip to content

Commit

Permalink
Improved FileSet object
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Guenther committed Jun 25, 2015
1 parent 87811a9 commit b590fed
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 22 deletions.
32 changes: 13 additions & 19 deletions bob/bio/base/database/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,36 +40,30 @@ class FileSet:
Use this class, whenever the database provides several files that belong to the same probe.
Each file set has an id, an associated client (aka. identity, person, user), and a list of associated files.
Usually, these files are part of a database, which has a common directory for all files.
The paths of this file set are usually *relative* to that common directory, and they are usually stored *without* filename extension.
The file id can be anything hashable, but needs to be unique all over the database.
The client id can be anything hashable, but needs to be identical for different files of the same client, and different between clients.
Each file set has an id, and a list of associated files, which are of type :py:class:`File` of the same client.
The file set id can be anything hashable, but needs to be unique all over the database.
**Parameters:**
file_id : str or int
A unique ID that identifies the file.
This ID might be identical to the ``path``, though integral IDs perform faster.
client_id : str or int
A unique ID that identifies the client (user) to which this file belongs.
This ID might be the name of the person, though integral IDs perform faster.
file_set_id : str or int
A unique ID that identifies the file set.
path : str
The file path of the file, which is relative to the common database directory, and without filename extension.
files : [:py:class:`File`]
A list of File objects that should be stored inside this file.
All files of that list need to have the same client ID.
"""

def __init__(self, file_set_id, client_id, file_set_name):
def __init__(self, file_set_id, files, path=None):
# The **unique** id of the file set
self.id = file_set_id
# The id of the client that is attached to the file
self.client_id = client_id
# A name of the file set
self.path = file_set_name
assert len(files)
self.client_id = files[0].client_id
assert all(f.client_id == self.client_id for f in files)
# The list of files contained in this set
self.files = []
self.files = files

def __lt__(self, other):
"""Defines an order between file sets by using the order of the file set ids."""
# compare two File set objects by comparing their IDs
return self.id < other.id
7 changes: 4 additions & 3 deletions bob/bio/base/test/dummy/fileset.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import bob.db.atnt
import os

from bob.bio.base.database import DatabaseBob, DatabaseBobZT, FileSet
from bob.bio.base.database import DatabaseBob, DatabaseBobZT, File, FileSet
from bob.bio.base.test.utils import atnt_database_directory

class FileSetDatabase (DatabaseBobZT):
Expand All @@ -28,9 +28,10 @@ def probe_file_sets(self, model_id = None, group = 'dev'):
# arrange files by clients
file_sets = []
for client_files in files:
# convert into our File objects (so that they are tested as well)
our_files = [File(f.id, f.client_id, f.path) for f in client_files]
# generate file set for each client
file_set = FileSet(client_files[0].client_id, client_files[0].client_id, client_files[0].path)
file_set.files = client_files
file_set = FileSet(our_files[0].client_id, our_files)
file_sets.append(file_set)
return file_sets

Expand Down

0 comments on commit b590fed

Please sign in to comment.