This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
epsilon = .1; | |
n_trials = 1000; | |
counter = 0; | |
function test() { | |
//pick a random number between 1 and 10, inclusive | |
random_number = rand(1, 10); | |
//if the random number is within the epsilon percentage | |
if (random_number <= bandit.epsilon * 10) { | |
//simply picks a bandit at random |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<script src="http://d3js.org/d3.v2.js"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.21/jquery-ui.min.js"></script> | |
<h1>A D3.js Dashboard</h1> | |
<div id="metrics"></div> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var data = []; | |
// this is our data array | |
var startingDate = new Date(2012, 8, 18); | |
// this is a date object | |
for (var i = 0; i < 10; i++) { // loop 10 times to create 10 data objects | |
var tmpObj = {}; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getMaxObjectValue(this_array, element) { | |
var values = []; | |
for (var i = 0; i < this_array.length; i++) { | |
values.push(Math.ceil(parseFloat(this_array[i][""+element]))); | |
} | |
values.sort(function(a,b){return a-b}); | |
return values[values.length-1]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//size the visible area of the graph using the margin values | |
var width = 500, height = 500; | |
var margin = {top: 30, right: 10, bottom: 40, left: 60}, | |
width = width - margin.left - margin.right, | |
height = height - margin.top - margin.bottom; | |
var minDate = (data[0].date), | |
maxDate = data[data.length-1].date; | |
minObjectValue = getMinObjectValue(data, 'DAU'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var yAxis = d3.svg.axis() | |
.scale(y) | |
.orient("left") | |
.ticks(5); | |
var xAxis = d3.svg.axis() | |
.scale(x) | |
.orient("bottom") | |
.ticks(5); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var line = d3.svg.line() | |
.x(function(d) { return x(d["date"]); }) | |
.y(function(d) { return y(d["DAU"]); }) | |
vis.append("svg:path") | |
.attr("d", line(data)) | |
.style("stroke", function() { | |
return "#000000"; | |
}) | |
.style("fill", "none") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var dataCirclesGroup = vis.append('svg:g'); | |
var circles = dataCirclesGroup | |
.selectAll('.data-point') | |
.data(data); | |
circles | |
.enter() | |
.append('svg:circle') | |
.attr('class', 'dot') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getData() { | |
var data = []; | |
var metrics = | |
{ | |
"countries": | |
[ | |
{ | |
"country": "USA", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createAverages(metric) { | |
for (var i = 1; i < metric.length; i++) { | |
metric[i].d1_retention = safeDivide(metric[i].d1_retention, metric[i].DNU) * 100; | |
metric[i].d7_retention = safeDivide(metric[i].d7_retention, metric[i].DNU) * 100; | |
metric[i].d30_retention = safeDivide(metric[i].d30_retention, metric[i].DNU) * 100; | |
metric[i].average_session_length = safeDivide(metric[i].sessions_length, metric[i].sessions) / 60; | |
metric[i].average_sessions_per_user = safeDivide(metric[i].sessions, metric[i].DAU); | |
} | |
return metric; |
OlderNewer