Skip to content

Links

Class to generate link to alarm log page

Source code in echo_baze/baze_root.py
def __init__(self, baze: e_bz.Baze) -> None:
    """Base class that all subclasses should inherit from.

    Parameters
    ----------
    baze : Baze
        Top level object carrying all functionality and the connection handler.

    """
    # check inputs
    if not isinstance(baze, e_bz.Baze):
        raise ValueError(f"baze must be of type Baze, not {type(baze)}")

    self.baze: e_bz.Baze = baze

Generates link for the alarm log page in Bazefield.

Parameters:

  • (DateTimeRange) –

    Period to be shown in the page.

  • (list[str] | None, default: None ) –

    What objects to show, by default None

  • (Literal['All', 'Alarm', 'Warning', 'Status'], default: 'All' ) –

    Type of alarm to show, by default "All"

Other Parameters:

  • all_object_ids

    Output of self.baze.objects.instances.get_ids() to avoid calling it again.

Returns:

  • str

    Link

Source code in echo_baze/link_alarmlog.py
@validate_call
def get(
    self,
    period: DateTimeRange,
    object_names: list[str] | None = None,
    alarm_type: Literal["All", "Alarm", "Warning", "Status"] = "All",
    **kwargs,
) -> str:
    """Generates link for the alarm log page in Bazefield.

    Parameters
    ----------
    period : DateTimeRange
        Period to be shown in the page.
    object_names : list[str] | None, optional
        What objects to show, by default None
    alarm_type : Literal["All", "Alarm", "Warning", "Status"], optional
        Type of alarm to show, by default "All"

    Other Parameters
    ----------------
    all_object_ids: dict[str, str]
        Output of self.baze.objects.instances.get_ids() to avoid calling it again.

    Returns
    -------
    str
        Link
    """
    # checking kwargs
    wanted_kwargs = ["all_object_ids"]
    missing_kwargs = [kw for kw in wanted_kwargs if kw not in kwargs]
    if missing_kwargs:
        logger.warning(f"Missing kwargs: {missing_kwargs}. This may make generating multiple links very slow")

    link_str = f"{HOSTNAME}/bazefield.portal/#/alarmlog?type={alarm_type}"

    # objectIds
    if object_names:
        all_object_ids = kwargs.get("all_object_ids")
        if all_object_ids is None:
            all_object_ids = self.baze.objects.instances.get_ids()
        link_str += "&objectIds="
        for object_name in object_names:
            if object_name in all_object_ids:
                link_str += f"{all_object_ids[object_name]},"
                continue
            raise ValueError(f"Object not found: {object_name}")
        link_str = link_str[:-1]

    # period
    link_str += f"&from={timestamp_from_datetime(period.start)}"
    link_str += f"&to={timestamp_from_datetime(period.end)}"

    return link_str

Class to generate link to allocations page

Source code in echo_baze/baze_root.py
def __init__(self, baze: e_bz.Baze) -> None:
    """Base class that all subclasses should inherit from.

    Parameters
    ----------
    baze : Baze
        Top level object carrying all functionality and the connection handler.

    """
    # check inputs
    if not isinstance(baze, e_bz.Baze):
        raise ValueError(f"baze must be of type Baze, not {type(baze)}")

    self.baze: e_bz.Baze = baze

Generates link for the availability page in Bazefield.

Parameters:

  • (DateTimeRange) –

    Period to be shown in the page.

  • (Literal['allocations', 'timeline', 'asset'], default: 'allocations' ) –

    Which tab will be selected in the portal, by default "allocations"

  • (list[str] | None, default: None ) –

    Which categories to show, by default None

  • (str, default: 'Internal - Wind - Event Types' ) –

    Which allocation type to show, by default "Internal - Wind - Event Types"

  • (list[str] | None, default: None ) –

    What objects to show, by default None

  • (bool, default: False ) –

    True to show excluded allocations, by default False

  • (bool, default: False ) –

    True to show overridden allocations, by default False

  • (bool, default: False ) –

    True to show available allocations, by default False

  • (bool, default: False ) –

    True to show full performance, by default False

Other Parameters:

  • alloc_type_ids

    Output of self.baze.allocations.types.get_ids() to avoid calling it again.

  • all_category_ids

    Output of self.baze.allocations.categories.get_ids() to avoid calling it again.

  • all_object_ids

    Output of self.baze.objects.instances.get_ids() to avoid calling it again.

Returns:

  • str

    Link

Source code in echo_baze/link_availability.py
@validate_call
def get(
    self,
    period: DateTimeRange,
    tab: Literal["allocations", "timeline", "asset"] = "allocations",
    categories: list[str] | None = None,
    allocation_type: str = "Internal - Wind - Event Types",
    object_names: list[str] | None = None,
    show_excluded: bool = False,
    show_overridden: bool = False,
    show_available: bool = False,
    show_fullperformance: bool = False,
    **kwargs,
) -> str:
    """Generates link for the availability page in Bazefield.

    Parameters
    ----------
    period : DateTimeRange
        Period to be shown in the page.
    tab : Literal["allocations", "timeline", "asset"], optional
        Which tab will be selected in the portal, by default "allocations"
    categories : list[str] | None, optional
        Which categories to show, by default None
    allocation_type : str, optional
        Which allocation type to show, by default "Internal - Wind - Event Types"
    object_names : list[str] | None, optional
        What objects to show, by default None
    show_excluded : bool, optional
        True to show excluded allocations, by default False
    show_overridden : bool, optional
        True to show overridden allocations, by default False
    show_available : bool, optional
        True to show available allocations, by default False
    show_fullperformance : bool, optional
        True to show full performance, by default False

    Other Parameters
    ----------------
    alloc_type_ids: dict[str, int], optional
        Output of self.baze.allocations.types.get_ids() to avoid calling it again.
    all_category_ids: dict[str, dict[str, int]], optional
        Output of self.baze.allocations.categories.get_ids() to avoid calling it again.
    all_object_ids: dict[str, int], optional
        Output of self.baze.objects.instances.get_ids() to avoid calling it again.

    Returns
    -------
    str
        Link
    """
    # checking kwargs
    wanted_kwargs = ["alloc_type_ids", "all_category_ids", "all_object_ids"]
    missing_kwargs = [kw for kw in wanted_kwargs if kw not in kwargs]
    if missing_kwargs:
        logger.warning(f"Missing kwargs: {missing_kwargs}. This may make generating multiple links very slow")

    # allocation type id
    alloc_type_ids = kwargs.get("alloc_type_ids")
    if alloc_type_ids is None:
        alloc_type_ids = self.baze.allocations.types.get_ids()

    if allocation_type not in alloc_type_ids:
        raise ValueError(f"Allocation type not found: {allocation_type}")
    alloc_type_id = alloc_type_ids[allocation_type]

    # allocation categories ids
    all_category_ids = kwargs.get("all_category_ids")
    if all_category_ids is None:
        all_category_ids = self.baze.allocations.categories.get_ids(allocation_types=[allocation_type])
    all_category_ids = all_category_ids[allocation_type]
    if categories is None:
        categories = list(all_category_ids.keys())
    alloc_category_ids = [str(v) for k, v in all_category_ids.items() if k in categories]

    tab_mapping = {
        "allocations": "",
        "timeline": "/timeline",
        "asset": "/override/turbine/",
    }

    link_str = f"{HOSTNAME}/bazefield.portal/#/availability{tab_mapping[tab]}?sidebar=true"

    # category
    link_str += f"&allocationTypeId={alloc_type_id}"
    link_str += f"&categoryIds={','.join(alloc_category_ids)}"

    # options
    link_str += f"&showRun={'true' if show_fullperformance else 'false'}&showOverridden={'true' if show_overridden else 'false'}&showExcluded={'true' if show_excluded else 'false'}&showAvailable={'true' if show_available else 'false'}&showUnedited=true&showManual=true"

    # objectIds
    if object_names:
        all_object_ids = kwargs.get("all_object_ids")
        if all_object_ids is None:
            all_object_ids = self.baze.objects.instances.get_ids()
        link_str += "&objectIds="
        for object_name in object_names:
            if object_name in all_object_ids:
                link_str += f"{all_object_ids[object_name]},"
                continue
            raise ValueError(f"Object not found: {object_name}")
        link_str = link_str[:-1]
        link_str += f"&objectId={all_object_ids[object_names[0]]}"

    # period
    link_str += f"&from={timestamp_from_datetime(period.start)}"
    link_str += f"&to={timestamp_from_datetime(period.end)}"

    return link_str

Class to generate links to trend page

Source code in echo_baze/baze_root.py
def __init__(self, baze: e_bz.Baze) -> None:
    """Base class that all subclasses should inherit from.

    Parameters
    ----------
    baze : Baze
        Top level object carrying all functionality and the connection handler.

    """
    # check inputs
    if not isinstance(baze, e_bz.Baze):
        raise ValueError(f"baze must be of type Baze, not {type(baze)}")

    self.baze: e_bz.Baze = baze

Generates the link to the trend page in BazeField.

Parameters:

  • (DateTimeRange) –

    Desired period for the trend.

  • (dict[str, list[str]]) –

    Dict in the format {object_name: [tag1, tag2, ...]}.

Other Parameters:

  • point_details

    Output of self.baze.points.details.get() to avoid calling it again.

  • obj_ids

    Output of self.baze.objects.instances.get_ids() to avoid calling it again.

Returns:

  • str

    Trend link.

Source code in echo_baze/link_trend.py
@validate_call
def get(
    self,
    period: DateTimeRange,
    points: dict[str, list[str]],
    **kwargs,
) -> str:
    """Generates the link to the trend page in BazeField.

    Parameters
    ----------
    period : DateTimeRange
        Desired period for the trend.
    points : dict[str, list[str]]
        Dict in the format {object_name: [tag1, tag2, ...]}.

    Other Parameters
    ----------------
    point_details: dict[str, dict[str, dict[str, Any]]]
        Output of self.baze.points.details.get() to avoid calling it again.
    obj_ids: dict[str, int]
        Output of self.baze.objects.instances.get_ids() to avoid calling it again.

    Returns
    -------
    str
        Trend link.
    """
    # checking kwargs
    wanted_kwargs = ["point_details", "obj_ids"]
    missing_kwargs = [kw for kw in wanted_kwargs if kw not in kwargs]
    if missing_kwargs:
        logger.warning(f"Missing kwargs: {missing_kwargs}. This may make generating multiple links very slow")

    obj_ids = kwargs.get("obj_ids")
    if obj_ids is None:
        obj_ids = self.baze.objects.instances.get_ids()

    link_str = f"{HOSTNAME}/bazefield.portal/#/trend?assetTagsChecked=true&sidebar=true"

    # period
    link_str += f"&from={timestamp_from_datetime(period.start)}"
    link_str += f"&to={timestamp_from_datetime(period.end)}"

    point_details = kwargs.get("point_details")
    if point_details is None:
        point_details = self.baze.points.details.get(points=points, output_type="dict")

    link_obj_ids = []
    link_tag_ids = []
    for object_name, point_names in points.items():
        if object_name in obj_ids:
            link_obj_ids.append(obj_ids[object_name])
        else:
            raise ValueError(f"Object {object_name} not found in the database")
        for point in point_names:
            tag_id = point_details[object_name][point]["measurementId"]
            link_tag_ids.append(str(tag_id))
    link_str += f"&tags={','.join(link_tag_ids)}"
    link_str += f"&objectIds={','.join(link_obj_ids)}"

    return link_str

Class to generate links to object dashboard page

Source code in echo_baze/baze_root.py
def __init__(self, baze: e_bz.Baze) -> None:
    """Base class that all subclasses should inherit from.

    Parameters
    ----------
    baze : Baze
        Top level object carrying all functionality and the connection handler.

    """
    # check inputs
    if not isinstance(baze, e_bz.Baze):
        raise ValueError(f"baze must be of type Baze, not {type(baze)}")

    self.baze: e_bz.Baze = baze

Generates the link to the object dashboard page in BazeField.

Parameters:

  • (str) –

    Name of the object.

Returns:

  • str

    Trend link.

Source code in echo_baze/link_objectdash.py
@validate_call
def get(
    self,
    object_name: str,
) -> str:
    """Generates the link to the object dashboard page in BazeField.

    Parameters
    ----------
    object_name : str
        Name of the object.

    Returns
    -------
    str
        Trend link.
    """
    return f"{HOSTNAME}/bazefield.portal/#/domainObjectDashboard/{object_name}?dashboardProperty=model.attributes.defaultDashboard"