Donmai

Statistics and You: A Quick and Dirty Workaround

Posted under General

Related to the conversation in topic #13045.

Anyways, I decided to go ahead and create something like I asked for in the above topic using a scripting language. It's quick and it's dirty, but it works well enough for me. If someone wants to spruce it up or throw up other examples from other programming languages, then please feel free to do so. ^__^

Note: The following was tested with Python 3.5 on Windows

Code
import statistics
import urllib.request
####VARIABLES####
# maxscore = highest score to search for (determine with order:score)
# username = login information for full API use (otherwise limit==2 tags)
# apikey = authentication info, generated from your user page
# searchtags = list of tags that determine statistics population
# duration = d=day,w=week,mo=month,y=year; see help:cheatsheet wiki for more details
##################
maxscore = 30
username = 'BrokenEagle98' #<----Enter your username here
apikey = 'ENTER_API_KEY_HERE'
searchtags = 'user:BrokenEagle98+girls_und_panzer' #<----Enter tags separated by '+'
duration = '..3mo'
##################
url=('http://danbooru.donmai.us/counts/posts.json?login=%s&api_key=%s&tags=%s+age:%s+score:%%d') % (username,apikey,searchtags,duration)
scores=[]
for x in range(0, maxscore):
	urlsubmit = url % x
	scores.extend([x] * int(((urllib.request.urlopen(urlsubmit)).read()).decode(encoding='utf-8')[21:-2]))

#MEAN
statistics.mean(scores)
#STANDARD DEVIATION
statistics.stdev(scores)
#FIRST QUARTILE (Q1)
scores[round(len(scores)/4)]
#MEDIAN (Q2)
statistics.median(scores)
#THIRD QUARTILE (Q3)
scores[3*round(len(scores)/4)]
1