Skip to content

Commit 200a78d

Browse files
committed
lots of interesting data to play with now
1 parent f11ccf5 commit 200a78d

File tree

3 files changed

+78
-13
lines changed

3 files changed

+78
-13
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,5 @@ ggtracker_scan
4343
node_modules
4444

4545
# Ignore temp data used for development
46-
public/ents.json
47-
public/matches.json
46+
public/ents.*
47+
public/matches.*

app/assets/javascripts/scout.js

Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function renderAll() {
1212
d3.select("#active").text(formatNumber(gr_all.value()));
1313
numWins = _.find(winGrp.all(), function(grp) {return grp.key}).value
1414
pctWins = Math.round(1000.0 * numWins / gr_all.value()) / 10.0;
15-
console.log("wins:", numWins, pctWins);
15+
// console.log("wins:", numWins, pctWins);
1616
d3.select("#winrate").text(pctWins);
1717
}
1818

@@ -220,24 +220,37 @@ function barChart() {
220220
};
221221

222222
function scout_init() {
223+
var start = Date.now();
224+
223225
matches = {};
224226
entities = [];
225227
match_winner = {};
226228
match_loser = {};
227229
gamerecords = [];
228-
$.getJSON("http://localhost:3000/matches.json", function( data ) {
229-
$.each( data, function( index, match ) {
230+
231+
entity_non_numerics = ["race", "chosen_race", "win"]
232+
233+
d3.csv("http://localhost:3000/matches.csv", function(error, csv_matches) {
234+
csv_matches.forEach( function(match, index) {
230235
match.play_date = new Date(match.play_date);
236+
match.id = +match.id
237+
match.average_league = +match.average_league
238+
match.duration_minutes = +match.duration_minutes
231239
matches[match.id] = match
232240
});
233-
$.getJSON("http://localhost:3000/ents.json", function( data ) {
234-
$.each( data, function( index, entity ) {
241+
d3.csv("http://localhost:3000/ents.csv", function(error, csv_ents) {
242+
csv_ents.forEach( function(entity, index) {
243+
for (var key in entity) {
244+
if (!(_.contains(entity_non_numerics, key))) {
245+
entity[key] = +entity[key];
246+
}
247+
}
235248
entities.push(entity);
236249
if (entity.match_id in matches) {
237250
match = matches[entity.match_id];
238-
if (entity.win == 1) {
251+
if (entity.win == "true") {
239252
match_winner[entity.match_id] = entity;
240-
} else if (entity.win == 0) {
253+
} else if (entity.win == "false") {
241254
match_loser[entity.match_id] = entity;
242255
}
243256
if (entity.match_id in match_winner && entity.match_id in match_loser) {
@@ -251,6 +264,7 @@ function scout_init() {
251264

252265
}
253266
});
267+
var rec_built = Date.now();
254268
gr_cf = crossfilter(gamerecords);
255269
gr_all = gr_cf.groupAll();
256270

@@ -280,20 +294,38 @@ function scout_init() {
280294

281295
owsDim = gr_cf.dimension(function(gr) { return gr.opponent.w8 });
282296
owsGrp = owsDim.group(function(d) { return Math.floor(d / 5) * 5 });
297+
298+
mb2Dim = gr_cf.dimension(function(gr) { return Math.floor(gr.player.miningbase_2 / 60) });
299+
mb2Grp = mb2Dim.group(function(d) { return d; })
300+
301+
omb2Dim = gr_cf.dimension(function(gr) { return Math.floor(gr.opponent.miningbase_2 / 60) });
302+
omb2Grp = omb2Dim.group(function(d) { return d; })
303+
304+
lgDim = gr_cf.dimension(function(gr) { return gr.match.average_league });
305+
lgGrp = lgDim.group(function(d) { return d; });
306+
307+
var dims_built = Date.now();
283308

284309
charts = [
310+
barChart()
311+
.dimension(lgDim)
312+
.group(lgGrp)
313+
.x(d3.scale.linear()
314+
.domain([0, 6])
315+
.rangeRound([0, 10 * 15])),
316+
285317
barChart()
286318
.dimension(asDim)
287319
.group(asGrp)
288320
.x(d3.scale.linear()
289-
.domain([0, 1500])
321+
.domain([0, 2000])
290322
.rangeRound([0, 10 * 15])),
291323

292324
barChart()
293325
.dimension(oasDim)
294326
.group(oasGrp)
295327
.x(d3.scale.linear()
296-
.domain([0, 1500])
328+
.domain([0, 2000])
297329
.rangeRound([0, 10 * 15])),
298330

299331
barChart()
@@ -310,6 +342,20 @@ function scout_init() {
310342
.domain([0, 50])
311343
.rangeRound([0, 10 * 20])),
312344

345+
barChart()
346+
.dimension(mb2Dim)
347+
.group(mb2Grp)
348+
.x(d3.scale.linear()
349+
.domain([0, 15])
350+
.rangeRound([0, 10 * 20])),
351+
352+
barChart()
353+
.dimension(omb2Dim)
354+
.group(omb2Grp)
355+
.x(d3.scale.linear()
356+
.domain([0, 15])
357+
.rangeRound([0, 10 * 20])),
358+
313359
barChart()
314360
.dimension(durDim)
315361
.group(durGrp)
@@ -348,6 +394,14 @@ function scout_init() {
348394

349395
renderAll();
350396

397+
var end = Date.now();
398+
var total_time = end - start;
399+
console.log("init took " + (total_time / 1000) + " seconds");
400+
401+
var build_rec = (rec_built - start) / 1000;
402+
var build_dims = (dims_built - rec_built) / 1000;
403+
var build_chart = (end - dims_built) / 1000;
404+
console.log(build_rec, build_dims, build_chart);
351405
});
352406
});
353407

app/views/home/scout.html

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@
4747
stroke: #666;
4848
}
4949

50+
#league-chart {
51+
width: 260px;
52+
}
53+
5054
#duration-chart {
5155
width: 260px;
5256
}
@@ -72,7 +76,6 @@
7276

7377
<div id="static">
7478
<div class="content">
75-
<div class="static_inner">
7679
<div id="player_race">
7780
<span>Player race:</span>
7881
<span class="selector">P</span>
@@ -88,6 +91,9 @@
8891
<div><span id="winrate">-</span>% matches won.</div>
8992
<div><span id="active">-</span> of <span id="total">-</span> matches selected.</div>
9093
<div id="charts">
94+
<div id="league-chart" class="chart">
95+
<div class="title">Game League</div>
96+
</div>
9197
<div id="as-chart" class="chart">
9298
<div class="title">Player's Army Strength @ X minutes</div>
9399
</div>
@@ -100,6 +106,12 @@
100106
<div id="ows-chart" class="chart">
101107
<div class="title">Opponent's Workers @ X minutes</div>
102108
</div>
109+
<div id="mb2-chart" class="chart">
110+
<div class="title">Player's 2nd Mining Base Timing</div>
111+
</div>
112+
<div id="omb2-chart" class="chart">
113+
<div class="title">Opponent's 2nd Mining Base Timing</div>
114+
</div>
103115
<div id="duration-chart" class="chart">
104116
<div class="title">Game Length, minutes</div>
105117
</div>
@@ -108,6 +120,5 @@
108120
</div>
109121
</div>
110122

111-
</div>
112123
</div>
113124
</div>

0 commit comments

Comments
 (0)