Skip to content

CLI | cli interface

ewolio edited this page Feb 20, 2020 · 26 revisions

Most functionalities of the CLI are accessible through the cli object and the modules it contains:

Each of this module is an EntityTable.


Users

The cli.users interface (singleton of UserTable) allows to list, create, modify and delete users from the table user of the database.

UserTable

Methods:

  • cli.users.create(firstname, lastname, email, password, is_admin=False)

    Add a user to the database. This operation needs administrator privilege.

    Parameters:
    • firstname [str]: User's first name.
    • lastname [str]: User's last name.
    • email [str]: User's email. It's also the ID used by the user to authenticate to the server.
    • password [str]: User's password. As of now, the CLI doesn't encrypt the password.
    • is_admin [bool]: Set the role of the user (deprecated since more role have been added).
    Return:

    The created user as an User object.

  • cli.users[id]

    Fetch one or several users from the database. Alternatively you can use cli.users.getById(id).

    Parameters:
    • id [int, list(int)]: A user id or a list of users id.
    Return:

    A User entity if id is an int, or a EntityList(User) if ìd is a list.

  • cli.users.save(entity)

    Update a user of the database. Alternatively, you may call entity.save(). This operation needs administrator privilege.

    Parameters:
    • entity [User]: The modified User object to save in the database.
  • cli.users.delete(entities)

    Remove a user from the database. This operation need administrator privilege.

    Parameters:
    • entities [int|User]: The user to delete or its id.
    Return:

    The deleted user as an User object.

  • cli.users.list()

    List all users contained in the table user of the database.

    Return:

    The user list as an EntityList(User) object.

User entity

A User object represents a single entity from the user table of the database.

Attributes:

  • id [int]: The index (and primary key) of the user.
  • email [str]: The user's email. It's also the id used to authenticate the user.
  • firstName [str]: The user's first name.
  • lastName [str]: The user's last name.
  • isAdmin [bool]: The user's role. (Deprecated since more role have been added.)
  • Inherited attributes from Entity

Methods:


Images

The cli.images interface (singleton of ImageTable) allows to list, upload, modify, download and delete images from the table image of the database.

ImageTable

Methods

  • cli.images.create(path, type, metadata=None, preprocessing=None)

    Upload an image (and optionally its preprocessing) and add an image entry to the database. This operation needs administrator privilege. This operation may take some time since after the image uploaded, it will be converted to jpeg if needed and a thumbnail will be computed.

    Parameters:
    • path [str]: Path to the image file to upload.
    • type [str]: The acquisition type (fundus, OCT...).
    • metadata [dict]: Optional metadata passed along the images. The original name of the image and its preprocessing are automatically stored in metadata['filename'] and metadata['preprocessingFilename'].
    • preprocessing [str]: Path to the preprocessed image to upload. If None, no preprocessing is associated with this image.
    Return:

    The created user as an Image object.

  • cli.images.save(entity)

    Update an image of the database. Alternatively, you may call image.save(). Uploading a new image or preprocessing is not yet implemented in the CLI. This operation needs administrator privilege.

    Parameters:
    • entity [Image]: The modified image to save in the database.
  • cli.images.delete(entities)

    Remove an image from the database. This operation need administrator privilege.

    Parameters:
    • entities [int|Image]: The image to delete or its id.
    Return:

    The deleted image as an Image object.

  • cli.images.list()

    List all images contained in the table image of the database.

    Return:

    The image list as an EntityList(Image) object.

Image entity

An Image object represents a single entity from the image table of the database.

Attributes:

  • id [int]: The index (and primary key) of the image.
  • preprocessing [bool]: True if a preprocessing image is associated with this entity.
  • metadata [dict]: The image metadata.
  • type [str]: The image acquisition type.
  • Inherited attributes from Entity

Methods:

  • image.download_image(out=None)

    Download the image file.

    Parameters:
    • out [str]: Path where the file will be written. (If none is passed the file is not stored on the disk).
    Return:

    The image as an array numpy. (Dimensions are [height, width, channel], channels are in BGR order).

  • image.download_preprocessing(out=None)

    Download the preprocessed image file.

    Parameters:
    • out [str]: Path where the file will be written. (If none is passed the file is not stored on the disk).
    Return:

    The preprocessed image as an array numpy. (Dimensions are [height, width, channel], channels are in BGR order).


Annotations

The cli.annotations interface (singleton of AnnotationTable) allows to add, list, modify, download and delete annotations from the table annotation of the database.

AnnotationTable

Methods

  • cli.annotations.create(image, comment=None, data=None)

    Create an annotation.

    Parameters:
    • image [int|Image]: Id of the image or Image entity to which the annotation is linked.
    • comment [str]: Comment stored along with the annotation.
    • data [AnnotationData]: The graphical and non-graphical annotation data.
    Return:

    The created annotation as an Annotation object.

  • cli.annotations.save(entity)

    Update an annotation of the database. Alternatively, you may call entity.save(). A submit event is automatically generated in the database. This operation needs administrator privilege.

    Parameters:
    • entity [Annotation]: The modified annotation to save in the database.
  • cli.annotations.list()

    List all annotations contained in the annotation table of the database.

    Return:

    The annotation list as an EntityList(Annotation) object.

Annotation entity

An Annotation object represents a single entity from the annotation table of the database.

Attributes:

  • id [int]: The index (and primary key) of the annotation.
  • comment [str]: Comment associated with the annotation. This comment is not visible from the frontend, it should be used as note created by and for the research team.
  • image [Image]: The image to which this annotation is linked. Read-only
  • submitEvent [SubmissionEvent]: The last submission event. Read-only
  • Inherited attributes from Entity

Methods:

AnnotationData class

Attributes

  • biomarkers [dict]: A dictionary containing the graphical annotation. The key encode the biomarker name and the value is a string containing a bitmap (png in base64 format) or an SVG.
  • hierarchy [dict]: A dictionary describing the biomarkers hierarchy.
  • nongraphic [dict]: A dictionary containing non-graphic annotation.

Tasks

The cli.tasks interface (singleton of TasksTable) allows to add, list, modify and delete tasks from the table task of the database.

TasksTable

Methods

  • cli.tasks.create(type, annotation, complete=False, visible=True, comment=None, assign_to=None)

    Create a task.

    Parameters:
    • type [int|TaskType]: Id or a TaskType entity of the task of the type.
    • annotation [int|Annotation|Image]: Id or Annotation entity to modify to complete the task. If an Image is provided, an empty annotation is created on that image.
    • complete [bool]: Mark this task as completed or incomplete.
    • visible [bool]: Mark this task as visible or hidden. (Hidden task are not presented in the task list).
    • comment [str]: Comment associated with the task. This comment is not visible from the frontend, it should be used as note created by and for the research team.
    • assign_to [intUser]: If not None, the task is assigned to the provided user.
    Return:

    The created task as an Task object.

  • cli.tasks.save(entity)

    Update a task of the database. Alternatively, you may call task.save(). This operation needs administrator privilege.

    Parameters:
    • entity [Task]: The modified task to save in the database.
  • cli.tasks.list()

    List all tasks contained in the task table of the database.

    Return:

    The task list as an EntityList(Task) object.

  • cli.tasks.delete(entities)

    Remove a task from the database. This operation need administrator privilege.

    Parameters:
    • entities [int|Task]: The task to delete or its id.
    Return:

    The deleted task as a Task object.

Task entity

An Task object represents a single entity from the task table of the database.

Attributes:

  • id [int]: The index (and primary key) of the task.
  • taskType [TaskType]: The task's type.
  • annotation [Annotation]: The annotation modified by the task.
  • isComplete [bool]: True if the task was marked as completed.
  • isVisible [bool]: True if the task is visible.
  • comment [str]: Comment associated with the annotation. This comment is not visible from the frontend, it should be used as note created by and for the research team.
  • assignedUser [User]: The user to which this task is assigned.
  • creator [User]: The user who created this task. Read-only
  • Inherited attributes from Entity

Methods:


Task Types

The cli.task_types interface (singleton of TaskTypesTable) allows to add, list, modify and delete task types from the table taskType of the database.

TaskTypesTable

Methods

  • cli.task_types.create(title, description)

    Create a task type.

    Parameters:
    • title [str]: Task type title.
    • description [str]: Description of the task displayed next to the image in the annotation interface.
    Return:

    The created task type as an TaskType object.

  • cli.task_types.save(entity)

    Update a task type of the database. Alternatively, you may call entity.save(). This operation needs administrator privilege.

    Parameters:
    • entity [TaskType]: The modified task to save in the database.
  • cli.task_types.list()

    List all task types contained in the taskType table of the database.

    Return:

    The task list as an EntityList(TaskType) object.

  • cli.task_types.delete(entities)

    Remove a task type from the database. This operation need administrator privilege.

    Parameters:
    • entities [int|TaskType]: The task type to delete or its id.
    Return:

    The deleted task type as a TaskType object.

TaskType entity

An TaskType object represents a single entity from the taskType table of the database.

Attributes:

  • id [int]: The index (and primary key) of the task type.
  • title [str]: Task type's title.
  • description [str]: Task type's description.
  • Inherited attributes from Entity

Methods:


Submission Events

The cli.submission_events interface (singleton of SumbissionEventTable) allows to list submission events from the table submissionEvents of the database.

SumbissionEventTable

Methods

  • cli.submission_events.list(user=None, image=None)

    List all submission contained in the submissionEvents table of the database. Optionally events can be filtered.

    Parameters:
    • user [int|User]: A user or its id. If not None, only events submitted by this user will be listed.
    • image [int|Image]: An image or its id. If not None, only events related to this image will be displayed.
    Return:

    The event matching the filter parameters as an EntityList(SubmissionEvent) object.

SubmissionEvent entity

A SubmissionEvent object represents a single entity from the submissionEvent table of the database.

Attributes:

  • id [int]: The index (and primary key) of the event.
  • description [str]: Submission's description. Some descriptions are generated automatically (for example when creating or cloning an annotation).
  • date [str]: Submission's date.
  • timestamp [float]: Time spent annotating since the last event (in minutes).
  • user [User]: The user who made the submission.
  • parentEventId [int]: The id of the parent submission event of this event.
  • Inherited attributes from Entity

Methods:

  • event.parent_event()

    Fetch the parent event.

    Return:

    The parent event as a SubmissionEvent.

  • event.history()

    Retrieve all submission events in this event history. (This event parent, its parent, until the original submission).

    Return:

    An EntityList(SubmissionEvent) containing all ancestors of this event and itself, sorted in chronological order.

Clone this wiki locally