~mmcg069/software-center/bug855666

« back to all changes in this revision

Viewing changes to softwarecenter/db/database.py

  • Committer: Michael Vogt
  • Date: 2011-07-21 15:28:53 UTC
  • Revision ID: michael.vogt@ubuntu.com-20110721152853-isdwy3wd800y9xd1
add top rated carousel

Show diffs side-by-side

added added

removed removed

Lines of Context:
77
77
    def __call__(self, doc):
78
78
        return locale.strxfrm(doc.get_value(self.db._axi_values["display_name"]))
79
79
 
 
80
class TopRatedSorter(xapian.KeyMaker):
 
81
    """ Sort using the top rated data """
 
82
    def __init__(self, db, review_loader):
 
83
        super(TopRatedSorter, self).__init__()
 
84
        self.db = db
 
85
        self.review_loader = review_loader
 
86
    def __call__(self, doc):
 
87
        app = Application(self.db.get_appname(doc),
 
88
                          self.db.get_pkgname(doc))
 
89
        stats = self.review_loader.get_review_stats(app)
 
90
        import xapian
 
91
        if stats:
 
92
            return xapian.sortable_serialise(stats.dampened_rating)
 
93
        return xapian.sortable_serialise(0)
80
94
 
81
95
def parse_axi_values_file(filename="/var/lib/apt-xapian-index/values"):
82
96
    """ parse the apt-xapian-index "values" file and provide the