app_recommender.py 1.19 KB
Newer Older
1 2 3 4 5 6 7
#!/usr/bin/env python

import logging
import datetime

from apprecommender.recommender import Recommender
from apprecommender.user import LocalSystem
8
from apprecommender.config import Config
9 10 11 12 13


class AppRecommender:
    def __init__(self):
        self.recommender = Recommender()
14
        self.config = Config()
15

16 17
    def make_recommendation(self, reference_pkgs=None,
                            print_recommendation=True):
18 19
        begin_time = datetime.datetime.now()
        logging.info("Computation started at %s" % begin_time)
20

21 22 23 24
        if not reference_pkgs:
            reference_pkgs = []

        user = LocalSystem(reference_pkgs)
25
        recommendation_size = Config().num_recommendations
26
        user_recommendation = (self.recommender.get_recommendation(
27 28 29
                               user, recommendation_size))

        logging.info("Recommending applications for user %s" % user.user_id)
30 31
        if print_recommendation:
            print(user_recommendation)
32 33 34 35 36 37

        end_time = datetime.datetime.now()
        logging.info("Computation completed at %s" % end_time)
        delta = end_time - begin_time
        logging.info("Time elapsed: %d seconds." % delta.seconds)

38
        return user_recommendation