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

  • Home
  • SEARCH
  • 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 8345813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:48:20+00:00 2026-06-09T06:48:20+00:00

I’m working on a time-decay algorithm for a post system based on Reddit’s model

  • 0

I’m working on a time-decay algorithm for a post system based on Reddit’s model here:
http://amix.dk/blog/post/19588

My working port is here:

public class Calculation
{
    protected DateTime Epoch = new DateTime(1970, 1, 1);

    protected long EpochSeconds(DateTime dt)
    {
        var ts = dt.Subtract(Convert.ToDateTime("1/1/1970 8:00:00 AM"));

        return ((((((ts.Days * 24) + ts.Hours) * 60) + ts.Minutes) * 60) + ts.Seconds);
    }

    protected int Score(int upVotes, int downVotes)
    {
        return upVotes - downVotes;
    }

    public double HotScore(int upVotes, int downVotes, DateTime date)
    {
        var s = Score(upVotes, downVotes);
        var order = Math.Log(Math.Max(Math.Abs(s), 1), 10);
        var sign = Math.Sign(s);
        var seconds = EpochSeconds(date) - 1134028003;
        return Math.Round(order + sign * ((double)seconds / 45000), 7);
    }
}

Based on the model output from the link provided, I should see gradual decay at 0-13 hours, and sharp decay after that.

What I’m seeing is very homogeneous decay, and scores much higher than the output from the original code (original code: 3480-3471).

Here is how I’m testing:

        Calculation c = new Calculation();
        double now = c.HotScore(100, 2, DateTime.Now);
        double fivehoursago = c.HotScore(100, 2, DateTime.Now.AddHours(-5));
        double tenhoursago = c.HotScore(100, 2, DateTime.Now.AddHours(-10));
        double elevenhoursago = c.HotScore(100, 2, DateTime.Now.AddHours(-11));
        double twelvehoursago = c.HotScore(100, 2, DateTime.Now.AddHours(-12));
        double thirteenhoursago = c.HotScore(100, 2, DateTime.Now.AddHours(-13));
        double fiftyhoursago = c.HotScore(100, 2, DateTime.Now.AddHours(-50));
        double onehundredhoursago = c.HotScore(100, 2, DateTime.Now.AddHours(-100));
        Console.WriteLine(now.ToString());
        Console.WriteLine(fivehoursago.ToString());
        Console.WriteLine(tenhoursago.ToString());
        Console.WriteLine(elevenhoursago.ToString());
        Console.WriteLine(twelvehoursago.ToString());
        Console.WriteLine(thirteenhoursago.ToString());
        Console.WriteLine(fiftyhoursago.ToString());
        Console.WriteLine(onehundredhoursago.ToString());
        Console.ReadLine();

Output values:

now:               4675.2993816
five hours:        4674.8993816
ten hours:         4674.4993816
eleven hours:      4674.4193816
twelve hours:      4674.3393816
thirteen hours:    4674.2593816
fifty hours:       4671.2993816
one-hundred hours: 4667.2993816

Clearly it’s SORT of working right, but something is off. It could be related to the lack of true *nix Epoch support, or the lack of analogous microseconds calculation, but something isn’t quite right.

Possible reference resources:
http://blogs.msdn.com/b/brada/archive/2004/03/20/93332.aspx
http://codeclimber.net.nz/archive/2007/07/10/convert-a-unix-timestamp-to-a-.net-datetime.aspx

  • 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-06-09T06:48:22+00:00Added an answer on June 9, 2026 at 6:48 am

    Your primary problem is that the hot algorithm is time dependent. Your calculating the hot score at DateTime.Now, whereas the article was written on 23. Nov 2010 (look at the bottom of the article).

    With some trial and error, it seems the data was calculated at approximately 2010-11-23 07:35. Try using that value rather than DateTime.Now, and you should get about the same results as the data in the graph shown.

    Mind you, you could make the following improvements to your code:

    public class Calculation
    {
        private static readonly DateTime Epoch = new DateTime(1970, 1, 1);
    
        private double EpochSeconds(DateTime dt)
        {
            return (dt - Epoch).TotalSeconds;
        }
    
        private int Score(int upVotes, int downVotes)
        {
            return upVotes - downVotes;
        }
    
        public double HotScore(int upVotes, int downVotes, DateTime date)
        {
            int s = Score(upVotes, downVotes);
            double order = Math.Log(Math.Max(Math.Abs(s), 1), 10);
            int sign = Math.Sign(s);
            double seconds = EpochSeconds(date) - 1134028003;
            return Math.Round(order + sign * seconds / 45000, 7);
        }
    }
    

    My results:

    3479.0956039
    3478.6956039
    3478.2956039
    3478.2156039
    3478.1356039
    3478.0556039
    3475.0956039
    3471.0956039
    

    Changes:

    • Used the declared Epoch rather than a convert of 1970-01-01 08:00:00 (I think 08:00 is a mistake).
    • You can subtract two dates using a - b; which is the same as a.Subtract(b) but more succinct and it mirrors the original Python code.
    • A timespan does give you microsecond precision (Ticks are the smallest unit and equal 100 nanoseconds).
    • Also, TotalSeconds gives you the total number of seconds within a time span; no need to recalculate that. The fractional part even gives you your microsecond precision.
    • By returning double from EpochSeconds, you keep this precision.
    • Made the data types explicit rather than var to clearly indicate what variable is what (they match the method signatures, so no implicit upcasting).
    • Changed unneeded protected to private and made the Epoch a constant.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I'm trying to create an if statement in PHP that prevents a single post
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.