ash_model.NProfile

class ash_model.NProfile(node_id=None, **kwargs)[source]

A profile holding attributes and computed statistics for a node.

Parameters:
  • node_id (int | None) –

  • kwargs (Any) –

__init__(node_id=None, **kwargs)[source]

Initialize a new NProfile.

Parameters:
  • node_id (int | None) – Optional identifier for the node.

  • kwargs (Any) – Initial attributes to set on the profile.

Return type:

None

Methods

__init__([node_id])

Initialize a new NProfile.

add_attribute(key, value)

Add or update a single attribute in the profile.

add_attributes(**kwargs)

Add or update multiple attributes in the profile.

add_statistic(attr_name, stat_name, value)

Add or update a computed statistic for a given attribute.

attribute_computed_statistics(attr_name)

List all computed statistic names for a given attribute.

get_attribute(key)

Retrieve the value of a given attribute.

get_attributes()

Retrieve all attributes in the profile.

get_statistic(attr_name[, stats_name])

Retrieve computed statistics for a given attribute.

has_attribute(key)

Check if an attribute exists in the profile.

has_statistic(attr_name, stats_name)

Check if a specific statistic exists for a given attribute.

items()

Get all attribute key-value pairs as a list.

to_dict()

Convert the profile to a dictionary representation.

__init__(node_id=None, **kwargs)[source]

Initialize a new NProfile.

Parameters:
  • node_id (int | None) – Optional identifier for the node.

  • kwargs (Any) – Initial attributes to set on the profile.

Return type:

None

add_attribute(key, value)[source]

Add or update a single attribute in the profile.

Parameters:
  • key (str) – Name of the attribute to add.

  • value (Any) – Value of the attribute.

Return type:

None

add_attributes(**kwargs)[source]

Add or update multiple attributes in the profile.

Parameters:

kwargs (Any) – Key-value pairs of attributes to add.

Return type:

None

get_attribute(key)[source]

Retrieve the value of a given attribute.

Parameters:

key (str) – Name of the attribute to retrieve.

Returns:

The attribute’s value.

Raises:

ValueError – If the attribute is not present.

Return type:

str | int | float

get_attributes()[source]

Retrieve all attributes in the profile.

Returns:

Dictionary of attribute names to values.

Return type:

Dict[str, Any]

has_attribute(key)[source]

Check if an attribute exists in the profile.

Parameters:

key (str) – Name of the attribute to check.

Returns:

True if the attribute exists, False otherwise.

Return type:

bool

add_statistic(attr_name, stat_name, value)[source]

Add or update a computed statistic for a given attribute.

Parameters:
  • attr_name (str) – The attribute to which the statistic applies.

  • stat_name (str) – Name of the statistic (e.g., ‘mean’, ‘max’).

  • value (float) – Numeric value of the statistic.

Raises:

ValueError – If the attribute is not present in the profile.

Return type:

None

get_statistic(attr_name, stats_name=None)[source]

Retrieve computed statistics for a given attribute.

Parameters:
  • attr_name (str) – The attribute whose statistics to retrieve.

  • stats_name (str | None) – Specific statistic name to retrieve (optional).

Returns:

Dictionary of statistic names to their values.

Raises:

ValueError – If the attribute or statistic is not present.

Return type:

Dict[str, float]

has_statistic(attr_name, stats_name)[source]

Check if a specific statistic exists for a given attribute.

Parameters:
  • attr_name (str) – The attribute to check.

  • stats_name (str) – The statistic name to check.

Returns:

True if the statistic exists, False otherwise.

Raises:

ValueError – If the attribute is not present.

Return type:

bool

attribute_computed_statistics(attr_name)[source]

List all computed statistic names for a given attribute.

Parameters:

attr_name (str) – The attribute to query.

Returns:

List of statistic names.

Raises:

ValueError – If the attribute is not present or has no statistics.

Return type:

List[str]

items()[source]

Get all attribute key-value pairs as a list.

Returns:

List of tuples (key, value).

Return type:

List[Tuple[str, Any]]

to_dict()[source]

Convert the profile to a dictionary representation.

Returns:

Dictionary with ‘node_id’ and ‘attrs’ keys.

Return type:

Dict[str, Any]