Skip to content

Commit f11ccf5

Browse files
committed
actually interesting now
1 parent 91fba7f commit f11ccf5

File tree

5 files changed

+160
-41
lines changed

5 files changed

+160
-41
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,7 @@ ggtracker_scan
4141

4242
# Ignore nonsense that node installed here
4343
node_modules
44+
45+
# Ignore temp data used for development
46+
public/ents.json
47+
public/matches.json

app/assets/javascripts/scout.js

Lines changed: 120 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
1-
var formatNumber = d3.format(",d"),
2-
formatChange = d3.format("+,d"),
3-
formatDate = d3.time.format("%B %d, %Y"),
4-
formatTime = d3.time.format("%I:%M %p");
1+
var formatNumber = d3.format(",d"),
2+
formatChange = d3.format("+,d"),
3+
formatDate = d3.time.format("%B %d, %Y"),
4+
formatTime = d3.time.format("%I:%M %p");
55

6-
function render(method) {
7-
d3.select(this).call(method);
8-
}
6+
function render(method) {
7+
d3.select(this).call(method);
8+
}
99

10-
function renderAll() {
10+
function renderAll() {
1111
chart.each(render);
12-
// dont have a number yet showing all
13-
// d3.select("#active").text(formatNumber(all.value()));
14-
}
12+
d3.select("#active").text(formatNumber(gr_all.value()));
13+
numWins = _.find(winGrp.all(), function(grp) {return grp.key}).value
14+
pctWins = Math.round(1000.0 * numWins / gr_all.value()) / 10.0;
15+
console.log("wins:", numWins, pctWins);
16+
d3.select("#winrate").text(pctWins);
17+
}
1518

16-
window.filter = function(filters) {
19+
window.filter = function(filters) {
1720
filters.forEach(function(d, i) { charts[i].filter(d); });
1821
renderAll();
19-
};
22+
};
2023

21-
window.reset = function(i) {
24+
window.reset = function(i) {
2225
charts[i].filter(null);
2326
renderAll();
24-
};
27+
};
2528

2629

2730
function barChart() {
@@ -217,57 +220,136 @@ function barChart() {
217220
};
218221

219222
function scout_init() {
220-
matches = [];
223+
matches = {};
221224
entities = [];
225+
match_winner = {};
226+
match_loser = {};
227+
gamerecords = [];
222228
$.getJSON("http://localhost:3000/matches.json", function( data ) {
223229
$.each( data, function( index, match ) {
224230
match.play_date = new Date(match.play_date);
225-
matches.push(match);
231+
matches[match.id] = match
226232
});
227233
$.getJSON("http://localhost:3000/ents.json", function( data ) {
228234
$.each( data, function( index, entity ) {
229235
entities.push(entity);
236+
if (entity.match_id in matches) {
237+
match = matches[entity.match_id];
238+
if (entity.win == 1) {
239+
match_winner[entity.match_id] = entity;
240+
} else if (entity.win == 0) {
241+
match_loser[entity.match_id] = entity;
242+
}
243+
if (entity.match_id in match_winner && entity.match_id in match_loser) {
244+
gamerecords.push({'player': match_winner[entity.match_id],
245+
'opponent': match_loser[entity.match_id],
246+
'match': match})
247+
gamerecords.push({'player': match_loser[entity.match_id],
248+
'opponent': match_winner[entity.match_id],
249+
'match': match})
250+
}
251+
252+
}
230253
});
231-
ent_cf = crossfilter(entities);
232-
raceDim = ent_cf.dimension(function(ent) { return ent.race });
233-
winDim = ent_cf.dimension(function(ent) { return ent.race });
254+
gr_cf = crossfilter(gamerecords);
255+
gr_all = gr_cf.groupAll();
256+
257+
raceDim = gr_cf.dimension(function(gr) { return gr.player.race });
258+
raceGrp = raceDim.group();
234259

235-
m_cf = crossfilter(matches);
236-
m_dur_d = m_cf.dimension(function(m) { return Math.min(40, m.duration_minutes) });
237-
m_dur_g = m_dur_d.group(function(d) { return Math.floor(d / 5) * 5 });
260+
oppRaceDim = gr_cf.dimension(function(gr) { return gr.opponent.race });
261+
oppRaceGrp = oppRaceDim.group();
262+
263+
winDim = gr_cf.dimension(function(gr) { return gr.player.win });
264+
winGrp = winDim.group();
265+
266+
durDim = gr_cf.dimension(function(gr) { return Math.min(40, gr.match.duration_minutes) });
267+
durGrp = durDim.group(function(d) { return Math.floor(d / 5) * 5 });
268+
269+
dateDim = gr_cf.dimension(function(gr) { return gr.match.play_date });
270+
dateGrp = dateDim.group();
271+
272+
asDim = gr_cf.dimension(function(gr) { return gr.player.as8 });
273+
asGrp = asDim.group(function(d) { return Math.floor(d / 100) * 100 });
274+
275+
oasDim = gr_cf.dimension(function(gr) { return gr.opponent.as8 });
276+
oasGrp = oasDim.group(function(d) { return Math.floor(d / 100) * 100 });
277+
278+
wsDim = gr_cf.dimension(function(gr) { return gr.player.w8 });
279+
wsGrp = wsDim.group(function(d) { return Math.floor(d / 5) * 5 });
238280

239-
m_date_d = m_cf.dimension(function(m) { return m.play_date });
240-
m_date_g = m_date_d.group(d3.time.day);
281+
owsDim = gr_cf.dimension(function(gr) { return gr.opponent.w8 });
282+
owsGrp = owsDim.group(function(d) { return Math.floor(d / 5) * 5 });
241283

242284
charts = [
243285
barChart()
244-
.dimension(m_dur_d)
245-
.group(m_dur_g)
246-
.x(d3.scale.linear()
247-
.domain([0, 40])
248-
.rangeRound([0, 20 * 8])),
286+
.dimension(asDim)
287+
.group(asGrp)
288+
.x(d3.scale.linear()
289+
.domain([0, 1500])
290+
.rangeRound([0, 10 * 15])),
249291

250292
barChart()
251-
.dimension(m_date_d)
252-
.group(m_date_g)
293+
.dimension(oasDim)
294+
.group(oasGrp)
295+
.x(d3.scale.linear()
296+
.domain([0, 1500])
297+
.rangeRound([0, 10 * 15])),
298+
299+
barChart()
300+
.dimension(wsDim)
301+
.group(wsGrp)
302+
.x(d3.scale.linear()
303+
.domain([0, 50])
304+
.rangeRound([0, 10 * 20])),
305+
306+
barChart()
307+
.dimension(owsDim)
308+
.group(owsGrp)
309+
.x(d3.scale.linear()
310+
.domain([0, 50])
311+
.rangeRound([0, 10 * 20])),
312+
313+
barChart()
314+
.dimension(durDim)
315+
.group(durGrp)
316+
.x(d3.scale.linear()
317+
.domain([0, 40])
318+
.rangeRound([0, 20 * 8])),
319+
320+
barChart()
321+
.dimension(dateDim)
322+
.group(dateGrp)
253323
.round(d3.time.day.round)
254324
.x(d3.time.scale()
255-
.domain([new Date(2014, 7, 15), new Date(2014, 8, 15)])
256-
.rangeRound([0, 10 * 30]))
325+
.domain([new Date(2014, 7, 1), new Date(2014, 8, 3)])
326+
.rangeRound([0, 10 * 40])),
257327
];
258328

259329
chart = d3.selectAll(".chart")
260330
.data(charts)
261331
.each(function(chart) { chart.on("brush", renderAll).on("brushend", renderAll); });
262332

333+
d3.selectAll("#total")
334+
.text(formatNumber(gr_cf.size()));
335+
336+
$("#player_race .selector").each( function(index, raceSelector) {
337+
$(raceSelector).click( function() {
338+
raceDim.filter(this.textContent);
339+
renderAll();
340+
})
341+
});
342+
$("#opponent_race .selector").each( function(index, raceSelector) {
343+
$(raceSelector).click( function() {
344+
oppRaceDim.filter(this.textContent);
345+
renderAll();
346+
})
347+
});
348+
263349
renderAll();
264350

265-
// .domain([0, 24])
266-
// .rangeRound([0, 10 * 24]))
267351
});
268352
});
269353

270-
// raceDim.group().size()
271-
// raceDim.group().all() <-- counts for P, T and Z
272354

273355
}

app/views/home/scout.html

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,17 @@
5252
}
5353

5454
#date-chart {
55+
width: 520px;
56+
}
57+
58+
#as-chart {
5559
width: 260px;
5660
}
61+
62+
#oas-chart {
63+
width: 260px;
64+
}
65+
5766
</style>
5867
<% end %>
5968

@@ -64,15 +73,41 @@
6473
<div id="static">
6574
<div class="content">
6675
<div class="static_inner">
67-
76+
<div id="player_race">
77+
<span>Player race:</span>
78+
<span class="selector">P</span>
79+
<span class="selector">T</span>
80+
<span class="selector">Z</span>
81+
</div>
82+
<div id="opponent_race">
83+
<span>Opponent race:</span>
84+
<span class="selector">P</span>
85+
<span class="selector">T</span>
86+
<span class="selector">Z</span>
87+
</div>
88+
<div><span id="winrate">-</span>% matches won.</div>
89+
<div><span id="active">-</span> of <span id="total">-</span> matches selected.</div>
6890
<div id="charts">
91+
<div id="as-chart" class="chart">
92+
<div class="title">Player's Army Strength @ X minutes</div>
93+
</div>
94+
<div id="oas-chart" class="chart">
95+
<div class="title">Opponent's Army Strength @ X minutes</div>
96+
</div>
97+
<div id="ws-chart" class="chart">
98+
<div class="title">Player's Workers @ X minutes</div>
99+
</div>
100+
<div id="ows-chart" class="chart">
101+
<div class="title">Opponent's Workers @ X minutes</div>
102+
</div>
69103
<div id="duration-chart" class="chart">
70104
<div class="title">Game Length, minutes</div>
71105
</div>
72106
<div id="date-chart" class="chart">
73107
<div class="title">Game Date</div>
74108
</div>
75109
</div>
110+
76111
</div>
77112
</div>
78113
</div>

public/ents.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

public/matches.json

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)