zabgrab.services.listing

Listing data points, filtered, sorted and sliced (zabgrab show).

A listing is made of sections. Sorted by time, there’s one section holding every item’s points, interleaved. Sorted by value, there’s one section per item, since values of different items (often in different units) can’t be ranked together.

Module Attributes

STATISTICS

The hourly trend statistics, in the order they're shown.

SORT_KEYS

What --sort accepts.

Functions

listing(series, options)

List the points of some series, filtered, sorted and sliced.

matching(series, options)

Find the positions of a series' points that pass the filters.

value_column(series[, sort])

Name the column holding a series' values, for sorting and filtering.

Classes

ListingOptions([sort, descending, limit, ...])

How to filter, sort and slice a listing.

Row(series, index)

One point of a series.

Section(series, rows, matched)

A part of a listing.

zabgrab.services.listing.STATISTICS = ('min', 'avg', 'max', 'count')

The hourly trend statistics, in the order they’re shown.

zabgrab.services.listing.SORT_KEYS = ('time', 'value', 'min', 'avg', 'max', 'count')

What --sort accepts.

class zabgrab.services.listing.ListingOptions(sort='time', descending=False, limit=None, offset=0, grep=None, above=None, below=None)[source]

Bases: object

How to filter, sort and slice a listing.

Parameters:
sort

time, value, or a trend statistic (min, avg, max or count).

Type:

str

descending

Largest (or latest) first.

Type:

bool

limit

At most this many points (per section); None for all.

Type:

int or None

offset

Skip this many points (per section) first.

Type:

int

grep

Only points whose value, as text, contains a match.

Type:

re.Pattern or None

above, below

Only numeric points whose value is greater than above and less than below.

Type:

float or None

class zabgrab.services.listing.Row(series, index)[source]

Bases: object

One point of a series.

Parameters:
series

The series.

Type:

Series

index

The point’s position in the series’ columns.

Type:

int

get(column)[source]

Get the point’s value in a column (None if the series lacks it).

Parameters:

column (str)

Return type:

Any

class zabgrab.services.listing.Section(series, rows, matched)[source]

Bases: object

A part of a listing.

Parameters:
series

The items whose points are in the section, in the order given.

Type:

list of Series

rows

The points shown, in order.

Type:

list of Row

matched

How many points matched the filters, before offset and limit.

Type:

int

zabgrab.services.listing.value_column(series, sort='value')[source]

Name the column holding a series’ values, for sorting and filtering.

Raw data has a value column. Hourly trends have statistics instead: the one named by sort, else the average (or the first one fetched).

Parameters:
  • series (Series) – The series.

  • sort (str, optional) – The --sort key.

Returns:

str – The column’s name.

Raises:

ZabgrabError – If sort names a statistic the series doesn’t have.

Return type:

str

zabgrab.services.listing.listing(series, options)[source]

List the points of some series, filtered, sorted and sliced.

Parameters:
  • series (sequence of Series) – The items’ data.

  • options (ListingOptions) – How to filter, sort and slice.

Returns:

list of Section – One section sorted by time, or one per item sorted by value or a statistic. Sections with no matching points are left out.

Raises:

ZabgrabError – If the sort key doesn’t apply to a series (see value_column()).

Return type:

list[Section]

zabgrab.services.listing.matching(series, options)[source]

Find the positions of a series’ points that pass the filters.

Parameters:
  • series (Series) – The series.

  • options (ListingOptions) – The filters (grep, above and below), and the sort key, which picks the value compared for hourly trends (see value_column()).

Returns:

list of int – The positions, in time order.

Return type:

list[int]