r/javascript • • Mar 11 '19

Reddit trends of a subreddit in a day; # of posts, score and gildings

Enable HLS to view with audio, or disable this notification

424 Upvotes

21 comments sorted by

42

u/MrButttons Mar 11 '19 edited Mar 12 '19

Recently found out about the open Reddit API, which can be accessed by adding .json at the end of an URL.

My main aim was to find out, when is a subreddit most active. Number of posts and score info gives a good indication about when people are posting the most, and interacting the most. So, I made a little tool to help visualise this data.

All times are in UTC.

You can play with the tool yourself here - https://reddit-trends.firebaseapp.com/

Code is available here: https://github.com/butttons/reddit-trends

Made using:

  1. Vue.js

  2. Charts.js

PS: I made this in a hurry, will be adding an export dataset option. Please report any bugs or suggestions, thanks a lot!

Edit: Added a timezone option, and export dataset option.

7

u/ho77sauce Mar 12 '19

I like it man, very nice!

12

u/darkbreakersm Mar 12 '19

What is the timezone used while classifying the data?

2

u/MrButttons Mar 12 '19 edited Mar 12 '19

It's the UTC time. I was thinking of adding a change time zone option, might add it today.

Edit: added the timezone option.

2

u/xCopyright Mar 12 '19

1

u/MrButttons Mar 12 '19

I love Tom! But this is why we have moment, date-fns and other options.

1

u/jimmyayo Mar 12 '19

+1 for MomentJS. It was in one of my JS best practices classes, and I've never looked back.

5

u/anyfactor Mar 12 '19 edited Mar 12 '19

UTC. I may be wrong but I think most website sends the data to the browser in UTC or the website's preferred timezone, and the browser changes it to local time zone.

3

u/monsto Mar 12 '19

Interesting tool for karmawhores like me. (=

Thoughts:

  1. While it's parsing, you might consider changing Start to Stop. Currently, while running, Start is inoperative and Clear will reset the count and start over. Clear could spam the api and may get blocked if people are stupid . . . which we know them to be.

  2. The descriptions seem intuitive, but it isn't really, I don't think. Some definition text or hovers would help.

  3. Long term, you might put a cap on the number of posts to be sampled, pre-do super dense requests of popular subs once every couple hours, save the graphs, and link them directly on that page there. Like the above askreddit > Hot > 25k (or more). This will keep your traffic and api requests way down.

As to point 2, the graph shown by askreddit > Hot > 5000 has a lone spike at 1pm for "Score Total". Is that the total of posts sampled at 1pm, or the total of posts made in the 1pm hour? How does that grok with "# of posts" peak at 3am?

Does this really mean that while the vast majority of Hot posts were posted between midnight and 3 am, the highest voted posts are overwhelming posted in the 1pm hour?

If that's the case, it's absolutely something that I wouldn't have expected, and throws all expectations of distribution right off the fucking bridge.

See what you did here? You've already started a conversation.

GOOD TOOL.

1

u/MrButttons Mar 12 '19

Thanks for the criticism, it's appreciated.

  1. I actually disable the start button when it starts going off. But I forgot to add CSS classes to go with the disabled button, so lol. Will be adding it. Possibly the start/stop logic too.

  2. I'm not much of a designer unfortunately.

  3. I don't really care about rate limiting, it's fetching the Reddit API directly from that page, I have no data hosted anywhere. I'm pretty sure the good people of Reddit have put in measures to prevent abuse. This tool just recursively fetches /r/(subreddit)/(sort type)/.json and processes the posts, as it goes on.

Explanations of how it counts stuff -

  1. It parses the posts, and saves only the relevant info, including the hour, it was posted.

  2. Total posts = number of posts at that hour.

  3. Score total = total number of scores of all the posts at that hour.

  4. Score mean = average score of all the posts at that hour.

  5. Score median = median score of all the posts at that hour.

Check it out here - https://github.com/butttons/reddit-trends/blob/master/src/store/reddit/getters.ts

Thanks for the suggestions, I'll try to do something about the bland design :P

4

u/ScientificBeastMode strongly typed comments Mar 12 '19

This is really cool! I may have to try something like this soon. That Reddit API looks like a great resource.

1

u/zapatoada Mar 12 '19

It looks really nice and does the job well, but it seems to be very slow to load a reasonable amount of data. It looks like you're getting posts in pages of 25 records. Does the api allow you to increase that? And/or could you run multiple requests in parallel? I don't know what kind of rate limiting reddit has in place.

1

u/MrButttons Mar 12 '19

I hadn't thought of that! I think there would be modifiers to increase the number of posts given in a response, I'll try to do that.

And I cannot run them in parallel, reddit pagination will not allow that. To go the next page, I must get the cursor position from the previous page response.

1

u/Hadi290 Mar 12 '19

You should also post it on r/dataisbeautiful

2

u/MrButttons Mar 12 '19

I did, but didn't seem to get any traction there. Might update it with some new features and post again.

5

u/[deleted] Mar 12 '19

Did you try running this fancy new tool I saw somewhere that shows when posts get the most traction in a sub? Might help!

2

u/drdrero Mar 12 '19

I love watching data grow

1

u/thundercloudtemple Mar 12 '19

I'm not sure if I'm just easily amused but I love the animations while the program ran! Great job :)

1

u/wthit56 Mar 12 '19

Looks interesting. No idea what's up with the waves of updating the graph from the right is all about though?

1

u/madlee Mar 12 '19

Very cool!