@cronjobs.register
def cache_most_unhelpful_kb_articles():

    REDIS_KEY = settings.HELPFULVOTES_UNHELPFUL_KEY

    old_formatted = _get_old_unhelpful()
    final = _get_current_unhelpful(old_formatted)

    if final == {}:
        return

    def _mean(vals):
        """Argument: List of floats"""
        if len(vals) == 0:
            return None
        return sum(vals) / len(vals)

    def _bayes_avg(C, m, R, v):
        # Bayesian Average
        # C = mean vote, v = number of votes,
        # R = mean rating, m = minimum votes to list in topranked
        return (C * m + R * v) / (m + v)

    mean_perc = _mean([float(final[key]['currperc']) for key in final.keys()])
    mean_total = _mean([float(final[key]['total']) for key in final.keys()])

    #  TODO: Make this into namedtuples
    sorted_final = [(key,
                     final[key]['total'],
                     final[key]['currperc'],
                     final[key]['diffperc'],
                     _bayes_avg(mean_perc, mean_total,
                                final[key]['currperc'],
                                final[key]['total']))
                    for key in final.keys()]
    sorted_final.sort(key=lambda entry: entry[4])  # Sort by Bayesian Avg

    redis = redis_client('helpfulvotes')

    redis.delete(REDIS_KEY)

    max_total = max([b[1] for b in sorted_final])

    for entry in sorted_final:
        doc = Document.objects.get(pk=entry[0])
        redis.rpush(REDIS_KEY, (u'%s::%s::%s::%s::%s::%s::%s' %
                                (entry[0],  # Document ID
                                 entry[1],  # Total Votes
                                 entry[2],  # Current Percentage
                                 entry[3],  # Difference in Percentage
                                 1 - (entry[1] / max_total),  # Graph Color
                                 doc.slug,  # Document slug
                                 doc.title)))  # Document title
Write a list of elements.
dataset/ETHPy150Open mozilla/kitsune/kitsune/dashboards/cron.py/cache_most_unhelpful_kb_articles--crossover with--dataset/ETHPy150Open sdispater/cleo/cleo/commands/command.py/Command.list