API

class riskmatrix.RiskMatrix(name: str)[source]

The main class to build a risk matrix.

add_axis(axis_name: str, *, points: Iterable[riskmatrix.axis.Point] = None, size: int = None, use_letters: bool = False) → riskmatrix.axis.Axis[source]

Add an axis to the risk matrix using a list of axis points.

Alternatively, you can also give a size number to quickly set up an axis. This is nice if you don’t care about the information in the axis points.

Parameters:
  • axis_name (str) – The name for the axis. E.g. Severity or Probability.
  • points (Iterable[Tuple], optional) – A list of points that make up the axis. Defaults to None.
  • size (int, optional) – A quick way to set up an axis by defining how many points you want. Defaults to None.
  • use_letters (bool, optional) – Option to use letters instead of numbers when specifying size. Defaults to False.
Raises:

ValueError – You have to provide either a list of points or a size. You can’t do both.

Returns:

Axis

add_category(code: str, name: str, color: str, text_color: str, description: str = '') → riskmatrix.category.Category[source]

Add a category to the Riskmatrix.

Categories should be added from low to high.

Parameters:
  • code (str) – A short code for the category. E.g. ‘HIG’
  • name (str) – A full name for the category. E.g. ‘High risk’
  • color (str) – A hexadecimal background color code.
  • text_color (str) – A hexadecimal text color code.
  • description (str, optional) – A longer description about what this category means. Defaults to “”.
Returns:

Category

categories

Return a tuple of all Categories in the Riskmatrix.

Sorted by value from low to high.

Returns:A tuple of Categories.
Return type:Tuple[Category, ..]
coordinates

Return a tuple of all Coordinates in the RiskMatrix.

Returns:Tuple of Coordinates sorted alphabetically.
Return type:Tuple[Coordinate, ..]
get_category(coordinate: riskmatrix.coordinate.Coordinate) → riskmatrix.category.Category[source]

Give a Coordinate to get a Category if there is a mapping between them.

Parameters:coordinate (Coordinate) – An instance of Coordinate.
Returns:An instance of Category.
Return type:Category
Exceptions:
KeyError: If the Coordinate couldn’t be found, a KeyError is raised.
get_coordinate(coordinate: str) → riskmatrix.coordinate.Coordinate[source]

Get the Coordinate for a string code like ‘A2’.

Parameters:coordinate (str) – A string which is the code of the Coordinate. E.g. ‘A2’
Returns:A Coordinate if it can be found, or None.
Return type:Optional[Coordinate]
Exceptions:
KeyError: If the Coordinate couldn’t be found, a KeyError is raised.
map_coordinate(category: riskmatrix.category.Category, points: Iterable[riskmatrix.axis.AxisPoint]) → riskmatrix.coordinate.Coordinate[source]

Map a Category to a Coordinate

Parameters:
  • category (Category) – An instance of Category.
  • points (Iterable[AxisPoint]) – A collection of AxisPoint that make up a Coordinate.
Returns:

Coordinate

map_coordinates(category: riskmatrix.category.Category, coordinates: Iterable[Iterable[riskmatrix.axis.AxisPoint]]) → None[source]

Given a Category and a list of AxisPoint collections (each making up a Coordinate), map the Category to each Coordinate.

Parameters:
  • category (Category) – A single Category.
  • coordinates (Iterable[Iterable[AxisPoint]]) – A list of AxisPoint iterables that represent Coordinates.
Returns:

None

class riskmatrix.Axis(name: str, matrix: RiskMatrix)[source]

An axis for a RiskMatrix. Contains AxisPoints.

This class holds the points together and gives them an order.

add_point(point: riskmatrix.axis.Point) → None[source]

Add a Point to the Axis.

The Point is used to create an AxisPoint. The AxisPoint also has a reference to the parent Axis and a value to order them with other AxisPoints on the Axis.

Parameters:point (Point) – The point to add to the Axis.
Returns:None
points

Get the points of the Axis.

Returns:An ordered tuple of AxisPoint.
Return type:Tuple[AxisPoint, ..]
class riskmatrix.AxisPoint(code: str, name: str, description: str, value: int, axis: riskmatrix.axis.Axis)[source]

Has: * a code (e.g. ‘A’ or 1) * a name (e.g. ‘Unlikely’) * a description (e.g. For a definition.) * a numeric value

class riskmatrix.Category(code: str, name: str, color: str, text_color: str, description: str = '')[source]

A collection of points has a RiskMatrix Category.

class riskmatrix.Coordinate(points: Iterable[riskmatrix.axis.AxisPoint])[source]

A collection of AxisPoints to represent a location in a matrix.