storages Package

base Module

class recommends.storages.base.BaseRecommendationStorage(settings=None)[source]

Bases: object

can_lock = False
get_identifier(obj, site_id=None, rating=None, *args, **kwargs)[source]

Given an object and optional parameters, returns a string identifying the object uniquely.

get_lock()[source]

Acquire a storage-specific lock

get_recommendations_for_user(user, limit, raw_id=False)[source]
if raw_id = False:
Returns a list of Recommendation objects for given user, ordered by score.
else:

Returns a list of recommended model ids[pk] for given user, ordered by score.

Example:

::
[
{
“object_id”: XX, “contect_type_id”: XX

]

get_similarities_for_object(obj, limit, raw_id=False)[source]
if raw_id = False:
Returns a list of Similarity objects for given obj, ordered by score.
else:

Returns a list of similar model ids[pk] for given obj, ordered by score.

Example:

[
    {
        "related_object_id": XX, "contect_type_id": XX
    },
    ..
]
get_votes()[source]

Optional.

Retrieves the vote matrix saved by store_votes.

You won’t usually need to implement this method, because you want to use fresh data. But it might be useful if you want some kind of heavy caching, maybe for testing purposes.

release_lock()[source]

Release a storage-specific lock

remove_recommendation(obj)[source]

Deletes all recommendations for object obj.

remove_similarity(obj)[source]

Deletes all similarities that have object obj as source or target.

resolve_identifier(identifier)[source]

This method is the opposite of get_identifier. It resolve the object’s identifier to an actual model.

store_recommendations(recommendations)[source]

Stores all the recommendations.

recommendations is an iterable with the following schema:

(
    (
        <user>,
        (
            (<object_identifier>, <score>),
            (<object_identifier>, <score>)
        ),
    )
)
store_similarities(itemMatch)[source]
store_votes(iterable)[source]

Optional.

Saves the vote matrix.

You won’t usually need to implement this method, because you want to use fresh data. But it might be useful if you want to dump the votes on somewhere, maybe for testing purposes.

iterable is the vote matrix, expressed as a list of tuples with the following schema:

[
    ("<user_id1>", "<object_identifier1>", <score>),
    ("<user_id1>", "<object_identifier2>", <score>),
    ("<user_id2>", "<object_identifier1>", <score>),
    ("<user_id2>", "<object_identifier2>", <score>),
]
threshold_recommendations = 0
threshold_similarities = 0