Skip to content

Commit 9692232

Browse files
dsmilkovnkreeger
authored andcommitted
Add validation score to the chart (#74)
* save * save
1 parent 3433eaf commit 9692232

File tree

8 files changed

+115
-27
lines changed

8 files changed

+115
-27
lines changed

baseball-node/.vscode/settings.json

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Place your settings in this file to overwrite default and user settings.
2+
{
3+
"search.exclude": {
4+
"**/node_modules": true,
5+
"dist/": true,
6+
"**/yarn.lock": true
7+
},
8+
"files.trimTrailingWhitespace": true,
9+
"editor.tabSize": 2,
10+
"editor.insertSpaces": true,
11+
"[javascript]": {
12+
"editor.formatOnSave": true
13+
},
14+
15+
"tslint.enable": true,
16+
"tslint.run": "onType",
17+
"tslint.configFile": "tslint.json",
18+
"[typescript]": {
19+
"editor.formatOnSave": true
20+
},
21+
22+
"clang-format.style": "Google",
23+
"files.insertFinalNewline": true,
24+
"editor.detectIndentation": false,
25+
"editor.wrappingIndent": "none",
26+
"clang-format.executable": "${workspaceRoot}/node_modules/.bin/clang-format"
27+
}

baseball-node/.vscode/tasks.json

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"version": "2.0.0",
3+
"tasks": [
4+
{
5+
"command": "yarn",
6+
"label": "lint",
7+
"type": "shell",
8+
"args": [
9+
"lint"
10+
],
11+
"problemMatcher": {
12+
"base": "$tslint5",
13+
"owner": "tslint-type-checked",
14+
"fileLocation": "absolute"
15+
}
16+
},
17+
{
18+
"command": "yarn",
19+
"label": "build",
20+
"type": "shell",
21+
"args": ["build", "--pretty", "false"],
22+
"problemMatcher": [
23+
"$tsc"
24+
]
25+
}
26+
]
27+
}

baseball-node/src/abstract-pitch-model.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717

1818
import * as tf from '@tensorflow/tfjs';
19-
2019
import {PitchData, PitchDataBatch, PitchTrainFields} from './pitch-data';
2120
import {TrainProgress} from './types';
2221

@@ -73,4 +72,4 @@ export abstract class PitchModel {
7372
});
7473
this.totalTrainSteps++;
7574
}
76-
}
75+
}

baseball-node/src/client/App.vue

+38-7
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,49 @@ limitations under the License.
1515

1616
<template>
1717
<div class="container content">
18-
<div id="table"></div>
18+
<div id="table">
19+
<h2 style="text-align:center;">Accuracy per pitch type (%)</h2>
20+
<div id="legend">
21+
<div class="legend-item">
22+
<div class="score"></div>
23+
<div>Train set</div>
24+
</div>
25+
<div class="legend-item">
26+
<div class="score validation"></div>
27+
<div>Test set</div>
28+
</div>
29+
</div>
30+
<div id="table-rows"></div>
31+
</div>
1932
</div>
2033
</template>
2134

2235
<script lang="ts" src="./app.ts"></script>
2336

2437
<style>
38+
#table {
39+
border-right: 2px solid #bbb;
40+
width: 660px;
41+
}
2542
#table .row {
2643
display: flex;
2744
align-items: center;
28-
margin: 5px 0;
45+
margin: 25px 0;
46+
}
47+
#legend {
48+
position: absolute;
49+
}
50+
.legend-item {
51+
display: flex;
52+
align-items: center;
53+
margin-bottom: 20px;
2954
}
55+
56+
.legend-item .score {
57+
width: 30px;
58+
margin-right: 10px;
59+
}
60+
3061
.label {
3162
text-align: center;
3263
font-family: "Google Sans", sans-serif;
@@ -37,26 +68,26 @@ limitations under the License.
3768
}
3869
#table .label {
3970
margin-right: 20px;
40-
width: 300px;
71+
width: 360px;
4172
text-align: right;
4273
}
4374
#table .score {
44-
background-color: #999;
75+
background-color: #0277bd;
4576
height: 30px;
4677
text-align: right;
4778
line-height: 30px;
4879
color: white;
4980
padding-right: 10px;
5081
box-sizing: border-box;
5182
}
52-
53-
#table .score-container {
54-
border-right: 1px solid black;
83+
#table .score.validation {
84+
background-color: #ef6c00;
5585
}
5686

5787
html,
5888
body {
5989
font-family: Roboto, sans-serif;
90+
color: #5f6368;
6091
}
6192

6293
body {

baseball-node/src/client/app.ts

+19-14
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,13 @@
1717

1818
import * as socketioClient from 'socket.io-client';
1919
import Vue from 'vue';
20-
2120
import {AccuracyPerClass} from '../types';
2221

2322
const SOCKET = 'http://localhost:8001/';
2423

2524
// tslint:disable-next-line:no-default-export
2625
export default Vue.extend({
27-
// tslint:disable-next-line:object-literal-shorthand
28-
mounted: function() {
26+
mounted: () => {
2927
const socket = socketioClient(
3028
SOCKET, {reconnectionDelay: 300, reconnectionDelayMax: 300});
3129
socket.connect();
@@ -42,13 +40,14 @@ export default Vue.extend({
4240
}
4341
});
4442

43+
const BAR_WIDTH_PX = 300;
44+
4545
function plotAccuracyPerClass(accPerClass: AccuracyPerClass) {
46-
const table = document.getElementById('table');
46+
const table = document.getElementById('table-rows');
4747
table.innerHTML = '';
4848

49-
const BAR_WIDTH_PX = 300;
50-
5149
for (const label in accPerClass) {
50+
const scores = accPerClass[label];
5251
// Row.
5352
const rowDiv = document.createElement('div');
5453
rowDiv.className = 'row';
@@ -64,14 +63,20 @@ function plotAccuracyPerClass(accPerClass: AccuracyPerClass) {
6463
const scoreContainer = document.createElement('div');
6564
scoreContainer.className = 'score-container';
6665
scoreContainer.style.width = BAR_WIDTH_PX + 'px';
67-
68-
const scoreDiv = document.createElement('div');
69-
scoreDiv.className = 'score';
70-
const score = accPerClass[label].training;
71-
scoreDiv.style.width = (score * BAR_WIDTH_PX) + 'px';
72-
scoreDiv.innerHTML = (score * 100).toFixed(1) + '%';
73-
74-
scoreContainer.appendChild(scoreDiv);
7566
rowDiv.appendChild(scoreContainer);
67+
68+
plotScoreBar(scores.training, scoreContainer);
69+
if (scores.validation) {
70+
plotScoreBar(scores.validation, scoreContainer, 'validation');
71+
}
7672
}
7773
}
74+
75+
function plotScoreBar(
76+
score: number, container: HTMLDivElement, className = '') {
77+
const scoreDiv = document.createElement('div');
78+
scoreDiv.className = 'score ' + className;
79+
scoreDiv.style.width = (score * BAR_WIDTH_PX) + 'px';
80+
scoreDiv.innerHTML = (score * 100).toFixed(1);
81+
container.appendChild(scoreDiv);
82+
}

baseball-node/src/client/client.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ import Vue from 'vue';
1919
import App from './App.vue';
2020

2121
// tslint:disable-next-line:no-unused-expression
22-
new Vue({el: '#app', render: h => h(App)});
22+
new Vue({el: '#app', render: h => h(App)});

baseball-node/src/server/server.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {bindTensorFlowBackend} from '@tensorflow/tfjs-node';
1919

2020
import {PitchTypeModel} from '../pitch-type-model';
2121
import {sleep} from '../utils';
22-
2322
import {Socket} from './socket';
2423

2524
const TIMEOUT_BETWEEN_EPOCHS_MS = 100;
@@ -42,4 +41,4 @@ async function run() {
4241
}
4342
}
4443

45-
run();
44+
run();

baseball-node/yarn.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -1246,7 +1246,7 @@ cipher-base@^1.0.0, cipher-base@^1.0.1, cipher-base@^1.0.3:
12461246
inherits "^2.0.1"
12471247
safe-buffer "^5.0.1"
12481248

1249-
clang-format@~1.2.3:
1249+
clang-format@^1.2.3:
12501250
version "1.2.3"
12511251
resolved "https://registry.yarnpkg.com/clang-format/-/clang-format-1.2.3.tgz#2763561aa7449c43737480f8df3a2b5b66e6cf37"
12521252
dependencies:

0 commit comments

Comments
 (0)