Skip to content

Instantly share code, notes, and snippets.

View ESeufert's full-sized avatar

Eric Benjamin Seufert ESeufert

View GitHub Profile
$(document).ready(function() {
var data = getData();
data = createAverages(data);
buildLineChart(data, "Retention",
['d1_retention', 'd7_retention', 'd30_retention'],
1000, 300, "Date", "Retention (percentage)");
function getData() {
var data = [];
var metrics =
{
"countries":
[
{
"country": "USA",
function buildConsole(data) {
var html = "";
html += "<div id=\"country-selector\" class=\"console-element\">";
for (var i = 0; i < data.length; i++) {
html += "<div style=\"width: 150px; float: left;\">";
html += "<input name=\"countries\" id=\"country-selector-" + data[i][0] + "\" type=\"checkbox\" ";
if (i == 0) {
html += "checked"; // set the first country to checked to provide some default data for the graphs
}
function cloneData(data) {
//create a "deep copy" of the objects within the metrics array
//ensures that objects are not copied by reference
var metrics = [];
for (var i = 0; i < data.length; i++) {
metrics.push(cloneMetric(data[i]));
}
return metrics;
}
function aggregateMetric(metrics, countries) {
var metric = []; //the single metric array of dates that we'll return,
//aggregated over the selected countries
var count = 0; // a count of countries being aggregated over
for (var i = 0; i < metrics.length; i++) {
if (jQuery.inArray(metrics[i][0], countries) > -1) { //this is a country we should aggregate for
if (count == 0) {
metric = cloneMetric(metrics[i]); // since metric is empty, set metric to the first set of metrics we find
count++;
function resetCharts(metrics) {
var countries = getCountries(); // get checked items
var metric = aggregateMetric(metrics, countries); // build one metric item out of the selected countries and the full dataset
$('#metrics').html(''); // reset the metrics div html
buildLineChart(metric, "Retention", ['d1_retention_pct', 'd7_retention_pct', 'd30_retention_pct'], 1000, 300, "Date", "Retention (percentage)");
buildLineChart(metric, "Daily New Users", ['DNU'], 500, 300, "Date", "New Users");
buildLineChart(metric, "Daily Active Users", ['DAU'], 500, 300, "Date", "Users");
buildLineChart(metric, "Average Session Length", ['average_session_length'], 500, 300, "Date", "Session Length (minutes)");
buildLineChart(metric, "Average Sessions per User", ['average_sessions_per_user'], 500, 300, "Date", "Sessions per User");
$(document).ready(function() {
var data = getData();
buildConsole(data);
resetCharts(data);
$('#country-selector').change(function() {
var metrics = cloneData(data);
@ESeufert
ESeufert / LTV_and_Retention_Curves.py
Created January 14, 2019 16:44
Showcasing how LTV curves are dependent on Retention Curves
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import pandas as pd
import numpy as np
import random
def build_userbase( n, payer_percentage ):
users = pd.DataFrame( columns=[ "user", "payer", "payment_probability", "payment" ] )
for x in range( 1, n + 1 ):
payer = True if random.randint( 1, 100 ) <= ( payer_percentage * 100 ) else 0
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from sklearn.linear_model import Ridge
from sklearn.preprocessing import PolynomialFeatures
from sklearn.pipeline import make_pipeline
from scipy.optimize import curve_fit
import statsmodels.stats.api as sms
import math
import operator
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
import matplotlib.colors as pltcolors
import pandas as pd
import numpy as np
import random
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import colors as mcolors
from matplotlib import cm
from beautifultable import BeautifulTable