biometrics_tracker.utilities.utilities module

class biometrics_tracker.utilities.utilities.MutableString(seq)

Bases: UserString

biometrics_tracker.utilities.utilities.compare_hms(time1, time2) bool

Compares the hour, minutes and seconds of two datetime.time objects. This avoids false inequalities based on microsecond level variances

Parameters
  • time1 (datetime.time) – the first of a pair of times to be compared

  • time2 (datetime.time) – the second of a pair of times to be compared

Returns

are the times equal

Return type

bool

biometrics_tracker.utilities.utilities.compare_mdyhms(datetime1: datetime, datetime2: datetime) bool

Compares the day, month, year, hour, minutes and seconds of two datetime.datetime objects. This avoids false inequalities based on microsecond level variances

Parameters
  • datetime1 (datetime.datetime) – the first of a pair of datetimes to be compared

  • datetime2 (datetime.datetime) – the second of a pair of datetimes to be compared

Returns

are the datetimes equal

Return type

bool

biometrics_tracker.utilities.utilities.datetime_from_str(datetime_str: str) datetime

Returns a datetime created from the ISO format string passed to the function

Parameters

datetime_str (str) – an ISO formatted date/time string

Returns

a date/time

Return type

datetime.datetime

biometrics_tracker.utilities.utilities.increment_date(dt: date, years: int = 0, months: int = 0, days: int = 0) date

Increments the provided date by the specified number of years, months and days. The increment values may be positive or negative, but they must all have the same sign or a ValueError exception will be raised. :param dt: the date to be incremented :type dt: datetime.date :param years: the number of years to increment :type years: int :param months: the number of months to increment :type months: int :param days: the number of days to increment :type days: int :return: the resulting date :rtype: datetime.date

biometrics_tracker.utilities.utilities.increment_datetime(dattim: datetime, years: int = 0, months: int = 0, days: int = 0) datetime

Increments the provided date by the specified number of years, months and days. The increment values may be positive or negative, but they must all have the same sign or a ValueError exception will be raised. :param dattim: the datetime to be incremented :type dattim: datetime.datetime :param years: the number of years to increment :type years: int :param months: the number of months to increment :type months: int :param days: the number of days to increment :type days: int :return: the resulting date :rtype: datetime.date

biometrics_tracker.utilities.utilities.max_dom(month: int) int

Returns the number of days in the specified month :param month: the month for which the number of days will be returned :type month: int :return: the number of days in the month :rtype: int

biometrics_tracker.utilities.utilities.mk_datetime(dt: date, tm: time) datetime

Create a datetime using separate date and time values

Parameters
  • dt (datetime.date) – date value

  • tm (datetime.time) – time value

Returns

datetime value

Return type

datetime.datetime

biometrics_tracker.utilities.utilities.ordinal(number: int)

Converts an integer to its ordinal representation

Parameters

number (int) – integer to be converted

Returns

ordinal form of the specified number

Return type

str

biometrics_tracker.utilities.utilities.split_camelcase(camelcase: str) list[str]

Splits a camelcase string into its components :param camelcase: a camelcase formatted string :type camelcase: str :return: a list consisting of the components of the original string :rtype: list[str]

biometrics_tracker.utilities.utilities.split_datetime(dttm: ~datetime.datetime) -> (<class 'datetime.date'>, <class 'datetime.time'>)

Return date and time instances created from the proved datetime

Parameters

dttm (datetime.datetime) – datetime to be split into date and time values

Returns

a tuple containing a date and a time

Return type

tuple[datetime.date, datetime.time]

biometrics_tracker.utilities.utilities.step_enumerate(lst: list[Any], start: int = 0, step: int = 1) list[tuple[int, Any]]

This function is similar to the built in enumerate function, but it allows you to specify a starting value and the amount to increment the index for each item in the list

Parameters
  • lst (list[Any]) – a list of items to be enumerated

  • start (int) – the starting value for the enumeration

  • step (int) – the amount by which the index will be incremented for each itme in the list

Returns

a list of tuples consisting of index/item pairs

Return type

list[tuple[int, Any]]

biometrics_tracker.utilities.utilities.time_from_str(time_str: str) time

Returns a time created from a string formated as HH:MM:SS. This function uses the following regular expression to validate the string format and extract hours, minutes and seconds from the string: ‘(d{1,2})[:](d{2})[:](d{0,2})s*’

Parameters

time_str (str) – the time, in string form

Returns

a time

Return type

datetime.datetime

biometrics_tracker.utilities.utilities.whereami(package_name: str) Path

Returns a Path object pointing to the location of the application’s package folder

Returns

the path of the application’s package directory

Return type

pathlib.Path