Commit 8ad9f066350ba4d4e85787e8da32f795313520fa
1 parent
bdc5a4e1
Exists in
master
and in
1 other branch
Profile strategy that ignores auto-installed packages.
Small fix on how packages list populates user's item_score dict. It was missing any package that has 'install' in its name.
Showing
2 changed files
with
18 additions
and
4 deletions
Show diff stats
src/app_recommender.py
| ... | ... | @@ -37,6 +37,7 @@ if __name__ == '__main__': |
| 37 | 37 | cfg = Config() |
| 38 | 38 | rec = Recommender(cfg) |
| 39 | 39 | user = LocalSystem() |
| 40 | + user.maximal_pkg_profile() | |
| 40 | 41 | |
| 41 | 42 | begin_time = datetime.datetime.now() |
| 42 | 43 | logging.debug("Recommendation computation started at %s" % begin_time) | ... | ... |
src/user.py
| ... | ... | @@ -20,6 +20,7 @@ |
| 20 | 20 | import commands |
| 21 | 21 | import xapian |
| 22 | 22 | import logging |
| 23 | +import apt | |
| 23 | 24 | |
| 24 | 25 | class FilterTag(xapian.ExpandDecider): |
| 25 | 26 | def __call__(self, term): |
| ... | ... | @@ -30,15 +31,26 @@ class FilterTag(xapian.ExpandDecider): |
| 30 | 31 | |
| 31 | 32 | class User: |
| 32 | 33 | """ """ |
| 33 | - def __init__(self,item_score,user_id=0,demo_profile=0): | |
| 34 | + def __init__(self,item_score,user_id=0,demographic_profile=0): | |
| 34 | 35 | """ """ |
| 35 | 36 | self.id = user_id |
| 36 | 37 | self.item_score = item_score |
| 37 | - self.demo_profile = demo_profile | |
| 38 | + self.demographic_profile = demographic_profile | |
| 38 | 39 | |
| 39 | 40 | def items(self): |
| 40 | 41 | return self.item_score.keys() |
| 41 | 42 | |
| 43 | + def maximal_pkg_profile(self): | |
| 44 | + cache = apt.Cache() | |
| 45 | + old_profile_size = len(self.item_score) | |
| 46 | + for p in self.item_score.keys(): | |
| 47 | + pkg = cache[p] | |
| 48 | + if pkg.is_auto_installed: | |
| 49 | + del self.item_score[p] | |
| 50 | + profile_size = len(self.item_score) | |
| 51 | + logging.info("Reduced packages profile size from %d to %d." % | |
| 52 | + (old_profile_size, profile_size)) | |
| 53 | + | |
| 42 | 54 | def axi_tag_profile(self,apt_xapian_index,profile_size): |
| 43 | 55 | terms = [] |
| 44 | 56 | for item in self.items(): |
| ... | ... | @@ -65,6 +77,7 @@ class LocalSystem(User): |
| 65 | 77 | def __init__(self): |
| 66 | 78 | item_score = {} |
| 67 | 79 | dpkg_output = commands.getoutput('/usr/bin/dpkg --get-selections') |
| 68 | - for p in dpkg_output.replace('install','\t').split(): | |
| 69 | - item_score[p] = 1 | |
| 80 | + for line in dpkg_output.splitlines(): | |
| 81 | + pkg = line.split('\t')[0] | |
| 82 | + item_score[pkg] = 1 | |
| 70 | 83 | User.__init__(self,item_score) | ... | ... |