Skip to content

Instantly share code, notes, and snippets.

@adeak
Created March 3, 2018 13:20
Show Gist options
  • Save adeak/8518d64b5177dccc7122696746941f36 to your computer and use it in GitHub Desktop.
Save adeak/8518d64b5177dccc7122696746941f36 to your computer and use it in GitHub Desktop.
rep of wim vs user2357112 based on wim's script
from datetime import datetime
import numpy as np
from scipy import optimize as opt
from matplotlib import pyplot as plt
import requests
def parser(text):
xs = []
ys = []
for line in text.splitlines():
if line == '-- bonuses (100)':
continue
dashes, date_str, rep, delta, equals, total = line.split()
xs.append(datetime.strptime(date_str, '%Y-%m-%d').date())
ys.append(int(total))
return np.array(xs), np.array(ys)
wx, wy = parser(requests.get('https://pastebin.com/raw/mEqNkR4K').text)
kx, ky = parser(requests.get('https://pastebin.com/raw/D0pFWcyv').text)
maxlen = max(wx.size,kx.size)
fig,ax = plt.subplots()
ax.plot(wx, wy, 'r-')
ax.plot(kx, ky, 'b-')
ax.set_title('Raw rep')
# filter common datapoints
commondays = np.intersect1d(wx, kx, assume_unique=True)
def filt(arrx, arry, commons):
inds = np.isin(arrx, commons, assume_unique=True)
return arrx[inds], arry[inds]
wx, wy = filt(wx, wy, commondays)
kx, ky = filt(kx, ky, commondays)
days = np.array([delta.days for delta in wx - wx[-1]])
# get slope
numsamples = 150
(slope,_),pcov = opt.curve_fit(lambda d,a,b:a*d+b, days[-numsamples:], (wy + ky)[-numsamples:]/2, p0=(200,1))
print(f'slope: {slope}/day')
capshift = slope*days
fig,ax = plt.subplots()
ax.plot(wx, wy - capshift, 'r-')
ax.plot(kx, ky - capshift, 'b-')
ax.set_title('Common days shifted by final slope')
fig,ax = plt.subplots()
ax.plot(wx, wy - ky, 'g-')
ax.grid()
ax.set_title('wim - user2357112')
# number of crossings; ignore near brushes
inds = wy != ky
numcross = np.abs(np.diff(wy[inds] > ky[inds])).sum()
print(f'Number of crossings: {numcross}')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment