https://sppas.org/

SPPAS 4.16

Module sppas.src.anndata

Class sppasDuration

Description

Representation of a duration with vagueness.

Represents a duration identified by 2 float values:

  • the duration value;
  • the duration margin.

Constructor

Create a new sppasDuration instance.

Parameters

  • value: (float) value of the duration.
  • vagueness: (float) represents the vagueness of the value.
def __init__(self, value, vagueness=0.0):
    """Create a new sppasDuration instance.

    :param value: (float) value of the duration.
    :param vagueness: (float) represents the vagueness of the value.

    """
    self.__value = 0.0
    self.__margin = 0.0
    self.set_value(value)
    self.set_margin(vagueness)

Public functions

get

Return myself.

def get(self):
    """Return myself."""
    return self
set

Set the value/vagueness of another sppasDuration instance.

Parameters

  • other: (sppasDuration)
def set(self, other):
    """Set the value/vagueness of another sppasDuration instance.

        :param other: (sppasDuration)

        """
    if isinstance(other, sppasDuration) is False:
        raise AnnDataTypeError(other, 'sppasDuration')
    self.__value = other.get_value()
    self.__margin = other.get_margin()
get_value

Return the duration value (float).

def get_value(self):
    """Return the duration value (float)."""
    return self.__value
set_value

Set the duration to a new value.

Parameters

  • value: (float) the new duration value.
def set_value(self, value):
    """Set the duration to a new value.

        :param value: (float) the new duration value.

        """
    try:
        self.__value = float(value)
        if self.__value < 0.0:
            self.__value = 0.0
            raise AnnDataNegValueError(value)
    except TypeError:
        raise AnnDataTypeError(value, 'float')
get_margin

Return the vagueness of the duration (float).

def get_margin(self):
    """Return the vagueness of the duration (float)."""
    return self.__margin
set_margin

Fix the vagueness margin of the duration.

Parameters

  • vagueness: (float) the duration margin.
def set_margin(self, vagueness):
    """Fix the vagueness margin of the duration.

        :param vagueness: (float) the duration margin.

        """
    try:
        self.__margin = float(vagueness)
        if self.__margin < 0.0:
            self.__margin = 0.0
            raise AnnDataNegValueError(vagueness)
    except TypeError:
        raise AnnDataTypeError(vagueness, 'float')
copy

Return a deep copy of self.

def copy(self):
    """Return a deep copy of self."""
    t = self.__value
    r = self.__margin
    return sppasDuration(t, r)

Overloads

__format__
def __format__(self, fmt):
    return str(self).__format__(fmt)
__repr__
def __repr__(self):
    return 'Duration: {:f}, {:f}'.format(self.get_value(), self.get_margin())
__str__
def __str__(self):
    return '({:f}, {:f})'.format(self.get_value(), self.get_margin())
__hash__
def __hash__(self):
    return hash((self.__value, self.__margin))
__eq__

Equal is required to use '==' between 2 sppasDuration instances or

between a sppasDuration and an other object representing time.

This relationship takes into account the vagueness.

Parameters

  • other: (Duration, float, int) is the other duration to compare with.
def __eq__(self, other):
    """Equal is required to use '==' between 2 sppasDuration instances or
        between a sppasDuration and an other object representing time.
        This relationship takes into account the vagueness.

        :param other: (Duration, float, int) is the other duration to compare with.

        """
    if isinstance(other, (int, float, sppasDuration)) is False:
        return False
    if isinstance(other, sppasDuration) is True:
        delta = abs(self.__value - other.get_value())
        radius = self.__margin + other.get_margin()
        return delta <= radius
    if isinstance(other, (int, float)):
        delta = abs(self.__value - other)
        radius = self.__margin
        return delta <= radius
__lt__

LowerThan is required to use '<' between 2 sppasDuration instances

or between a sppasDuration and an other time object.

Parameters

  • other: (Duration, float, int) is the other duration to compare with.
def __lt__(self, other):
    """LowerThan is required to use '<' between 2 sppasDuration instances
        or between a sppasDuration and an other time object.

        :param other: (Duration, float, int) is the other duration to compare with.

        """
    if isinstance(other, sppasDuration) is True:
        return self != other and self.__value < other.get_value()
    return self != other and self.__value < other
__gt__

GreaterThan is required to use '>' between 2 Duration instances

or between a Duration and an other time object.

Parameters

  • other: (Duration, float, int) is the other duration to compare with.
def __gt__(self, other):
    """GreaterThan is required to use '>' between 2 Duration instances
        or between a Duration and an other time object.

        :param other: (Duration, float, int) is the other duration to compare with.

        """
    if isinstance(other, sppasDuration) is True:
        return self != other and self.__value > other.get_value()
    return self != other and self.__value > other
__ne__

Not equals.

Parameters
  • other
def __ne__(self, other):
    """Not equals."""
    return not self == other
__le__

Lesser or equal.

Parameters
  • other
def __le__(self, other):
    """Lesser or equal."""
    return self < other or self == other
__ge__

Greater or equal.

Parameters
  • other
def __ge__(self, other):
    """Greater or equal."""
    return self > other or self == other