Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7499331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:47:34+00:00 2026-05-29T19:47:34+00:00

I have a Django application in which I need to implement a simple trending/ranking

  • 0

I have a Django application in which I need to implement a simple trending/ranking algorithm. I’m very lost as a :

I have two models, Book and Reader. Every night, new books are added to my database. The number of readers for each book are updated too every night i.e. One book will have multiple reader statistic records (one record for each day).

Over a given period (past week, past month or past year), I would like to list the most popular books, what algorithm should I use for this?

The popularity doesn’t need to be realtime in any way because the reader count for each book is only updated daily.

I found one article which was referenced in another SO post that showed how they calculated trending Wikipedia articles but the post only showed how the current trend was calculated.

As someone pointed out on SO, it is a very simple baseline trend algorithm and only calculates the slope between two data points so I guess it shows the trend between yesterday and today.

I’m not looking for a uber complex trending algorithm like those used on Hacker News, Reddit, etc.

I have only two data axes, reader count and date.

Any ideas on what and how I should implement. For someone who’s never worked with anything statistics/algorithm related, this seems to be a very daunting undertaking.

Thanks in advance everyone.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T19:47:37+00:00Added an answer on May 29, 2026 at 7:47 pm

    Probably the simplest possible trending “algorithm” I can think of is the n-day moving average. I’m not sure how your data is structured, but say you have something like this:

    books = {'Twilight': [500, 555, 580, 577, 523, 533, 556, 593],
             'Harry Potter': [650, 647, 653, 642, 633, 621, 625, 613],
             'Structure and Interpretation of Computer Programs': [1, 4, 15, 12, 7, 3, 8, 19]
            }
    

    A simple moving average just takes the last n values and averages them:

    def moving_av(l, n):
        """Take a list, l, and return the average of its last n elements.
        """
        observations = len(l[-n:])
        return sum(l[-n:]) / float(observations)
    

    The slice notation simply grabs the tail end of the list, starting from the nth to last variable. A moving average is a fairly standard way to smooth out any noise that a single spike or dip could introduce. The function could be used like so:

    book_scores = {}
    for book, reader_list in books.iteritems():
        book_scores[book] = moving_av(reader_list, 5)
    

    You’ll want to play around with the number of days you average over. And if you want to emphasize recent trends you can also look at using something like a weighted moving average.

    If you wanted to focus on something that looks less at absolute readership and focuses instead on increases in readership, simply find the percent change in the 30-day moving average and 5-day moving average:

    d5_moving_av = moving_av(reader_list, 5)
    d30_moving_av = moving_av(reader_list, 30)
    book_score = (d5_moving_av - d30_moving_av) / d30_moving_av
    

    With these simple tools you have a fair amount of flexibility in how much you emphasize past trends and how much you want to smooth out (or not smooth out) spikes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two models in my Django application, for the purposes of storing search
I have two models in my Django 1.1.1 application: class UserRequest(models.Model): # blah blah
In my Django application, I have certain permissions which users need in order to
Sorry, a beginner's question: I have a very simple function in my Django application
I have an existing django application, with which I need to integrate django-cms. Django-cms
Hello I need to have multiple language support of my django admin application.I can
I'm working on a blog application in Django. Naturally, I have models set up
I have a a django application which is being served from apache/mod_wsgi under www.mysite.com/mysite
I want to have RSS feeds in my Django application, which should be viewable
In a django application I have the following model: class Appointment(models.Model): #some other fields

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.