Skip to content

Instantly share code, notes, and snippets.

@luke14free
Created September 14, 2015 14:52
Show Gist options
  • Save luke14free/fc695977b5dcffb16b70 to your computer and use it in GitHub Desktop.
Save luke14free/fc695977b5dcffb16b70 to your computer and use it in GitHub Desktop.
Generate pseudo logs for BS test
from scipy import stats
import pandas as pd
randgen = lambda n: [1 if i > .5 else 0 for i in stats.gamma.rvs(1, scale=0.7, size=n) > .5]
def truncate(l, n):
try:
ls = "".join(map(str, l))
idx = ls.index("".join(map(str, [0] * n)))
return l[:idx] + [0] * (len(l) - idx)
except ValueError:
return l
def generate_logs(days=90, users=1000, max_lazyness=5):
d = {i: truncate(randgen(days), max_lazyness) for i in range(users)}
logs = pd.DataFrame.from_dict(d).transpose()
logs.columns = ['Day ' + str(i) for i in range(1, days + 1)]
logs.index.name = "User ID"
return logs
generate_logs().to_csv("logs.csv")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment