Commit b590fed2 authored by Manuel Günther's avatar Manuel Günther
Browse files

Improved FileSet object

parent 87811a90
......@@ -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
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):
......@@ -28,9 +28,10 @@ class FileSetDatabase (DatabaseBobZT):
# 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
......
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