Package for recommendation system (68911) integration
Project description
Recommendation_68911
Django PyPi package serving as the interface for the recommendation system, providing models, managers, and migrations required by the vector recommendation service. This package is meant only for Django version 3.2 (and above) and above using the PostgreSQL database version 9.5 (and above). The package is intended to be used with a specific recommendation engine developed as part of my master's thesis project (not yet published) and is not for general purposes.
Installation guide
Install pip package:
pip install recommendation-68911
Add the package to the installed apps in the settings.py file (recommended before custom apps depending on this package).
# settings.py
INSTALLED_APPS = [
...
'recommendation_68911',
'your_custom_app',
]
Add the RECOMMENDATION_SQS_URL variable to your settings, which will specify the URL of your recommendation microservice API endpoint.
# settigs.py
RECOMMENDATION_SQS_URL = 'https://your.api.endpiont/...'
Run the pre-created migration to install the cube extension for your PostgreSQL (extension is compatible to be used also within AWS RDS).
python3 manage.py migrate recommendation_68911
Add RecomObjectQuerySet as a parent to your recommended object class QuerySet manager. If you don't have one, you will need to create one.
# managers.py
from recommendation_68911.managers import RecomObjectQuerySet
class YourObjectQuerySet(..., RecomObjectQuerySet):
...
Specify AbstractRecomObject as the parent of the object class you want to recommend and AbstractRecomActor for the actor class in your app's models.py. Also specify objects attributable to YourObjectClass to use the QuerySetManager created in the previous step. Finally, it's strongly recommended to specify cases when you don't want to perform object vector updates in the save() method by setting the self.update_vector attribute. If updating the vector is wanted, it is required to provide the object's attributes in self.dict_repr.
# models.py
from recommendation_68911.models import AbstractRecomObject, AbstractRecomActor
class YourObjectModel(..., AbstractRecomObject):
...
objects = YourObjectManager.from_queryset(YourObjectQuerySet)
...
def save(self, *args, **kwargs):
if not your_condition:
self.update_vector = False
else:
self.dict_repr = {
...
}
super().save(*args, **kwargs)
class YourActorModel(..., AbstractRecomActor):
...
After this step, you are ready to create and execute the migration to apply changes.
python3 manage.py makemigrations <your_app>
python3 manage.py migrate <your_app>
To send your actor-object interactions to the microservice, you'll need to use the create_interaction() method of the provided RecommendationService class. It's recommended to perform this task within the dispatch() method of your view.
# views.py
from recommendation_68911.services import RecommendationService
class YourDetailView(...):
...
def dispatch(self, request, *args, **kwargs):
super_result = super().dispatch(request, *args, **kwargs)
...
if your_session and your_object.vector != None:
RecommendationService().create_interaction(
object_dict={...},
object_vector=your_object.vector,
object_type="YOUR_TYPE",
your_session.session_key if your_session else None,
your_actor if your_actor.is_authenticated else None
)
return super_result
Your integration of the recommendation system is now finished. To apply a recommendation filter to a query set, add the order_by_recommended() method at the end of your query.
# views.py
class YourListView(...):
...
def get_queryset(...):
qs = super().get_queryset(...)
...
return qs.order_by_recommended(your_actor_object.vector)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file recommendation-68911-0.0.1.tar.gz.
File metadata
- Download URL: recommendation-68911-0.0.1.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e1b5d343764eb0a9a640b5cc4b7a0e436d5a425a1893f5426be54b8d6ca8e0dc
|
|
| MD5 |
3ee2a48c53eff6ac59bb67075101b3cb
|
|
| BLAKE2b-256 |
24df733352e826fe189f8a8fd2de848a149e27ddddf7c26e51d1d27892ab1a8b
|
File details
Details for the file recommendation_68911-0.0.1-py3-none-any.whl.
File metadata
- Download URL: recommendation_68911-0.0.1-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
06e49a853daf15fd2f5e824e988b023a4a6d8fbc8df430c0f745ea8acae8a6cf
|
|
| MD5 |
14afa230c44abb1e1d93356338aa9832
|
|
| BLAKE2b-256 |
7840bff32b0520649d8c41692e306ceadec1e49182ee622a69eb24eb4211557c
|