コード例 #1
0
ファイル: test_user.py プロジェクト: GCS2016/AppRecommender
class LocalSystemTest(unittest.TestCase):
    def setUp(self):
        self.user = LocalSystem()

    def test_get_time_score_invalid_file(self):
        result = self.user.get_time_score('invalid_path')

        self.assertFalse(result)
        self.assertEqual(len(result), 0)
コード例 #2
0
    def get_user(self, no_auto_pkg_profile):
        config = Config()

        user = LocalSystem()
        user.filter_pkg_profile(os.path.join(config.filters_dir,
                                             "desktopapps"))
        user.maximal_pkg_profile()

        if no_auto_pkg_profile:
            user.no_auto_pkg_profile()

        return user
コード例 #3
0
ファイル: test_user.py プロジェクト: GCS2016/AppRecommender
class LocalSystemTest(unittest.TestCase):

    def setUp(self):
        self.user = LocalSystem()

    def test_get_time_score_invalid_file(self):
        result = self.user.get_time_score('invalid_path')

        self.assertFalse(result)
        self.assertEqual(len(result), 0)
コード例 #4
0
    def get_user(self, no_auto_pkg_profile):
        config = Config()

        user = LocalSystem()
        user.filter_pkg_profile(
            os.path.join(config.filters_dir, "desktopapps"))
        user.maximal_pkg_profile()

        if no_auto_pkg_profile:
            user.no_auto_pkg_profile()

        return user
コード例 #5
0
    def create_pkg_data(self):
        user = LocalSystem()
        user.maximal_pkg_profile()
        user.no_auto_pkg_profile()
        user_pkgs = user.pkg_profile

        pkgs_time = self.get_packages_time(user_pkgs)
        self.save_package_time(pkgs_time)
        return pkgs_time
コード例 #6
0
 def reset(self, params, rep):
     if params['name'].startswith("content"):
         cfg = Config()
         # if the index was not built yet
         # app_axi = AppAptXapianIndex(cfg.axi,"results/arnaldo/AppAxi")
         cfg.axi = "data/AppAxi"
         cfg.index_mode = "old"
         cfg.weight = params['weight']
         self.rec = Recommender(cfg)
         self.rec.set_strategy(params['strategy'])
         self.repo_size = self.rec.items_repository.get_doccount()
         self.user = LocalSystem()
         self.user.app_pkg_profile(self.rec.items_repository)
         self.sample_size = int(
             len(self.user.pkg_profile) * params['sample'])
コード例 #7
0
class LocalSystemTest(unittest.TestCase):

    def setUp(self):
        self.user = LocalSystem()

    @patch('commands.getoutput')
    @patch('glob.glob', return_value=['test'])
    def test_get_apt_installed_pkgs(self, mock_glob, mock_command):
        mock_command.return_value = 'Commandline: apt install test1 test2\n'
        apt_pkgs = self.user.get_apt_installed_pkgs()

        self.assertEqual(2, len(apt_pkgs))
        self.assertIn('test1', apt_pkgs)
        self.assertIn('test2', apt_pkgs)

        mock_command.return_value = 'Commandline: apt remove test1 test2\n'
        apt_pkgs = self.user.get_apt_installed_pkgs()

        self.assertEqual(0, len(apt_pkgs))

        mock_command.return_value = 'Commandline: apt upgrade\n'
        apt_pkgs = self.user.get_apt_installed_pkgs()

        self.assertEqual(0, len(apt_pkgs))
コード例 #8
0
import sys

sys.path.insert(0, '../')
import logging
import datetime

from apprecommender.config import Config
from apprecommender.recommender import Recommender
from apprecommender.user import LocalSystem
from apprecommender.error import Error

if __name__ == '__main__':
    try:
        cfg = Config()
        rec = Recommender(cfg)
        user = LocalSystem()
        user.no_auto_pkg_profile()
        # user.maximal_pkg_profile()

        begin_time = datetime.datetime.now()
        logging.debug("Recommendation computation started at %s" % begin_time)

        print rec.get_recommendation(user)

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

    except Error:
        logging.critical("Aborting proccess. Use '--debug' for more details.")
コード例 #9
0
ファイル: test_user.py プロジェクト: GCS2016/AppRecommender
 def setUp(self):
     self.user = LocalSystem()
コード例 #10
0
import logging
import datetime

from apprecommender.config import Config
from apprecommender.evaluation import (Precision, Recall, F1, Accuracy,
                                       SimpleAccuracy, CrossValidation)
from apprecommender.recommender import Recommender
from apprecommender.user import LocalSystem
from apprecommender.error import Error

if __name__ == '__main__':
    try:
        cfg = Config()
        rec = Recommender(cfg)
        print "\nRecommender strategy: ", rec.strategy.description
        user = LocalSystem()
        # user.app_pkg_profile(rec.items_repository)
        user.no_auto_pkg_profile()
        begin_time = datetime.datetime.now()
        logging.debug("Cross-validation started at %s" % begin_time)

        metrics = []
        metrics.append(Precision())
        metrics.append(Recall())
        metrics.append(F1())
        metrics.append(Accuracy())
        metrics.append(SimpleAccuracy())
        validation = CrossValidation(0.9, 10, rec, metrics, 0.1)
        validation.run(user)
        print validation
コード例 #11
0
class ContentBasedSuite(expsuite.PyExperimentSuite):

    def reset(self, params, rep):
        if params['name'].startswith("content"):
            cfg = Config()
            # if the index was not built yet
            # app_axi = AppAptXapianIndex(cfg.axi,"results/arnaldo/AppAxi")
            cfg.axi = "data/AppAxi"
            cfg.index_mode = "old"
            cfg.weight = params['weight']
            self.rec = Recommender(cfg)
            self.rec.set_strategy(params['strategy'])
            self.repo_size = self.rec.items_repository.get_doccount()
            self.user = LocalSystem()
            self.user.app_pkg_profile(self.rec.items_repository)
            self.sample_size = int(
                len(self.user.pkg_profile) * params['sample'])
            # iteration should be set to 10 in config file
            # self.profile_size = range(10,101,10)

    def iterate(self, params, rep, n):
        if params['name'].startswith("content"):
            item_score = dict.fromkeys(self.user.pkg_profile, 1)
            # Prepare partition
            sample = {}
            for i in range(self.sample_size):
                key = random.choice(item_score.keys())
                sample[key] = item_score.pop(key)
            # Get full recommendation
            user = User(item_score)
            recommendation = self.rec.get_recommendation(user, self.repo_size)
            # Write recall log
            recall_file = "results/content/recall/%s-%s-%.2f-%d" % \
                          (params['strategy'], params[
                           'weight'], params['sample'], n)
            output = open(recall_file, 'w')
            output.write("# weight=%s\n" % params['weight'])
            output.write("# strategy=%s\n" % params['strategy'])
            output.write("# sample=%f\n" % params['sample'])
            output.write("\n%d %d %d\n" %
                         (self.repo_size, len(item_score), self.sample_size))
            notfound = []
            ranks = []
            for pkg in sample.keys():
                if pkg in recommendation.ranking:
                    ranks.append(recommendation.ranking.index(pkg))
                else:
                    notfound.append(pkg)
            for r in sorted(ranks):
                output.write(str(r) + "\n")
            if notfound:
                output.write("Out of recommendation:\n")
                for pkg in notfound:
                    output.write(pkg + "\n")
            output.close()
            # Plot metrics summary
            accuracy = []
            precision = []
            recall = []
            f1 = []
            g = Gnuplot.Gnuplot()
            g('set style data lines')
            g.xlabel('Recommendation size')
            for size in range(1, len(recommendation.ranking) + 1, 100):
                predicted = RecommendationResult(
                    dict.fromkeys(recommendation.ranking[:size], 1))
                real = RecommendationResult(sample)
                evaluation = Evaluation(predicted, real, self.repo_size)
                accuracy.append([size, evaluation.run(Accuracy())])
                precision.append([size, evaluation.run(Precision())])
                recall.append([size, evaluation.run(Recall())])
                f1.append([size, evaluation.run(F1())])
            g.plot(Gnuplot.Data(accuracy, title="Accuracy"),
                   Gnuplot.Data(precision, title="Precision"),
                   Gnuplot.Data(recall, title="Recall"),
                   Gnuplot.Data(f1, title="F1"))
            g.hardcopy(recall_file + "-plot.ps", enhanced=1, color=1)
            # Iteration log
            result = {'iteration': n,
                      'weight': params['weight'],
                      'strategy': params['strategy'],
                      'accuracy': accuracy[20],
                      'precision': precision[20],
                      'recall:': recall[20],
                      'f1': f1[20]}
            return result
コード例 #12
0
 def setUp(self):
     self.user = LocalSystem()