Skip to content

Instantly share code, notes, and snippets.

@apocalyptech
Created December 20, 2017 17:43
Show Gist options
  • Save apocalyptech/9a3edc71609a40429d41faf6fe71b8c1 to your computer and use it in GitHub Desktop.
Save apocalyptech/9a3edc71609a40429d41faf6fe71b8c1 to your computer and use it in GitHub Desktop.
Humble Indie Bundle release statistics
#!/usr/bin/env python
# vim: set expandtab tabstop=4 shiftwidth=4:
import datetime
import statistics
###
### 'statistics' is only available starting in Python 3.4, btw
###
###
### Output of run from after HIB16:
###
# Intervals found: 15 (HIBs: 16)
#
# Arithmetic mean: 141 days (4.7 months)
# Standard deviation: 57 days (1.9 months)
#
# Next HIB, if exactly at mean: July 13, 2016
# Next HIB, if exactly at mean+stddev: September 08, 2016
###
### Output of run from after HIB17:
###
# Intervals found: 16 (HIBs: 17)
#
# Arithmetic mean: 143 days (4.8 months)
# Standard deviation: 56 days (1.9 months)
#
# Next HIB, if exactly at mean: January 06, 2017
# Next HIB, if exactly at mean+stddev: March 03, 2017
###
### Output of run from after HIB18:
###
# Intervals found: 17 (HIBs: 18)
# 224, 224, 140, 170, 110, 92, 160, 106, 118, 42, 203, 39, 165, 181, 147, 175, 273
#
# Arithmetic mean: 151 days (5.0 months)
# Standard deviation: 62 days (2.1 months)
#
# Maximum HIB interval (between 17 and 18): 273 days (9.1 months)
# Current HIB interval, if released today: 0 days (0.0 months)
#
# Next HIB, if exactly at mean: October 14, 2017
# Next HIB, if exactly at mean+stddev: December 15, 2017
hibdates = [
'May 04, 2010', # 1
'December 14, 2010', # 2
'July 26, 2011', # 3
'December 13, 2011', # 4
'May 31, 2012', # 5
'September 18, 2012', # 6
'December 19, 2012', # 7
'May 28, 2013', # 8
'September 11, 2013', # 9
'January 07, 2014', # 10
'February 18, 2014', # 11
'September 09, 2014', # 12
'October 18, 2014', # 13
'April 01, 2015', # 14
'September 29, 2015', # 15
'February 23, 2016', # 16
'August 16, 2016', # 17
'May 16, 2017', # 18
]
intervals = []
date_fmt = '%B %d, %Y'
# Figure out how many days were inbetween each one
previous = None
max_interval = 0
max_hib = 1
for (idx, date) in enumerate(hibdates):
cur = datetime.datetime.strptime(date, date_fmt)
if previous is None:
previous = cur
continue
delta = cur - previous
if delta.days > max_interval:
max_interval = delta.days
max_hib = idx + 1
#print('Interval between %d and %d: %d days' % (idx, idx+1, delta.days))
intervals.append(delta.days)
previous = cur
# Find out how long it's been since the last one
current_delta = datetime.datetime.today() - datetime.datetime.strptime(hibdates[-1], date_fmt)
current_interval = current_delta.days
# Now report
mean = statistics.mean(intervals)
stddev = statistics.stdev(intervals)
print('')
print('Intervals found: %d (HIBs: %d)' % (len(intervals), len(intervals)+1))
print(', '.join([str(i) for i in intervals]))
print('')
print('Arithmetic mean: %d days (%0.1f months)' % (mean, mean/30))
print('Standard deviation: %d days (%0.1f months)' % (stddev, stddev/30))
# A bit more info
print('')
print('Maximum HIB interval (between %d and %d): %d days (%0.1f months)' % (max_hib-1, max_hib, max_interval, max_interval/30))
print('Current HIB interval, if released today: %d days (%0.1f months)' % (current_interval, current_interval/30))
# May as well project as well
next_mean = cur + datetime.timedelta(mean)
next_stddev = cur + datetime.timedelta(mean+stddev)
print('')
print('Next HIB, if exactly at mean: %s' % (datetime.datetime.strftime(next_mean, date_fmt)))
print('Next HIB, if exactly at mean+stddev: %s' % (datetime.datetime.strftime(next_stddev, date_fmt)))
print('')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment