orangeqs.juice.dashboard.utils#

Utilities for dashboard.

Module Contents#

Classes#

JuiceEnvironment

Manage the Jinja template environment for Juice.

PanelNotif

Message class to send notifications over the Juice Pub/Sub system.

Functions#

jupyterhub_service_prefix

Get the JupyterHub service prefix without trailing slash.

dashboard_base_url

Get the base URL for the dashboard without trailing slash.

filebrowser_base_url

Get the base URL for the filebrowser without trailing slash.

jupyterlab_base_url

Get the base URL for JupyterLab without trailing slash.

vscode_base_url

Get the base URL for VS Code without trailing slash.

url_to_name

Convert a URL path to a human-readable name.

influxdb2_base_url

Get the base URL for InfluxDB2 without trailing slash.

subscribe_to_events_task

Create and manage an async task to listen for pub/sub events.

get_palette

Return OQS color palette for colors, repeating.

get_stylesheet

Retrieve CSS file hosted by the singleuser server.

to_local_time

Convert a datetime object to the local timezone.

setup_notifications

Set up notifications for a Panel page.

API#

orangeqs.juice.dashboard.utils.jupyterhub_service_prefix() str#

Get the JupyterHub service prefix without trailing slash.

Looks up the JUPYTERHUB_SERVICE_PREFIX environment variable to determine the prefix. This variable usually contains the prefix for the user container, e.g. /user/<username>. Ensures that the returned prefix has no trailing slash.

orangeqs.juice.dashboard.utils.dashboard_base_url() str#

Get the base URL for the dashboard without trailing slash.

The URL consists of:

  • The JupyterHub service prefix (e.g. /user/<username>)

  • The endpoint for the dashboard, which is /dashboard

An example full URL would be /user/<username>/dashboard.

orangeqs.juice.dashboard.utils.filebrowser_base_url() str#

Get the base URL for the filebrowser without trailing slash.

A direct link to a specific path in the file browser can be constructed as {filebrowser_base_url()}/path/to/directory.

The URL returned by this function consists of:

  • The JupyterHub service prefix (e.g. /user/<username>)

  • The proxy path for the file browser, which is /filebrowser

  • The endpoint to serve files of the file browser, which is /files

An example returned URL is /user/<username>/filebrowser/files.

orangeqs.juice.dashboard.utils.jupyterlab_base_url() str#

Get the base URL for JupyterLab without trailing slash.

The URL consists of:

  • The JupyterHub service prefix (e.g. /user/<username>)

  • The endpoint to serve JupyterLab, which is /lab

An example full URL would be /user/<username>/lab.

orangeqs.juice.dashboard.utils.vscode_base_url() str#

Get the base URL for VS Code without trailing slash.

The URL consists of:

  • The JupyterHub service prefix (e.g. /user/<username>)

  • The endpoint to serve VS Code, which is /vscode

An example full URL would be /user/<username>/vscode. Specific folders can be opened by adding ?folder=path/to/folder to the URL.

orangeqs.juice.dashboard.utils.url_to_name(url: str) str#

Convert a URL path to a human-readable name.

Replaces -, _, and / with spaces and capitalizes each word.

orangeqs.juice.dashboard.utils.influxdb2_base_url() str#

Get the base URL for InfluxDB2 without trailing slash.

The URL consists of:

  • The JupyterHub service prefix (e.g. /user/<username>)

  • The endpoint to serve InfluxDB2, which is /influxdb2

An example full URL would be /user/<username>/influxdb2.

orangeqs.juice.dashboard.utils.subscribe_to_events_task(doc: bokeh.document.Document, subscriptions: list[tuple[type, str]], handler: collections.abc.Callable[[Any], None]) asyncio.Task[Any]#

Create and manage an async task to listen for pub/sub events.

WARNING: The returned task must be kept referenced to avoid being garbage collected.

Parameters#

  • doc: Document: The Bokeh document to schedule callbacks on.

  • subscriptions: list[tuple[type, str]]: A list of (event class, topic) tuples to subscribe to.

  • handler: Callable[[Any], None]: A callable to handle each incoming event.

Returns#

  • (An asyncio.Task managing the subscription.)

  • (Example:): class SomeDashboardComponent: def init(self, client, doc): self.client = client self.doc = doc self.listener_task = subscribe_to_events_task( self.doc, [(QuantityUpdate, “he3_flow”)], self._handle_event ) def _handle_event(self, event): # Process event (e.g. update a ColumnDataSource) self.source.patch({…})

orangeqs.juice.dashboard.utils.get_palette(count: int) list[str]#

Return OQS color palette for colors, repeating.

orangeqs.juice.dashboard.utils.get_stylesheet(path: str) str#

Retrieve CSS file hosted by the singleuser server.

orangeqs.juice.dashboard.utils.to_local_time(dt: datetime.datetime) datetime.datetime#

Convert a datetime object to the local timezone.

Parameters#

  • dt (datetime): The datetime object to convert. It should be timezone-aware.: If the input datetime is naive (lacking timezone information), it will be assumed to be in UTC, and a warning will be raised.

Returns#

  • (datetime: The datetime object converted to the local timezone.)

Notes#

  • If the input is a pandas.Timestamp, it will be handled similarly, with naive timestamps being assumed to be in UTC.

  • A warning will be logged if the input datetime or pandas.Timestamp is naive.

class orangeqs.juice.dashboard.utils.JuiceEnvironment(extra_loaders: jinja2.BaseLoader | list[jinja2.BaseLoader] | None = None, extra_template_paths: str | list[str] | None = None)#

Bases: jinja2.Environment

Manage the Jinja template environment for Juice.

get_jinja_template(file_name: str) jinja2.Template#

Retrieve a Jinja template by name.

get_panel_template(file_name: str) panel.template.Template#

Retrieve a template by file name as a Panel template.

For Juice Extensions: Note that if the directory the template file is in has not been added with extra_loaders or extra_template_paths in the init function beforehand, it will not be found.

class orangeqs.juice.dashboard.utils.PanelNotif(/, **data: Any)#

Bases: orangeqs.juice.messaging.Event

Message class to send notifications over the Juice Pub/Sub system.

level: int#

None

msg: str#

None

topic() str#

Return the topic for Panel notifs.

orangeqs.juice.dashboard.utils.setup_notifications(template: panel.template.Template) None#

Set up notifications for a Panel page.