forked from lukasvermeer/confidence
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
664 lines (616 loc) · 39.8 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>So You Think You Can Test? - Simulation-mode</title>
<link rel="stylesheet" href="bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="confidence.css">
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-105998856-2', 'auto');
ga('send', 'pageview');
</script>
</head>
<body>
<div id="app-confidence" class="container">
<div class="modal" id="help" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-body">
<h1 class="text-center">How to play</h1>
<div class="alert alert-warning">
<p class="text-justify"><strong>Warning:</strong> This game is still in active development. Your experience may change as I add new functionality and tweak features to enhance realism. I will strive to keep these instructions updated as the game evolves.</p>
<p class="text-center"><a href="http://lukasvermeer.nl/#contact" target="_blank">Feedback or ideas are very welcome. <span class="glyphicon glyphicon-envelope" aria-hidden="true"></span></a></p>
</div>
<h3>Objective</h3>
<p class="text-justify">You control the backlog and running experiments for a small development team. Each day you make decisions that impact product development and overall sales.</p>
<p class="text-justify">Your current progress is displayed at the top of the screen. Once you are done for the day, click <button type="button" class="btn btn-primary btn-xs">proceed to next day</button> to move the simulation forward.</p>
<p class="text-justify">After <code>{{settings.game_duration}}</code> days, the game is over and your final score is computed based on total sales.</p>
<p class="text-center lead">Your objective is to maximise total sales.</p>
<h3>Backlog</h3>
<p class="text-justify">Your teams maintains a simplified backlog. Different tasks can be prioritised or deleted entirely. If nothing is prioritised, your team will pick up a random task when needed.</p>
<p class="text-justify">Each task has visible and invisible properties, depending on the <code>feedback level</code>.</p>
<dl>
<dt>Topics</dt>
<dd>
<p class="text-justify">
Each task is related to one of 5 different topics:
<span class="label label-primary" :style="{ background: backlog_colors[0] }">{{backlog_topics[0]}}</span>,
<span class="label label-primary" :style="{ background: backlog_colors[1] }">{{backlog_topics[1]}}</span>,
<span class="label label-primary" :style="{ background: backlog_colors[2] }">{{backlog_topics[2]}}</span>,
<span class="label label-primary" :style="{ background: backlog_colors[3] }">{{backlog_topics[3]}}</span>, or
<span class="label label-primary" :style="{ background: backlog_colors[4] }">{{backlog_topics[4]}}</span>.
Different topics share different underlying probabilities of success and effect sizes.
<p class="text-justify">
This means that all tasks of topic <span class="label label-primary" :style="{ background: backlog_colors[0] }">{{backlog_topics[0]}}</span> will tend to show similar results.
These settings are randomised each playthrough, so that <span class="label label-primary" :style="{ background: backlog_colors[2] }">{{backlog_topics[2]}}</span> might be a promising topic in one playthrough, but disastrous in another.
</p>
<p class="text-center lead">Exploration through experimentation in order to figure out which topics to exploit is the core challenge in this game.</p>
</dd>
<dt>Effort</dt>
<dd>
<p class="text-justify">
Each task requires a certain amount of effort to implement. There are 3 levels of complexity:
<span class="label label-default" :style="{ background: complexity_colors[0] }">{{backlog_complexities[0]}}</span>,
<span class="label label-default" :style="{ background: complexity_colors[1] }">{{backlog_complexities[1]}}</span>, and
<span class="label label-default" :style="{ background: complexity_colors[2] }">{{backlog_complexities[2]}}</span>.
</p>
<p class="text-justify">
Increased complexity also results in higher risk or reward. Experiments that result from tasks of <span class="label label-default" :style="{ background: complexity_colors[2] }">{{backlog_complexities[2]}}</span> complexity tend to have larger effect sizes, in either direction, than those of <span class="label label-default" :style="{ background: complexity_colors[0] }">{{backlog_complexities[0]}}</span> complexity.
</p>
</dd>
</dl>
<h3>Experiments</h3>
<p class="text-justify">Once a task is complete, a new experiment will be started. Each day, new users will be exposed to the experiment and statistics will be computed.</p>
<p class="text-justify">
At any given moment, you can decide to either
<span class="btn-group btn-group-xs"><button type="button" class="btn btn-danger">Stop</button></span> or
<span class="btn-group btn-group-xs"><button type="button" class="btn btn-success">Ship</button></span> an experiment.
Stopped experiments are removed from the game. Shipping an experiment will cause all future users to be exposed to this change.
</p>
<p class="text-justify">You can review past experimental results and decisions in the <code>history</code> tab.</p>
<p class="text-center lead">This is a game of chance, but not of chance alone. The faster you learn, the more you will earn. Good luck!</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-lg btn-primary btn-block" data-dismiss="modal"><strong>Close</strong></button>
</div>
</div>
</div>
</div>
<div class="modal" id="decision" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document" v-if="message.type == 'decision'">
<div class="modal-content">
<div class="modal-body" v-if="message.fullon">
<h1 class="text-center">You shipped {{message.exp.name}}.</h1>
<experiment-table :e="message.exp" :ci_scale_min="0.1"></experiment-table>
<p class="text-center lead" v-if="settings.feedback_level > 1">The real effect of this experiment was {{((message.exp.effect[1]-1)*100).toFixed(2)}}%.</p>
</div>
<div class="modal-body" v-if="!message.fullon">
<h1 class="text-center">You stopped {{message.exp.name}}.</h1>
<experiment-table :e="message.exp" :ci_scale_min="0.1"></experiment-table>
<p class="text-center lead" v-if="settings.feedback_level > 1">The real effect of this experiment was {{((message.exp.effect[1]-1)*100).toFixed(2)}}%.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-lg btn-primary btn-block" data-dismiss="modal"><strong>Close</strong></button>
</div>
</div>
</div>
</div>
<div class="modal" id="end_game" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-body">
<h1 class="text-center">The game is over</h1>
<p class="text-center">
<span class="text-muted label label-info">{{feedback_levels[settings.feedback_level]}}</span>
<span class="text-muted label label-info">{{settings.game_duration}} days</span>
</p>
<p class="text-center lead">Your final score is {{format_percent(overall_performance.get_relative_effect(1)[0])}}.</p>
<experiment-table :e="overall_performance"></experiment-table>
<p class="text-center lead">
<span v-if="overall_performance.is_significant()">
This is significantly
<strong v-if="overall_performance.get_relative_effect(1)[0] > 0">better</strong>
<strong v-if="overall_performance.get_relative_effect(1)[0] < 0">worse</strong>
than would have been expected if there had been no product changes made at all.
</span>
<span v-if="!overall_performance.is_significant()">
This is not significantly different from what would have been expected if there had been no product changes made at all.
</span>
</p>
</div>
<div class="modal-footer">
<a href="http://grnh.se/s3cdil" class="btn btn-lg btn-default btn-block" target="_blank"><small>Want to get paid to run experiments?</small><br /><strong>Apply for a job at Booking.com</strong></a>
<button type="button" class="btn btn-lg btn-primary btn-block" data-dismiss="modal"><strong>Close</strong></button>
</div>
</div>
</div>
</div>
<div v-if="!game_state.playing" class="row">
<!-- A general introduction to the game. -->
<div class="col-md-offset-2 col-md-8">
<h1>So You Think You Can Test?</h1>
<p class="text-justify lead">Decision making under uncertainty is complicated business. This game aims to make decision makers more aware of the complex trade off between indecision and acting on insufficient information.</p>
<h2>Simulation-mode</h2>
<p>
<div class="well">
<div class="form-group">
<label>Feedback level</label>
<p class="form-text text-muted">The amount of information you will have available during the simulation. Reduced feedback increases realism.</p>
<select v-model.number="settings.feedback_level" class="form-control">
<option value="1">Realistic (You will receive no feedback during the simulation)</option>
<option value="2">Instant feedback (You will receive instant feedback after each experiment decision)</option>
<option value="3">God-mode (Hidden parameters of the simulation are exposed)</option>
</select>
</div>
<div class="form-group">
<label>Game duration</label>
<p class="form-text text-muted">Longer play increases the opportunity to uncover the underlying simulation parameters through experimentation.</p>
<select v-model.number="settings.game_duration" class="form-control">
<option value="28">28 days (Barely enough time to run a few experiments)</option>
<option value="91">91 days (13 weeks. A single quarter. Enough time to explore)</option>
<option value="364">364 days (52 weeks. A whole year. Almost enough time to get bored)</option>
</select>
</div>
</div>
</p>
<p><button type="button" class="btn btn-lg btn-primary btn-block" v-on:click="start_sim_game"><strong>Start simulation-mode</strong><br /><small>realistic turn-based simulation</small></button></p>
<p><button type="button" class="btn btn-lg btn-warning btn-block" v-if="user == null" v-on:click="login"><strong>Login with Twitter</strong><br /><small>to view and compete on the leaderboard</small></button></p>
<div class="row" v-if="user != null">
<div class="col-md-offset-2 col-md-8 text-center">
<h2>Leaderboard</h2>
<p>
<span class="text-muted label label-info">{{feedback_levels[settings.feedback_level]}}</span>
<span class="text-muted label label-info">{{settings.game_duration}} days</span>
</p>
<p v-if="leaderboard.length == 0" class="text-muted text-center">*crickets*</p>
<dl class="dl-horizontal">
<span v-for="(l, i) in leaderboard_reversed">
<dt><span class="badge">#{{i+1}}</span> {{l.username}}</dt>
<dd>
{{format_number(l.score)}}
</dd>
</span>
</dl>
</div>
</div>
<p><button type="button" class="btn btn-lg btn-default btn-block" v-if="user != null" v-on:click="logout"><strong>Log out of Twitter</strong><br /><small>you are signed in as {{user.displayName}}</small></button></p>
<p><button type="button" class="btn btn-lg btn-default btn-block" data-toggle="modal" data-target="#help"><strong>Read instructions</strong><br /><small>some words on how to play</small></button></p>
<p><a href="arcade.html" class="btn btn-lg btn-default btn-block"><strong>Switch to arcade-mode</strong><br /><small>fast-paced time-based action</small></a></p>
<p class="text-center"><small>Created by <a href="http://www.lukasvermeer.nl">Lukas Vermeer</a> — Make this more awesome on <a href="https://github.com/lukasvermeer/confidence">GitHub</a></small></p>
</div>
</div>
<div v-if="game_state.playing">
<!-- Scores header for Simulation-mode. -->
<div class="row">
<div class="col-md-4 text-center"><h2>Day {{day}}/{{settings.game_duration}}</h2></div>
<div class="col-md-4 text-center"><h2>Sales {{format_number(conversions)}}</h2></div>
<div class="col-md-4 text-center">
<h2>
<button type="button" class="btn btn-default" data-toggle="modal" data-target="#help">Instructions</button>
<button type="button" class="btn btn-primary" v-if="day<settings.game_duration" :disabled="game_state.computing" v-on:click="next_round_sim()">Proceed to next day</button>
<button type="button" class="btn btn-danger" v-if="day>=settings.game_duration" v-on:click="end_sim_game()">End game</button>
</h2>
</div>
</div>
<!-- Nav tabs -->
<ul class="nav nav-tabs" role="tablist">
<li role="presentation">
<a href="#backlog" aria-controls="backlog" role="tab" data-toggle="tab">
Backlog <span class="badge">{{backlog[1].length}}</span>
</a>
</li>
<li role="presentation" class="active">
<a href="#experiments" aria-controls="experiments" role="tab" data-toggle="tab">
Experiments <span class="badge" v-if="summary_statistics.length > 0">{{summary_statistics.length}}</span>
</a>
</li>
<li role="presentation"><a href="#history" aria-controls="history" role="tab" data-toggle="tab" v-on:click="fake_resize">History</a></li>
</ul>
<div class="tab-content">
<!-- Backlog pane -->
<div role="tabpanel" class="tab-pane row" id="backlog">
<div class="col-md-4" v-for="(b,i) in backlog">
<p class="text-center lead">{{backlog_headings[i]}}</p>
<div v-for="(e,j) in b">
<div class="panel panel-default">
<div class="panel-heading">
{{e.name}}
<span class="label label-default" :style="{ background: complexity_colors[e.metadata.Complexity] }">{{backlog_complexities[e.metadata.Complexity]}}</span>
<span class="label label-primary" :style="{ background: backlog_colors[e.metadata.Topic] }">{{backlog_topics[e.metadata.Topic]}}</span>
<div class="btn-toolbar pull-right">
<div class="btn-group btn-group-xs" v-if="i == 0">
<button type="button" class="btn btn-default" @click="prioritize_task(j)">Prioritize</button>
</div>
<div class="btn-group btn-group-xs">
<button type="button" class="btn btn-default" @click="delete_task(j,i)">Delete</button>
</div>
</div>
</div>
<div class="panel-body">
<div class="progress" v-if="(e.progress/e.effort*100).toFixed(0) > 0" style="height: 2px">
<div class="progress-bar" role="progressbar" :aria-valuenow="(e.progress/e.effort*100).toFixed(0)" aria-valuemin="0" aria-valuemax="100" :style="{ width: (e.progress/e.effort*100).toFixed(0)+'%' }"></div>
</div>
<dl class="dl-horizontal" v-if="settings.feedback_level > 2">
<span><dt>Effect</dt><dd>{{(e.effect[1]-1).toLocaleString('en',{style:'percent',minimumFractionDigits:2})}}</dd></span>
<span><dt>Effort</dt><dd>{{(e.effort).toLocaleString('en')}}</dd></span>
</dl>
{{e.description}}
</div>
</div>
</div>
</div>
</div>
<!-- Experiments pane -->
<div role="tabpanel" class="tab-pane active row" id="experiments">
<!-- Experiments display for Simulation-mode. -->
<div class="col-md-12" v-if="summary_statistics.length == 0">
<div class="alert alert-info text-center" role="alert">There are currently no experiments running. Use the navigation above to switch to the <mark>backlog</mark> tab to prioritize their development.</div>
</div>
<div class="col-md-6" v-for="(exp,i) in summary_statistics">
<div class="panel panel-default">
<div class="panel-heading">
<strong>Experiment {{exp.experiment_id}}</strong>
<span class="label label-primary" :style="{ background: backlog_colors[exp.metadata.Topic] }">{{backlog_topics[exp.metadata.Topic]}}</span>
<span>(running for {{ exp.days }} days)</span>
<div class="btn-toolbar pull-right">
<div class="btn-group btn-group-xs">
<button type="button" class="btn btn-danger" v-on:click="sim_choose_exp(i, false)">Stop</button>
</div>
<div class="btn-group btn-group-xs">
<button type="button" class="btn btn-success" v-on:click="sim_choose_exp(i, true)">Ship</button>
</div>
</div>
</div>
<experiment-table :e="exp" :ci_scale_min="0.1"></experiment-table>
<p class="text-center lead" v-if="settings.feedback_level > 2">The real effect of this experiment is {{((exp.effect[1]-1)*100).toFixed(2)}}%.</p>
</div>
</div>
</div>
<div role="tabpanel" class="tab-pane row" id="history">
<div class="col-md-12" v-if="history[0].length == 0 && history[1].length == 0">
<div class="alert alert-info text-center" role="alert">No experiment decisions have been made so far. Use the navigation above to switch to the <mark>experiments</mark> tab to make some.</div>
</div>
<div class="col-md-12">
<reactive-chart :chart="chart"></reactive-chart>
</div>
<div class="col-md-6" v-for="(h,i) in history" v-if="history[0].length > 0 || history[1].length > 0">
<p class="text-center lead">{{history_headings[i]}}: {{history[i].length}}</p>
<div v-for="(e,j) in h" class="panel panel-default">
<div class="panel-heading">
<strong>Experiment {{e.experiment_id}}</strong>
<span class="label label-primary" :style="{ background: backlog_colors[e.metadata.Topic] }">{{backlog_topics[e.metadata.Topic]}}</span>
<span>(running for {{ e.days }} days)</span>
</div>
<experiment-table :e="e" :ci_scale_min="0.1"></experiment-table>
<p class="text-center lead" v-if="settings.feedback_level > 1">The real effect of this experiment was {{((e.effect[1]-1)*100).toFixed(2)}}%.</p>
</div>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="jquery/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="plotly/plotly.min.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.8.1/firebase.js"></script>
<script src="https://unpkg.com/vue/dist/vue.js"></script>
<script src="https://unpkg.com/vuefire/dist/vuefire.js"></script>
<script type="text/javascript" src="d3/d3.min.js"></script>
<script type="text/javascript" src="jstat/jstat.min.js"></script>
<script type="text/javascript" src="experiment.js"></script>
<script type="text/javascript">
//
// Decision making under uncertainty is complicated business. This game aims to make
// decision makers more aware of the complex trade off between indecision and acting
// on insufficient information.
//
var e = [];
// Initialize Firebase
var config = {
apiKey: "AIzaSyDZepeGLJDBlYRhw7jxf-kPa3Telk2tFWA",
authDomain: "confidence-app.firebaseapp.com",
databaseURL: "https://confidence-app.firebaseio.com",
projectId: "confidence-app",
storageBucket: "",
messagingSenderId: "122184836654"
};
firebase.initializeApp(config);
var provider = new firebase.auth.TwitterAuthProvider();
var db = firebase.database();
var leaderboard = db.ref('leaderboard/2/91');
// Get user data (if logged in).
firebase.auth().getRedirectResult().then(function (result) {
// The signed-in user info.
}).catch(function (error) {
// Handle Errors here.
var errorCode = error.code;
var errorMessage = error.message;
console.log('ERROR ' + errorCode + ': ' + errorMessage);
});
Vue.use(Vuefire.rtdbPlugin);
confidence = new Vue({
el: '#app-confidence',
beforeCreate: function () {
firebase.auth().onAuthStateChanged(function (user) {
this.user = user
}.bind(this))
},
created: function () {
this.bind_leaderboard();
},
watch: {
'settings.feedback_level': function (val) {
this.rebind_leaderboard();
},
'settings.game_duration': function (val) {
this.rebind_leaderboard();
},
},
data: {
leaderboard: [],
user: {},
AVERAGE_EFFECT: -0.25,
AVERAGE_EFFECT_STDDEV: 0.5,
DEV_CAPACITY: 2,
summary_statistics: [],
overall_performance: new Experiment(-1),
day: 0,
conversion: 0,
conversions: 0,
game_state: {
playing: false,
computing: false,
},
backlog: [[], [], [],],
backlog_headings: ['To be prioritized', 'Prioritized', 'In progress'],
backlog_topics: ['A', 'B', 'C', 'D', 'E'],
backlog_complexities: ['Low', 'Medium', 'High'],
backlog_index: 0,
history_headings: ['Stopped', 'Shipped'],
history: [[], []],
feedback_levels: ['', 'Realistic', 'Instant feedback', 'God-mode'],
settings: {
feedback_level: 2,
game_duration: 91,
visitors_per_day: 100000,
conversion_rate: 0.05,
topic_effects: [[-0.5, 0.5], [-0.25, 0.5], [0, 0], [0.25, 0.5], [0.5, 0.5],],
},
message: {},
chart: {
uuid: "boxplot",
traces: [
{ y: [], type: 'box', name: 'A' },
{ y: [], type: 'box', name: 'B' },
{ y: [], type: 'box', name: 'C' },
{ y: [], type: 'box', name: 'D' },
{ y: [], type: 'box', name: 'E' },
],
layout: {
title: {
text: 'Observed Effects by Category',
font: {
family: 'Arial',
size: 24,
},
},
autosize: true,
margin: true,
},
},
},
firebase: {
leaderboard: leaderboard.orderByChild('score').limitToLast(10),
},
computed: {
leaderboard_reversed: function () {
return (this.leaderboard).reverse();
},
backlog_colors: function () {
return this.backlog_topics.map(function (e, i) { return d3.schemeCategory10[i] });
},
complexity_colors: function () {
return this.backlog_complexities.map(function (e, i) { return d3.schemeCategory20c[3 - i] });
},
},
methods: {
update_summary_statistics: function () {
this.summary_statistics = e;
// This is super nasty. I wish there was a nicer way to ensure Vue updates.
for (var i = 0; i < this.summary_statistics.length; ++i) {
this.summary_statistics[i].visits.splice(0, 1, this.summary_statistics[i].visits[0]);
}
this.overall_performance.visits.splice(0, 1, this.overall_performance.visits[0]);
},
add_random_task: function () {
var e = new Experiment(++this.backlog_index);
var topic = Math.floor(Math.random() * this.backlog_topics.length);
e.metadata['Topic'] = topic;
var effort = Math.floor(Math.random() * this.backlog_complexities.length);
e.metadata['Complexity'] = effort;
e.effort = 50 + effort * 100;
var effect = 1 + jStat.normal.sample(this.settings.topic_effects[topic][0], this.settings.topic_effects[topic][1] * (effort + 1)) / 100;
e.reset(effect);
this.backlog[0].push(e);
},
prioritize_task: function (i) {
if (this.backlog[0][i]) {
this.backlog[1].push(this.backlog[0].splice(i, 1)[0]);
}
},
delete_task: function (i, b) {
if (this.backlog[b][i]) {
this.backlog[b].splice(i, 1)[0];
this.add_random_task();
}
},
next_round_sim: function () {
if (!this.game_state.computing) {
this.game_state.computing = true;
setTimeout(function () { confidence.next_round_sim_deferred(); }, 10);
}
},
next_round_sim_deferred: function () {
var dc = this.DEV_CAPACITY;
// Simulate developers.
for (var i = 0; i < dc; ++i) {
var dp = 20 + (Math.random() * 20); // Developer points per developer per round.
while (dp > 0) {
if (this.backlog[2][i] && this.backlog[2][i].effort - this.backlog[2][i].progress > 0) {
// There is a task and it needs work.
var t = Math.min(dp, this.backlog[2][i].effort - this.backlog[2][i].progress);
this.backlog[2][i].progress += t;
dp -= t;
} else {
if (this.backlog[2][i] && this.backlog[2][i].effort - this.backlog[2][i].progress <= 0) {
// Task done.
e.push(this.backlog[2].splice(i, 1)[0]);
// Add new task.
this.add_random_task();
}
// Pick up new task. Prefer prioritized tasks.
var new_task = this.backlog[1].shift() || this.backlog[0].shift();
if (new_task) {
this.backlog[2].splice(i, 0, new_task);
} else {
// Nothing to do.
dp = 0;
}
}
}
}
this.run_experiments(this.settings.visitors_per_day);
this.day++;
for (var i = 0; i < e.length; ++i) {
if (e[i].active) {
e[i].days++;
}
}
this.game_state.computing = false;
},
sim_visitor: function () {
var c = this.conversion;
// assign to treatment for each exp and calculate aggregate effect size.
var a = [];
for (var i = 0; i < e.length; ++i) {
a[i] = e[i].assign_variant();
c = c * e[i].effect[a[i]];
}
// converted or not.
b = false; if (Math.random() <= c) { b = true; this.conversions++; }
// update exps to reflect.
for (var i = 0; i < e.length; ++i) {
if (e[i].active) {
e[i].visits[a[i]]++;
if (b) e[i].conversions[a[i]]++;
}
}
this.overall_performance.visits[0]++;
this.overall_performance.conversions[0] += this.settings.conversion_rate;
this.overall_performance.visits[1]++;
if (b) this.overall_performance.conversions[1]++;
},
run_experiments: function (v) {
for (var i = 0; i < v; ++i) { this.sim_visitor(); }
this.update_summary_statistics();
},
start_sim_game: function () {
this.game_state.playing = true;;
// Initialise experiment data.
e = new Array();
this.overall_performance = new Experiment(-1);
this.conversions = 0; this.day = 0; this.conversion = this.settings.conversion_rate;
this.backlog = [[], [], [],]; this.backlog_index = 0; this.history = [[], []];
this.settings.topic_effects = d3.shuffle(this.settings.topic_effects);
for (i = 0; i <= 6; ++i) {
this.add_random_task();
}
this.update_summary_statistics();
},
end_sim_game: function () {
$('#end_game').modal('show');
if (firebase.auth().currentUser) {
db.ref('leaderboard/' + this.settings.feedback_level + '/' + this.settings.game_duration).push({
username: firebase.auth().currentUser.displayName,
uid: firebase.auth().currentUser.uid,
photoURL: firebase.auth().currentUser.photoURL,
score: this.conversions,
timestamp: firebase.database.ServerValue.TIMESTAMP
});
this.rebind_leaderboard();
}
this.game_state.playing = false;
},
sim_choose_exp: function (exp, fullon) {
// apply change to conversion
if (fullon) { this.conversion = e[exp].effect[1] * this.conversion; }
this.message = { type: 'decision', fullon: fullon, exp: e[exp] };
$('#decision').modal('show');
e[exp].end_experiment();
// Calculate relative effect (struggled getting the existing here, feel free to replace)
var relativeEffectWorkaround = ((((e[exp]["conversions"][1] / e[exp]["visits"][1]) / (e[exp]["conversions"][0] / e[exp]["visits"][0])) - 1) * 100).toFixed(2);
// Update box plots with observed effects, metadata.topic puts them into the correct bucket
this.chart.layout.datarevision = this.chart["traces"][e[exp]["metadata"]["Topic"]].y.push(relativeEffectWorkaround);
this.history[0 + fullon].push(e.splice(exp, 1)[0]);
},
format_number: function (n) {
return n.toFixed().replace(/\d(?=(\d{3})+$)/g, '$&.');
},
format_percent: function (n) {
return n.toLocaleString('en', { style: 'percent', minimumFractionDigits: 2 });
},
login: function () {
firebase.auth().signInWithRedirect(provider);
},
logout: function () {
firebase.auth().signOut().then(function () {
// Sign-out successful.
}).catch(function (error) {
// An error happened.
console.log('ERROR: ' + error);
});
},
rebind_leaderboard: function () {
this.$unbind('leaderboard');
this.bind_leaderboard();
},
bind_leaderboard: function () {
this.$rtdbBind('leaderboard', db.ref('leaderboard/' + this.settings.feedback_level + '/' + this.settings.game_duration).orderByChild('score').limitToLast(10));
},
fake_resize: function () {
var resizeEvent = window.document.createEvent('UIEvents');
resizeEvent.initUIEvent('resize', true, false, window, 0);
window.dispatchEvent(resizeEvent);
}
},
});
// Reactive Box Plot Component
Vue.component("reactive-chart", {
props: ["chart"],
template: '<div :ref="chart.uuid"></div>',
mounted() {
Plotly.plot(this.$refs[this.chart.uuid], this.chart.traces, this.chart.layout, { responsive: true });
},
watch: {
chart: {
handler: function () {
Plotly.react(
this.$refs[this.chart.uuid],
this.chart.traces,
this.chart.layout,
{ responsive: true }
);
},
deep: true,
},
},
});
</script>
</body>
</html>