Commit c93445bc60a545feff2493cbbe5ba82d821d85a5
1 parent
8ad9f066
Exists in
master
and in
1 other branch
Created pkg_profile to save selected packages, preserving original item_score
dict for future enquiries.
Showing
1 changed file
with
7 additions
and
6 deletions
Show diff stats
src/user.py
... | ... | @@ -35,6 +35,7 @@ class User: |
35 | 35 | """ """ |
36 | 36 | self.id = user_id |
37 | 37 | self.item_score = item_score |
38 | + self.pkg_profile = self.item_score.keys() | |
38 | 39 | self.demographic_profile = demographic_profile |
39 | 40 | |
40 | 41 | def items(self): |
... | ... | @@ -42,18 +43,18 @@ class User: |
42 | 43 | |
43 | 44 | def maximal_pkg_profile(self): |
44 | 45 | cache = apt.Cache() |
45 | - old_profile_size = len(self.item_score) | |
46 | - for p in self.item_score.keys(): | |
46 | + old_profile_size = len(self.pkg_profile) | |
47 | + for p in self.pkg_profile[:]: #iterate list copy | |
47 | 48 | pkg = cache[p] |
48 | 49 | if pkg.is_auto_installed: |
49 | - del self.item_score[p] | |
50 | - profile_size = len(self.item_score) | |
50 | + self.pkg_profile.remove(p) | |
51 | + profile_size = len(self.pkg_profile) | |
51 | 52 | logging.info("Reduced packages profile size from %d to %d." % |
52 | 53 | (old_profile_size, profile_size)) |
53 | 54 | |
54 | 55 | def axi_tag_profile(self,apt_xapian_index,profile_size): |
55 | 56 | terms = [] |
56 | - for item in self.items(): | |
57 | + for item in self.pkg_profile: | |
57 | 58 | terms.append("XP"+item) |
58 | 59 | query = xapian.Query(xapian.Query.OP_OR, terms) |
59 | 60 | enquire = xapian.Enquire(apt_xapian_index) |
... | ... | @@ -69,7 +70,7 @@ class User: |
69 | 70 | return profile |
70 | 71 | |
71 | 72 | def txi_tag_profile(self,tags_xapian_index,profile_size): |
72 | - return tags_xapian_index.relevant_tags_from_db(self.items(), | |
73 | + return tags_xapian_index.relevant_tags_from_db(self.pkg_profile, | |
73 | 74 | profile_size) |
74 | 75 | |
75 | 76 | class LocalSystem(User): | ... | ... |