renewal_recsystem API Documentation

This page contains the full generated API documentation for objects in the renewal_recsystem package.

For documentation on how recsystems interact with the Renewal backend, see the Renewal Backend API. For more narrative documentation on the high-level interface for writing recsystems, see Recsystem Interface Documentation.

types

Define names for built-in types that aren't directly accessible as a builtin.

articles

Implements the ArticleCollection class, for maintaining a size-limited cache of articles known by the system.

renewal_recsystem.basic

renewal_recsystem.types

renewal_recsystem.recystem

renewal_recsystem.articles

Implements the ArticleCollection class, for maintaining a size-limited cache of articles known by the system.

Recsystems can use this if they like, but may also replace it with a more sophisticated data store, such as a database, for maintaining a collection of articles sent to the system.

class ArticleCollection(initial=None, max_size=None)[source]

Maintain a list of article objects sorted by article_id (ascending).

Articles are currently just represented as dicts and 'article_id' is their only required key.

Note

It might be a good idea to also feature validation of articles against a public schema.

MAX_ARTICLES = 10000

Maximum number of articles to keep cached in memory.

push(item)[source]

Push a new article to the collection while maintaining the sort invariant.

If the new article is already than the lowest article ID and the collection is already at capacity, it is discarded.

Examples

>>> from renewal_recsystem.articles import ArticleCollection
>>> articles = ArticleCollection(max_size=2)
>>> articles.push({'article_id': 2})
>>> len(articles)
1
>>> articles[2]
{'article_id': 2}

If the article_id already exists this push is ignored (it does not merge with or overwrite the existing article):

>>> articles.push({'article_id': 2, 'extra': True})
>>> len(articles)
1
>>> articles[2]
{'article_id': 2}

If the collection is at capacity, the article with the lowest article_id is dropped on the next push:

>>> articles.push({'article_id': 3})
>>> articles.push({'article_id': 4})
>>> len(articles)
2
>>> 2 in articles
False

Unless the new article is already below the lowest article_id, then the push is ignored:

>>> articles.push({'article_id': 1})
>>> len(articles)
2
>>> 1 in articles
False
>>> articles.article_ids
[3, 4]

renewal_recsystem.server

renewal_recsystem.utils

renewal_recsystem.utils.testing