Mean Reputation Change

7

2

Challenge

Given a the ID for a PPCG user who has existed for at least a month, output the average amount of reputation they gain per month. You can do this by dividing their reputation by the time since their account was created (which you can find on the profile). This should be returned floored; that is, truncate all of the decimals. (We don't care about the small stuff).

Input

A single integer, which is the user's ID

Output

A single integer, representing the floored rep change per month.

Test Cases

input -> output
42649 -> 127 (me)
12012 -> 3475 (Dennis)
8478  -> 3015 (Martin Ender)

HyperNeutrino

Posted 2017-05-05T03:41:46.287

Reputation: 26 575

4Can you define what a month is considered to be - a calendar month, a lunar month or 30 days? Or is it at our discretion? – Shaggy – 2017-05-05T07:27:12.143

@Shaggy When you go to a user profile, under the profile tab, it says "User for <x time>". Go by that. – HyperNeutrino – 2017-05-10T17:46:07.730

@HyperNeutrino so the formula is (rep/daysSinceAccountCreate)*30? You need to give us a constant for what a month is. – Sirens – 2017-05-11T17:39:22.100

@Sirens Go here and Ctrl-F for 1 year, 9 months. That's what I mean.

– HyperNeutrino – 2017-05-11T18:10:12.277

Should a check that the user has existed for at least a month be included? – DimP – 2017-05-18T13:02:16.980

@DimP I will say you can assume that. – HyperNeutrino – 2017-05-18T13:03:25.930

Answers

2

JS, ES6 243 235 168 166 165 164 bytes

i=>fetch(`//api.stackexchange.com/users/${i}?site=codegolf`).then(x=>x.json()).then(x=>alert(~~((y=x.items[0]).reputation/((new Date/1e3-y.creation_date)/2592e3))))

Based on the Python answer.

Run this in the console:

(i=>fetch(`//api.stackexchange.com/users/${i}?site=codegolf`).then(x=>x.json()).then(x=>alert(~~((y=x.items[0]).reputation/((new Date/1e3-y.creation_date)/2592e3)))))(+prompt("Enter a userId"))

-4 thanks to @insert_name_here

Old answer:

z=>fetch("//codegolf.stackexchange.com/u/"+z).then(x=>x.text()).then(x=>alert((/([\d,]+) <span class="label-uppercase">repu/.exec(x)[1].replace(/,/g,"")/(((y=/Member for <.+>((\d+) years?, )?(\d+) month/.exec(x))[2]||0)*12+ +y[3]||0))))

Improvements welcome! Just fetches the profile page and parses it with regular expressions!

Won't work as a stack snippet, but you can paste this in your console:

(z=>fetch("//codegolf.stackexchange.com/u/"+z).then(x=>x.text()).then(x=>alert(Math.floor(/([\d,]+) <span class="label-uppercase">repu/.exec(x)[1].replace(/,/g,"")/(((y=/Member for <.+>((\d+) years?, )?(\d+) month/.exec(x))[2]||0)*12+ +y[3]||0)))))(+prompt("Enter a userId"))

programmer5000

Posted 2017-05-05T03:41:46.287

Reputation: 7 828

1Okay :) You have a much higher rep change than me D: I think about double – HyperNeutrino – 2017-05-18T13:25:08.633

You could save two bytes by using new Date instead of Date.now(). You could also save one more by using 1e3 instead of 1000 and another by using 2592e3 instead of 2592000. – insert_name_here – 2017-05-18T14:22:50.253

1

Python 3 2, 206 219 201 193 bytes

import requests,time
a=requests.get('http://api.stackexchange.com/users/'+str(input())+'?site=codegolf').json()['items'][0]
print a['reputation']/((int(time.time())-a['creation_date'])/2592000)

I am estimating the months as the OP suggested, but actually print(int(b/((d-c)/2592000))) is a more accurate solution than print(int(b/int((d-c)/2592000))) and also saves a few bytes.

DimP

Posted 2017-05-05T03:41:46.287

Reputation: 251

get is not defined – HyperNeutrino – 2017-05-18T13:17:38.947

@HyperNeutrino try it again now, should work (Python 2). Obviously needs requests. – DimP – 2017-05-18T13:41:43.257