{"body": "
\n

# `collectors.core` \u2014 Core classes\u00b6

\n

This module contains Collector\u2019s core classes like like the `Collector` \nitself and the base base and default storages.

\n

\n
\nclass `collectors.core.``Collector`(*args[, **kwargs])\u00b6
\n

  This class can monitor the values of a given set of variables.

  \n

  Each variable is described by a name and a collector function which must\nbe passed as tuple `(name, func)`. The list of name-func-tuples may\nalso be nested, which is helpful for some convenience functions.

  \n

  For each variable a series for the observed values will be created. The\nvariables\u2019 series are accessible via an index (defined by the order you\npassed them) as well as by an attribute of a `Collector` instance named\nafter name.

  \n

  All collector functions will be called (in the same order as they were\nspecified) each time a `Collector` instance is called. The collector\nfunctions may either grab the desired values by themselves or let them be\npassed manually with each collector call.

  \n

  Here is an example how this works:

  \n

      >>> class Spam(object):\n...     a = 1\n...     b = 2\n...\n>>> spam = Spam()\n>>> c = Collector(('a', lambda: spam.a), ('b', lambda x: x))\n>>> c.a == c[0], c.b == c[1]\n(True, True)\n>>>\n>>> c(b=spam.b + 2)\n>>> spam.a, spam.b = 3, 4\n>>> c(b=spam.b + 2)\n>>> c # Collector inherits tuple, so you can do this:\n([1, 3], [4, 6])\n>>> c.a, c.b # You can also access it's elements by their name.\n([1, 3], [4, 6])\n

  \n
  \n

  In this example, `spam` is the object to be monitored. The monitor is\nconfigured to observe two variables named \u201ca\u201d and \u201cb\u201d. The collector\nfunction for \u201ca\u201d automatically retrieves `spam.a`, while the value for \u201cb\u201d\nneeds to be passed to the monitor manually as a keyword argument. For these\ncommon cases, there are the shortcuts `get()` and\n`manual()`.

  \n

  Note that names for data series need to be unique. `Collector`\ninstanciation will raise a `ValueError` if there’s a duplicate name.

  \n
  \n
  \n`__call__`(**kwargs)\u00b6
  \n

    Execute all collector functions and append the retrieved values to the\nseries of each variable.

    \n

    If a collector function required a parameter, you must pass it as\nkeyword argument with the variable\u2019s name.

    \n
  \n\n
  \n
  \n`collect`\u00b6
  \n
    This is just an alias to `__call__()`.
  \n\n

\n\n

\n
\nclass `collectors.core.``BaseStorage`\u00b6
\n

  Base class for storages.

  \n

  Storages define, where and in which format the collected data will be\nstored. During its initialization a `Collector` will call\n`create_series()` for each monitored variable. Every time the\n`Collector` is asked to collect the current values `append()`\ninvoked with the appropiate series and value.

  \n
  \n
  \n`append`(series, value)\u00b6
  \n

    Append `value` to `series`.

    \n

    You can either override this method in a subclass or assign an existing \nmethod (or lambda function) to the attribute `self.append`.

    \n
  \n\n
  \n
  \n`create_series`(name, index)\u00b6
  \n
    Create a new series for the variable `name` at `index` of the\ncollector.
  \n\n

\n\n

\n
\nclass `collectors.core.``DefaultStorage`\u00b6
\n

  Bases: `collectors.core.BaseStorage`

  \n

  The default storage used by `Collector`. The values of each\nmonitored variable are stored in a simple `list`.

  \n
  \n
  \n`append`(series, value)\u00b6
  \n

    Append `value` to `series`.

    \n

    You can either override this method in a subclass or assign an existing \nmethod (or lambda function) to the attribute `self.append`.

    \n
  \n\n
  \n
  \n`create_series`(name, index)\u00b6
  \n
    Return a new empty list.
  \n\n

\n\n
\n", "display_toc": false, "title": "`collectors.core` \u2014 Core classes", "sourcename": "ref/core.txt", "current_page_name": "ref/core", "next": {"link": "../shortcuts/", "title": "`collectors.shortcuts` \u2014 Useful shortcut functions"}, "rellinks": [["genindex", "General Index", "I", "index"], ["modindex", "Global Module Index", "M", "modules"], ["ref/shortcuts", "`collectors.shortcuts` \u2014 Useful shortcut functions", "N", "next"], ["ref/index", "API-Reference", "P", "previous"]], "meta": {}, "parents": [{"link": "../", "title": "API-Reference"}], "toc": "

\n
- `collectors.core` \u2014 Core classes
\n

\n", "prev": {"link": "../", "title": "API-Reference"}, "metatags": ""}