def _on_review_stats_data(self, spawn_helper, piston_review_stats,
                              callback):
        """ process stdout from the helper """
        review_stats = self.REVIEW_STATS_CACHE

        if self._cache_version_old and self._server_has_histogram(
                piston_review_stats):
            self.REVIEW_STATS_CACHE = {}
            self.save_review_stats_cache_file()
            self.refresh_review_stats(callback)
            return

        # convert to the format that s-c uses
        for r in piston_review_stats:
            s = ReviewStats(Application("", r.package_name))
            s.ratings_average = float(r.ratings_average)
            s.ratings_total = float(r.ratings_total)
            if r.histogram:
                s.rating_spread = json.loads(r.histogram)
            else:
                s.rating_spread = [0, 0, 0, 0, 0]
            s.dampened_rating = calc_dr(s.rating_spread)
            review_stats[s.app] = s
        self.REVIEW_STATS_CACHE = review_stats
        callback(review_stats)
        self.emit("refresh-review-stats-finished", review_stats)
        self.save_review_stats_cache_file()
Beispiel #2
0
    def _on_review_stats_data(self, spawn_helper, piston_review_stats):
        """ process stdout from the helper """
        review_stats = self.REVIEW_STATS_CACHE

        if self._cache_version_old and self._server_has_histogram(
                piston_review_stats):
            self.REVIEW_STATS_CACHE = {}
            self.save_review_stats_cache_file()
            self.refresh_review_stats()
            return

        # convert to the format that s-c uses
        for r in piston_review_stats:
            s = ReviewStats(Application("", r.package_name))
            s.ratings_average = float(r.ratings_average)
            s.ratings_total = float(r.ratings_total)
            if r.histogram:
                s.rating_spread = json.loads(r.histogram)
            else:
                s.rating_spread = [0, 0, 0, 0, 0]
            s.dampened_rating = calc_dr(s.rating_spread)
            review_stats[s.app] = s
        self.REVIEW_STATS_CACHE = review_stats
        self.emit("refresh-review-stats-finished", review_stats)
        self.save_review_stats_cache_file()
def show_top_rated_apps():
    # get the ratings
    cache = get_pkg_info()
    loader = get_review_loader(cache)
    review_stats = loader.REVIEW_STATS_CACHE
    # recalculate using different default power
    results = {}
    for i in [0.5, 0.4, 0.3, 0.2, 0.1, 0.05]:
        for (key, value) in review_stats.iteritems():
            value.dampened_rating = calc_dr(value.rating_spread, power=i)
        top_rated = loader.get_top_rated_apps(quantity=25)
        print "For power: %s" % i
        for (i, key) in enumerate(top_rated):
            item = review_stats[key]
            print "%(rang)2i: %(pkgname)-25s avg=%(avg)1.2f total=%(total)03i dampened=%(dampened)1.5f spread=%(spread)s" % { 
                'rang' : i+1,
                'pkgname' : item.app.pkgname,
                'avg' : item.ratings_average,
                'total' : item.ratings_total,
                'spread' : item.rating_spread,
                'dampened' : item.dampened_rating,
                }
        print 
        results[i] = top_rated[:]
Beispiel #4
0
def show_top_rated_apps():
    # get the ratings
    cache = get_pkg_info()
    loader = get_review_loader(cache)
    review_stats = loader.REVIEW_STATS_CACHE
    # recalculate using different default power
    results = {}
    for i in [0.5, 0.4, 0.3, 0.2, 0.1, 0.05]:
        for (key, value) in review_stats.iteritems():
            value.dampened_rating = calc_dr(value.rating_spread, power=i)
        top_rated = loader.get_top_rated_apps(quantity=25)
        print "For power: %s" % i
        for (i, key) in enumerate(top_rated):
            item = review_stats[key]
            print "%(rang)2i: %(pkgname)-25s avg=%(avg)1.2f total=%(total)03i dampened=%(dampened)1.5f spread=%(spread)s" % {
                'rang': i + 1,
                'pkgname': item.app.pkgname,
                'avg': item.ratings_average,
                'total': item.ratings_total,
                'spread': item.rating_spread,
                'dampened': item.dampened_rating,
            }
        print
        results[i] = top_rated[:]