Utilities
Utility Functions and Classes
These tools facilitate working with Joule data in modules and with the API. They are grouped by general category.
Time
joule.utilities.time_now()
:return: current time in UNIX microseconds
joule.utilities.timestamp_to_human(timestamp)
Convert a timestamp (integer microseconds since epoch) to a human-readable string, using the local timezone for display (e.g. from the TZ env var).
joule.utilities.human_to_timestamp(time)
Convert a time specification into a UNIX microsecond timestamp. Time specification may be a wide variety of date formats, relative interval such as "one minute ago", or a numeric timestamp. Raises :exc:ValueError for invalid time specification
joule.utilities.timestamp_to_datetime(timestamp)
joule.utilities.datetime_to_timestamp(date)
Time Intervals
joule.utilities.parse_time_interval(time_interval)
joule.utilities.interval_difference(src, dest)
Other
joule.utilities.ConnectionInfo
Encapsulates database connection information
Attributes:
| Name | Type | Description |
|---|---|---|
username |
str
|
database username |
password |
str
|
database password |
port |
int
|
database port |
database |
str
|
database name |
host |
str
|
hostname |
to_dsn()
Convert connection parameters to a DSN string used by SQLAlchemy and other database engines.
to_json()
Convert connection parameters to a dictionary of attributes appropriate for transmission as JSON
joule.utilities.yesno(val)
Convert a "yes" or "no" argument into a boolean value. Returns true
if val is "yes" and false if val is "no". Raises ValueError otherwise.
This is function can be used as the type parameter to argparse module arguments
to make it easier to implement "yes|no" flags.
joule.utilities.ImportLogger
joule.utilities.LogMessage
dataclass
Represents a log message produced by an joule.utilities.ImportLogger while processing a Joule archive upload
Attributes:
| Name | Type | Description |
|---|---|---|
source_label |
str
|
the importer source label |
destination |
str
|
where the data is being imported to |
message |
str
|
log contents |
target_type |
str
|
the type of importer |