|
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"); |
5 | 5 |
|
6 |
| - function render(method) { |
7 |
| - d3.select(this).call(method); |
8 |
| - } |
| 6 | +function render(method) { |
| 7 | + d3.select(this).call(method); |
| 8 | +} |
9 | 9 |
|
10 |
| - function renderAll() { |
| 10 | +function renderAll() { |
11 | 11 | 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 | +} |
15 | 18 |
|
16 |
| - window.filter = function(filters) { |
| 19 | +window.filter = function(filters) { |
17 | 20 | filters.forEach(function(d, i) { charts[i].filter(d); });
|
18 | 21 | renderAll();
|
19 |
| - }; |
| 22 | +}; |
20 | 23 |
|
21 |
| - window.reset = function(i) { |
| 24 | +window.reset = function(i) { |
22 | 25 | charts[i].filter(null);
|
23 | 26 | renderAll();
|
24 |
| - }; |
| 27 | +}; |
25 | 28 |
|
26 | 29 |
|
27 | 30 | function barChart() {
|
@@ -217,57 +220,136 @@ function barChart() {
|
217 | 220 | };
|
218 | 221 |
|
219 | 222 | function scout_init() {
|
220 |
| - matches = []; |
| 223 | + matches = {}; |
221 | 224 | entities = [];
|
| 225 | + match_winner = {}; |
| 226 | + match_loser = {}; |
| 227 | + gamerecords = []; |
222 | 228 | $.getJSON("http://localhost:3000/matches.json", function( data ) {
|
223 | 229 | $.each( data, function( index, match ) {
|
224 | 230 | match.play_date = new Date(match.play_date);
|
225 |
| - matches.push(match); |
| 231 | + matches[match.id] = match |
226 | 232 | });
|
227 | 233 | $.getJSON("http://localhost:3000/ents.json", function( data ) {
|
228 | 234 | $.each( data, function( index, entity ) {
|
229 | 235 | 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 | + } |
230 | 253 | });
|
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(); |
234 | 259 |
|
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 }); |
238 | 280 |
|
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 }); |
241 | 283 |
|
242 | 284 | charts = [
|
243 | 285 | 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])), |
249 | 291 |
|
250 | 292 | 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) |
253 | 323 | .round(d3.time.day.round)
|
254 | 324 | .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])), |
257 | 327 | ];
|
258 | 328 |
|
259 | 329 | chart = d3.selectAll(".chart")
|
260 | 330 | .data(charts)
|
261 | 331 | .each(function(chart) { chart.on("brush", renderAll).on("brushend", renderAll); });
|
262 | 332 |
|
| 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 | + |
263 | 349 | renderAll();
|
264 | 350 |
|
265 |
| -// .domain([0, 24]) |
266 |
| -// .rangeRound([0, 10 * 24])) |
267 | 351 | });
|
268 | 352 | });
|
269 | 353 |
|
270 |
| - // raceDim.group().size() |
271 |
| - // raceDim.group().all() <-- counts for P, T and Z |
272 | 354 |
|
273 | 355 | }
|
0 commit comments