-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathstatsoldreact.html
More file actions
executable file
·654 lines (638 loc) · 29.9 KB
/
statsoldreact.html
File metadata and controls
executable file
·654 lines (638 loc) · 29.9 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="msApplication-ID" content="57039gregstoll.com.BaseballCalculator"/>
<meta name="msApplication-PackageFamilyName" content="57039gregstoll.com.BaseballCalculator_mrfc7nnpdd326"/>
<title>Win Expectancy Finder</title>
<meta name="viewport" content="width=device-width">
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.3/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.3/JSXTransformer.js"></script> -->
<!--#include virtual="/bootstraphead.html"-->
<script src="reactbuild/react-with-addons.js"></script>
<script src="reactbuild/JSXTransformer.js"></script>
<!-- from https://github.com/mpowaga/react-slider -->
<script src="reactbuild/react-slider.js"></script>
<!-- <script src="jquery-1.11.3.min.js"></script> -->
<script src="jqueryui/jquery-ui.js"></script>
<style type="text/css">
P.littlespace {margin: 2px;}
.leverageVeryHigh {background-color: #f22; font-weight: 900;}
.leverageHigh {background-color: #99f; font-weight: 900;}
.leverageMedium {background-color: #ccc; font-weight: 900;}
table.scoreTable td { /*border: 1px solid black;*/ font-size: 150%;}
table.scoreTable td { padding: 1px 5px 1px 5px; }
table.innings { width: 300px; }
table.innings td { padding: 1px; width: 9%; text-align: center; }
table.innings td.sideHeader { width: auto; }
table.innings input[type="radio"] {
border-radius: 100% !important;
margin-block-end: 0;
margin-block-start: 3px;
margin-inline-end: 3px;
margin-inline-start: 5px;
}
table.innings th {
text-align: center;
}
/* slider stuff */
.horizontal-slider {
width: 100%;
max-width: 500px;
height: 15px;
border: 1px solid grey;
}
.vertical-slider {
height: 380px;
width: 50px;
border: 1px solid grey;
}
.handle {
font-size: 0.9em;
text-align: center;
background-color: black;
color: white;
cursor: pointer;
}
.handle.active {
background-color: grey;
}
.bar {
position: relative;
background: #ddd;
}
.bar.bar-1 {
background: #f8b74d;
}
.horizontal-slider .bar {
height: 15px;
}
.horizontal-slider .handle {
top: -1px;
width: 15px;
height: 17px;
line-height: 48px;
}
.vertical-slider .handle {
left: 1px;
width: 48px;
line-height: 50px;
}
.vertical-slider .bar {
left: 20px;
width: 10px;
}
#horizontal-0,
#horizontal-1, #horizontal-2, #horizontal-3,
#vertical {
margin: 20px 10px;
}
#horizontal-2 .bar.bar-2 {
background: #ddd;
}
/* transitions */
.outputTransition-enter {
opacity: 0.01;
}
.outputTransition-enter.outputTransition-enter-active {
opacity: 1;
transition: opacity 0.5s ease-in;
}
.outputTransition-leave {
opacity: 1;
}
.outputTransition-leave.outputTransition-leave-active {
opacity: 0.01;
transition: opacity 0.2s ease-in;
}
/*.outputTransition-appear {
opacity: 0.01;
transition: opacity .5s ease-in;
}
.outputTransition-appear.outputTransition-appear-active {
opacity: 1;
}*/
</style>
<script>
// Set this up to do extra calculations every time.
// 0 => first (or last) year
// x (if 0 < x < 1900) => first year + x
// x (if x < 0) => last year + x
// x (if x >= 1900) => that year
var extraYears = [];
//var extraYears = [[0, 0], [2006, 0], [-3, 0]];
var MIN_YEAR = 1957;
var MAX_YEAR = 2016;
function transformNonZeroYear(y)
{
if (y < 0) {
return MAX_YEAR + y;
}
if (y < 1900) {
return MIN_YEAR + y;
}
return y;
}
function transformYears(startYear, endYear)
{
if (startYear == 0) {
startYear = MIN_YEAR;
}
if (endYear == 0) {
endYear = MAX_YEAR;
}
startYear = transformNonZeroYear(startYear);
endYear = transformNonZeroYear(endYear);
return [startYear, endYear];
}
</script>
<script type="text/jsx">
React.initializeTouchEvents(true);
var ReactCSSTransitionGroup = React.addons.CSSTransitionGroup;
var InningHeader = React.createClass({
render: function() {
return <th>{this.props.inningNum}</th>;
}
});
var InningChoice = React.createClass({
handleClick: function(e) {
this.props.setInning(this.props.inning);
},
render: function () {
return <td><input type="radio" name="inningRadio" value="{this.props.inning.homeOrVisitor + this.props.inning.num}"
defaultChecked={this.props.inning.homeOrVisitor == this.props.chosenInning.homeOrVisitor && this.props.inning.num == this.props.chosenInning.num}
onClick={this.handleClick}
/></td>;
}
});
var InningTable = React.createClass({
setInning: function(inning) {
this.props.setInning(inning);
},
render: function () {
var i;
var headers = [];
for (i = 1; i <= this.props.numInnings; ++i)
{
headers.push(<InningHeader key={i} inningNum={i} />);
}
var visitorChoices = [];
for (i = 1; i <= this.props.numInnings; ++i)
{
var thisInning = {homeOrVisitor: 'V', num: i};
visitorChoices.push(<InningChoice key={thisInning.homeOrVisitor + thisInning.num} inning={thisInning} chosenInning={this.props.inning} setInning={this.setInning} />);
}
var homeChoices = [];
for (i = 1; i <= this.props.numInnings; ++i)
{
var thisInning = {homeOrVisitor: 'H', num: i};
homeChoices.push(<InningChoice key={thisInning.homeOrVisitor + thisInning.num} inning={thisInning} chosenInning={this.props.inning} setInning={this.setInning} />);
}
return <table className="innings">
<thead>
<tr>
<th></th>
{headers}
</tr>
</thead>
<tbody>
<tr>
<th className="sideHeader">V</th>
{visitorChoices}
</tr>
<tr>
<th className="sideHeader">H</th>
{homeChoices}
</tr>
</tbody>
</table>;
}
});
var OutsControl = React.createClass({
handleClick: function(e) {
this.props.setOuts((this.props.outs == 2) ? 0 : this.props.outs + 1);
},
getOutsColor: function(on) {
return on ? '#ff0000' : '#ffffff';
},
render: function() {
var WIDTH = 75;
var HEIGHT = 40;
var WIDTH_MARGIN = 5;
var HEIGHT_MARGIN = 5;
var circleRadius = Math.min(WIDTH - 3 * WIDTH_MARGIN, HEIGHT - 2 * HEIGHT_MARGIN) / 2;
return <p className="littlespace" style={{"display": "flex", "align-items": "center"}}><span>Outs:</span>
<svg width={WIDTH} height={HEIGHT} onClick={this.handleClick}>
<circle cx={WIDTH/4} cy={HEIGHT/2} r={circleRadius} stroke="#a0522d" fill={this.getOutsColor(this.props.outs >= 1)} />
<circle cx={(3*WIDTH)/4} cy={HEIGHT/2} r={circleRadius} stroke="#a0522d" fill={this.getOutsColor(this.props.outs >= 2)} />
</svg>
</p>;
}
});
var RunnersOnBaseList = React.createClass({
handleChange: function(e) {
this.props.setRunners(e.target.value);
},
render: function() {
return <p className="littlespace">Runners on base:
<select onChange={this.handleChange} value={this.props.runners}>
<option value="1">none</option>
<option value="2">1st</option>
<option value="3">2nd</option>
<option value="4">1st & 2nd</option>
<option value="5">3rd</option>
<option value="6">1st & 3rd</option>
<option value="7">2nd & 3rd</option>
<option value="8">loaded</option>
</select>
</p>;
}
});
var ScoreTable = React.createClass({
handleVisitorClick: function() {
this.props.setScore(this.props.score - 1);
},
handleHomeClick: function() {
this.props.setScore(this.props.score + 1);
},
render: function() {
var visitorScore = '';
var homeScore = '';
if (this.props.score < 0) {
visitorScore = '+' + (-1 * this.props.score);
} else if (this.props.score > 0) {
homeScore = '+' + (this.props.score);
} else {
visitorScore = "Tie";
homeScore = "Tie";
}
return <table className="scoreTable">
<tr><th>Visitor</th><td>{visitorScore}</td><td><button onClick={this.handleVisitorClick}>+</button></td></tr>
<tr><th>Home</th><td>{homeScore}</td><td><button onClick={this.handleHomeClick}>+</button></td></tr>
</table>;
}
});
var RunnersOnBaseDiamond = React.createClass({
getBaseColor: function(on) {
return on ? '#ff0000' : '#eeeeee';
},
pointsFromCenter: function(center, baseSize) {
return [[center[0], center[1] + baseSize], [center[0] + baseSize, center[1]], [center[0], center[1] - baseSize], [center[0] - baseSize, center[1]]];
},
toggleFirst: function(e) {
this.props.setRunners(((this.props.runners - 1) ^ 1) + 1);
},
toggleSecond: function(e) {
this.props.setRunners(((this.props.runners - 1) ^ 2) + 1);
},
toggleThird: function(e) {
this.props.setRunners(((this.props.runners - 1) ^ 4) + 1);
},
render: function() {
var WIDTH = 200;
var HEIGHT = 200;
var first = (this.props.runners - 1) & 1;
var second = (this.props.runners - 1) & 2;
var third = (this.props.runners - 1) & 4;
var baseSize = Math.max(WIDTH*0.1, 10);
var homeCenter = [WIDTH/2, HEIGHT*0.85];
var homePoints = [[homeCenter[0], homeCenter[1] + baseSize], [homeCenter[0] + baseSize, homeCenter[1]], [homeCenter[0] + baseSize], [homeCenter[1] - baseSize], [homeCenter[0] - baseSize, homeCenter[1] - baseSize], [homeCenter[0] - baseSize, homeCenter[1]]];
var firstCenter = [WIDTH*0.85, HEIGHT/2];
var firstPoints = this.pointsFromCenter(firstCenter, baseSize);
var secondCenter = [WIDTH/2, HEIGHT*0.15];
var secondPoints = this.pointsFromCenter(secondCenter, baseSize);
var thirdCenter = [WIDTH*0.15, HEIGHT/2];
var thirdPoints = this.pointsFromCenter(thirdCenter, baseSize);
return <div>
<svg width={WIDTH} height={HEIGHT}>
<rect x="0" y="0" width={WIDTH} height={HEIGHT} fill="#006400" />
<line x1={WIDTH/2} y1={HEIGHT*0.85} x2={WIDTH*0.85} y2={HEIGHT/2} strokeWidth="5" stroke="#a0522d" />
<line x1={WIDTH*0.85} y1={HEIGHT/2} x2={WIDTH/2} y2={HEIGHT*0.15} strokeWidth="5" stroke="#a0522d" />
<line x1={WIDTH/2} y1={HEIGHT*0.15} x2={WIDTH*0.15} y2={HEIGHT/2} strokeWidth="5" stroke="#a0522d" />
<line x1={WIDTH*0.15} y1={HEIGHT/2} x2={WIDTH/2} y2={HEIGHT*0.85} strokeWidth="5" stroke="#a0522d" />
{ /* home plate */ }
<polygon points={homePoints} strokeWidth="0" fill={this.getBaseColor(false)} />
{ /* first base */ }
<polygon points={firstPoints} strokeWidth="0" fill={this.getBaseColor(first)} onClick={this.toggleFirst} />
{ /* second base */ }
<polygon points={secondPoints} strokeWidth="0" fill={this.getBaseColor(second)} onClick={this.toggleSecond}/>
{ /* third base */ }
<polygon points={thirdPoints} strokeWidth="0" fill={this.getBaseColor(third)} onClick={this.toggleThird}/>
</svg>
</div>;
},
});
var YearsSlider = React.createClass({
onChange: function(value) {
if (this.setYearsEvent != undefined) {
window.clearTimeout(this.setYearsEvent);
}
// update view here
// We don't want to wait for the AJAX request to be sent
// (which will take at least this.TIMEOUT ms) to update the text
// here, so store it in our state instead of props.
this.setState({years: [value[0], value[1]]});
this.setYearsEvent = window.setTimeout(function() { this.doActualChange(value)}.bind(this), this.TIMEOUT);
},
doActualChange: function(value) {
this.setYearsEvent = undefined;
this.props.setYears([value[0], value[1]]);
},
componentDidMount: function() {
// delay before triggering setYears
this.TIMEOUT = 500;
this.setYearsEvent = undefined;
},
componentWillMount: function() {
this.setState({years: this.props.years});
},
componentWillReceiveProps: function(nextProps) {
this.setState({years: nextProps.years});
},
render: function() {
return <div>
<p className="littlespace">Years to include: {this.state.years[0]} - {this.state.years[1]}</p>
<ReactSlider className="horizontal-slider" orientation="horizontal" withBars={true} defaultValue={[this.state.years[0], this.state.years[1]]} min={MIN_YEAR} max={MAX_YEAR} onChange={this.onChange} />
</div>
}
});
var StatsResults = React.createClass({
componentDidMount: function() {
var node = React.findDOMNode(this);
$('.realOutput', node).effect("highlight");
},
componentDidUpdate: function(prevProps, prevState) {
var differences = false;
var properties = Object.keys(this.props);
for (var i in properties) {
if (properties[i] != 'years' && this.props[properties[i]] != prevProps[properties[i]]) {
differences = true;
break;
}
}
if (differences) {
var node = React.findDOMNode(this);
$('.realOutput', node).effect("highlight");
}
},
render: function() {
var mainDivStyle = {width: '300px', float: 'left'};
if (!this.props.isPrimary) {
mainDivStyle.marginTop = '20px';
}
if (this.props.isInitial) {
return <div style={mainDivStyle}/>
}
var key = this.props.name;// + Math.random();
if (this.props.total === 0) {
key = key + 'none';
return <div style={mainDivStyle}>
<ReactCSSTransitionGroup transitionName="outputTransition" transitionAppear={false} transitionLeave={false}>
<div className="realOutput" key={key}>No data found!</div>
</ReactCSSTransitionGroup>
</div>
}
var r = this.props;
var wins = r.wins;
var percent = (100 * wins) / r.total;
var displayPercent = Math.round(percent * 100)/100;
var displayHome = r.isHome;
var homeMoneyLine = '';
var visitorMoneyLine = '';
if (displayPercent < 50)
{
displayPercent = Math.round((100 - displayPercent) * 100)/100;
wins = r.total - wins;
displayHome = !displayHome;
}
var ml = Math.round((displayPercent/(100 - displayPercent)) * -100);
var oml = "+" + (-1 * ml);
if (displayHome) {
homeMoneyLine = ml;
visitorMoneyLine = oml;
} else {
homeMoneyLine = oml;
visitorMoneyLine = ml;
}
// TODO - refactor leverage stuff
var leverageDescription = 'Low';
var leverageClass = 'leverageLow';
if (r.leverageIndex >= 3.0) {
leverageDescription = 'Very High';
leverageClass = 'leverageVeryHigh';
} else if (r.leverageIndex >= 1.6) {
leverageDescription = 'High';
leverageClass = 'leverageHigh';
} else if (r.leverageIndex >= 0.8) {
leverageDescription = 'Medium';
leverageClass = 'leverageMedium';
}
leverageClass = 'leverageIndex ' + leverageClass;
var winnerTeamText = displayHome ? "Home" : "Visitor";
// make this something that always changes
// this uses ReactCSSTransitionGroup when change from some to no output
var yearsStyle = r.isPrimary ? {display : 'none'} : {};
return <div style={mainDivStyle}>
<ReactCSSTransitionGroup transitionName="outputTransition" transitionAppear={false}>
<div className="realOutput" key={key}>
<p className="littlespace" style={yearsStyle}>Years: {r.years[0]} - {r.years[1]}</p>
<p className="littlespace">Total games: {r.total}</p>
<p className="littlespace">Wins for {winnerTeamText}: {wins}</p>
<p className="littlespace">Win percentage: <b>{winnerTeamText} {displayPercent}%</b></p>
<p className="littlespace">Leverage index: <b className={leverageClass}>{r.leverageIndex} ({leverageDescription})</b></p>
<p className="littlespace">Home money line: <b>{homeMoneyLine}</b></p>
<p className="littlespace">Visitor money line: <b>{visitorMoneyLine}</b></p>
</div>
</ReactCSSTransitionGroup>
</div>;
}
});
var IndeterminateProgressBar = React.createClass({
render: function() {
return <progress style={{display: this.props.active ? '' : 'none'}} />;
}
});
var BaseballSituation = React.createClass({
addInitialState: function(state, name, years) {
state['results' + name] = {total: 0, wins: 0, leverageIndex: 0, isHome: false, isInitial: true, years: years};
},
getInitialState: function() {
var state = {inning: {homeOrVisitor: 'V', num: 1}, outs: 0, runners: 1, score: 0, years: [MIN_YEAR, MAX_YEAR], pendingRequests: false};
this.addInitialState(state, 'output', []);
var i;
for (i = 0; i < extraYears.length; ++i)
{
var localStartYear = extraYears[i][0];
var localEndYear = extraYears[i][1];
var transformedYears = transformYears(localStartYear, localEndYear);
this.addInitialState(state, 'output' + i, transformedYears);
}
// parse query hash
if (window.location.hash) {
var hash = window.location.hash.substring(1);
var parts = hash.split(".");
if (parts.length === 7 || parts.length === 5) {
var whichTeam = parts[0];
var scorediff = parseInt(parts[1]);
var inning = parts[2];
var outs = parts[3];
var runners = parts[4];
var startYear = MIN_YEAR;
var endYear = MAX_YEAR;
if (parts.length === 7) {
startYear = parseInt(parts[5]);
endYear = parseInt(parts[6]);
if (isNaN(startYear) || isNaN(endYear)) {
startYear = MIN_YEAR;
endYear = MAX_YEAR;
}
}
state.inning.homeOrVisitor = parts[0];
state.score = parseInt(parts[1]);
state.inning.num = parseInt(parts[2]);
state.outs = parseInt(parts[3]);
state.runners = parseInt(parts[4]);
state.years[0] = startYear;
state.years[1] = endYear;
}
}
return state;
},
componentDidMount: function() {
this.updateCalculations();
},
updateCalculations: function() {
var s = this.state;
// update query hash
var hash = s.inning.homeOrVisitor + "." + s.score + "." + s.inning.num + "." + s.outs + "." + s.runners;
if (s.years[0] != MIN_YEAR || s.years[1] != MAX_YEAR) {
hash += "." + s.years[0] + "." + s.years[1];
}
window.location.hash = hash;
// set up progress bar state
this.setState({'pendingHash' : hash, 'pendingCount': 1 + extraYears.length});
this.calculateStats(s.inning.homeOrVisitor, s.score, s.inning.num, s.outs, s.runners, s.years[0], s.years[1], 'output', hash);
var i;
for (i = 0; i < extraYears.length; ++i)
{
var localStartYear = extraYears[i][0];
var localEndYear = extraYears[i][1];
var transformedYears = transformYears(localStartYear, localEndYear);
localStartYear = transformedYears[0];
localEndYear = transformedYears[1];
this.calculateStats(s.inning.homeOrVisitor, s.score, s.inning.num, s.outs, s.runners, localStartYear, localEndYear, 'output' + i, hash);
}
},
calculateStats: function(whichTeam, scorediff, inning, outs, runners, startYear, endYear, name, hash) {
var isHome = whichTeam === "H";
if (!isHome)
{
scorediff *= -1;
}
var stateString = '"' + whichTeam + '",' + inning + ',' + outs + ',' + runners + ',' + scorediff;
$.ajax({url: 'getcumulativestats.cgi', data: {stateString: stateString, startYear: startYear, endYear: endYear, rand: Math.random()}, dataType: "json", complete: function(xhr, textStatus) {
var theseResults = this.state['results' + name];
theseResults.total = parseInt(xhr.responseJSON.total);
theseResults.wins = parseInt(xhr.responseJSON.wins);
theseResults.leverageIndex = parseFloat(xhr.responseJSON.leverage);
theseResults.isHome = isHome;
theseResults.isInitial = false;
newState = {}
newState['results' + name] = theseResults;
//this.setState(newState);
// use the callback for to atomically update pendingCount
this.setState(function(previousState, currentProps) {
if (hash === previousState['pendingHash']) {
newState['pendingCount'] = newState['pendingCount'] - 1;
}
return newState;
});
}.bind(this)});
},
setInning: function(newInning) {
this.setState({inning: newInning}, this.updateCalculations);
},
setOuts: function(newOuts) {
this.setState({outs: newOuts}, this.updateCalculations);
},
setRunners: function(newRunners) {
this.setState({runners: newRunners}, this.updateCalculations);
},
setScore: function(newScore) {
this.setState({score: newScore}, this.updateCalculations);
},
setYears: function(newYears) {
this.setState({years: newYears}, this.updateCalculations);
},
createStatsResults: function(isPrimary, name, years) {
return <StatsResults isPrimary={isPrimary} name={name}
total={this.state["results" + name].total} wins={this.state["results" + name].wins} leverageIndex={this.state["results" + name].leverageIndex} isHome={this.state["results" + name].isHome} isInitial={this.state["results" + name].isInitial} years={isPrimary ? [] : years} key={name} />
},
render: function () {
var NUM_INNINGS = 11;
var primaryStatsResultsList = []
primaryStatsResultsList.push(this.createStatsResults(true, 'output', []));
var i;
var statsResultsList = [];
for (i = 0; i < extraYears.length; ++i)
{
var localStartYear = extraYears[i][0];
var localEndYear = extraYears[i][1];
var transformedYears = transformYears(localStartYear, localEndYear);
statsResultsList.ph(is.eateStatsResults(f6lse, 'output' + i, transformedYears));
}
return <div>
<InningTable numInnings={NUM_INNINGS} inning={this.state.inning} setInning={this.setInning} />
<div style={{float: 'left'}}>
<OutsControl outs={this.state.outs} setOuts={this.setOuts} />
<RunnersOnBaseList runners={this.state.runners} setRunners={this.setRunners} />
<ScoreTable score={this.state.score} setScore={this.setScore} />
<YearsSlider years={this.state.years} setYears={this.setYears} />
</div>
<div style={{float: 'left', marginLeft: '25px'}}>
<RunnersOnBaseDiamond runners={this.state.runners} setRunners={this.setRunners} />
</div>
<div style={{clear: 'both'}}>
<IndeterminateProgressBar active={this.state.pendingCount > 0} />
</div>
{primaryStatsResultsList}
<div style={{clear: 'both'}}>
{statsResultsList}
</div>
<div style={{clear: 'both'}} />
</div>;
}
});
React.render(
<BaseballSituation />,
document.getElementById("reactTarget")
);
</script>
</head>
<body>
<!--#include virtual="/navbar.html"-->
<div class="container">
<div id="reactTarget"></div>
<p style="clear: both;">
<a href="https://www.microsoft.com/store/apps/9nblgggzkgt4"><img src="https://cmsresources.windowsphone.com/devcenter/en-us/legacy_v1/img/badgegenerator/English_wstore_black_258x67.png" alt="Download from Windows Store" /></a> <a href="http://www.windowsphone.com/s?appid=ab476634-9a24-4f0c-bc7a-4f65a12c33dd"><img src="DownloadWPMed.png" alt="Download from the Windows Phone Store" title="Download from the Windows Phone Store"></a></p>
<p>To make a graph of the Win Expectancy of a baseball game, use the <a href="graphgame.html">graph a game</a> tool.</p>
<p>This data is from MLB games from 1957-2015, including postseason games. All data is available at <a href="http://www.retrosheet.org/game.htm">Retrosheet</a>.</p>
<p><b>Linked from:</b> <a href="https://fivethirtyeight.com/features/donald-trump-has-a-20-percent-chance-of-becoming-president/">FiveThirtyEight</a> (search for "eighth inning"), <a href="https://www.washingtonpost.com/news/dc-sports-bog/wp/2016/05/31/a-seven-run-comeback-a-27-hour-rain-delay-and-a-trip-to-the-ncaa-tournament/">The Washington Post</a>, <a href="http://www.cbssports.com/mlb/news/how-win-expectancy-lets-you-track-each-teams-chances-to-win-world-series-game-7/">CBS Sports</a>, <a href="http://www.cbssports.com/mlb/eye-on-baseball/24732478/which-of-the-many-sac-bunts-in-al-wild-card-game-made-sense">CBS Sports again</a>, <a href="http://www.royalsreview.com/2016/4/4/11365240/fun-with-wp-and-wpa">Royals Review</a>, <a href="http://www.beyondtheboxscore.com/2015/10/21/9574081/the-impact-of-managerial-mistakes">Beyond the Box Score</a>, and more!</p>
<p>Idea taken from walkoffbalk.com's Win Expectancy Finder (now defunct). Here's a <a href="http://www.hardballtimes.com/main/article/the-one-about-win-probability/">good article about Win Expectancy</a>. Leverage Index calculations based on <a href="http://www.hardballtimes.com/crucial-situations/">this article</a>.</p>
<p>Source files also available on <a href="https://github.com/gregstoll/baseballstats">GitHub</a>.</p>
<ul>
<li><a href="getcumulativestats.py">getcumulativestats.cgi</a> - the source for .php file</li>
<li><a href="parseretrosheet.txt">parseretrosheet.py</a> - parses the <a href="http://www.retrosheet.org/game.htm">Retrosheet data</a></li>
<li><a href="processstats.txt">processstats.py</a> - puts the Retrosheet data in the <a href="probs.txt">probs.txt</a> file. See <a href="http://www.philbirnbaum.com/probs2.txt">Phil Birnbaum's description of the data file</a>.</li>
<li><a href="processcumulativestats.txt">processcumulativestats.py</a> - puts the Retrosheet data into cumulative files per year.</li>
</ul>
<p>The information used here was obtained free of charge from and is copyrighted by Retrosheet. Interested parties may contact Retrosheet at 20 Sunset Rd., Newark, DE 19711.</p>
<!-- <p><a href="/">Greg's home page</a></p> -->
<p><a href="index.html">Baseball statistic calculators</a></p>
<script src="https://www.google-analytics.com/urchin.js" type="text/javascript"></script>
<script type="text/javascript">
_uacct = "UA-362292-1";
urchinTracker();
</script>
</div>
</body></html>