264 <h1>Reports</h1> |
267 <h1>Reports</h1> |
265 <div class="settings"> |
268 <div class="settings"> |
266 <div class="setting"><input type="text" id="stat-count-limit" value="100"> times</div> |
269 <div class="setting"><input type="text" id="stat-count-limit" value="100"> times</div> |
267 <div class="setting">limit to <input type="text" id="stat-time-limit" value="10"> sec</div> |
270 <div class="setting">limit to <input type="text" id="stat-time-limit" value="10"> sec</div> |
268 <button id="statistic">Start</button> |
271 <button id="statistic">Start</button> |
|
272 <div class="setting"><input type="checkbox" id="report-score"/> score</div> |
|
273 <div class="setting"><input type="checkbox" id="report-turn"/> turn</div> |
|
274 <div class="setting"><input type="checkbox" id="report-speed"/> speed</div> |
269 <div class="clearfix"></div> |
275 <div class="clearfix"></div> |
270 </div> |
276 </div> |
271 <div id="reports"> |
277 <div id="reports"> |
272 <div class="clearfix"></div> |
278 <div class="clearfix"></div> |
273 </div> |
279 </div> |
728 stat.ts = tsTo - tsFrom; |
734 stat.ts = tsTo - tsFrom; |
729 stats.push(stat); |
735 stats.push(stat); |
730 if (tsTo - tsLimitFrom >= tsLimit) |
736 if (tsTo - tsLimitFrom >= tsLimit) |
731 break; |
737 break; |
732 } |
738 } |
|
739 var scoreChecked = document.getElementById('report-score').checked; |
|
740 var turnChecked = document.getElementById('report-turn').checked; |
|
741 var speedChecked = document.getElementById('report-speed').checked; |
733 var histo = {}; |
742 var histo = {}; |
734 for (i = stats.length-1; i >= 0; i--) { |
743 for (i = stats.length-1; i >= 0; i--) { |
735 var stat = stats[i]; |
744 var stat = stats[i]; |
736 if ( ! histo[stat.max]) |
745 if ( ! histo[stat.max]) |
737 histo[stat.max] = { n: 0, minSpeed: Infinity, meanSpeed: 0, maxSpeed: 0, minTurn: Infinity, meanTurn: 0, maxTurn: 0, minScore: Infinity, meanScore: 0, maxScore: 0 }; |
746 histo[stat.max] = { n: 0, minSpeed: Infinity, meanSpeed: 0, maxSpeed: 0, minTurn: Infinity, meanTurn: 0, maxTurn: 0, minScore: Infinity, meanScore: 0, maxScore: 0 }; |
738 var row = histo[stat.max]; |
747 var row = histo[stat.max]; |
739 row.n++; |
748 row.n++; |
740 var speed = (stat.turn * 1000.0) / stat.ts; |
749 if (scoreChecked) { |
741 row.minSpeed = Math.min(row.minSpeed, speed); |
750 row.minScore = Math.min(row.minScore, stat.score); |
742 row.meanSpeed += speed; |
751 row.meanScore += stat.score; |
743 row.maxSpeed = Math.max(row.maxSpeed, speed); |
752 row.maxScore = Math.max(row.maxScore, stat.score); |
744 row.minTurn = Math.min(row.minTurn, stat.turn); |
753 } |
745 row.meanTurn += stat.turn; |
754 if (turnChecked) { |
746 row.maxTurn = Math.max(row.maxTurn, stat.turn); |
755 row.minTurn = Math.min(row.minTurn, stat.turn); |
747 row.minScore = Math.min(row.minScore, stat.score); |
756 row.meanTurn += stat.turn; |
748 row.meanScore += stat.score; |
757 row.maxTurn = Math.max(row.maxTurn, stat.turn); |
749 row.maxScore = Math.max(row.maxScore, stat.score); |
758 } |
|
759 if (speedChecked) { |
|
760 var speed = (stat.turn * 1000.0) / stat.ts; |
|
761 row.minSpeed = Math.min(row.minSpeed, speed); |
|
762 row.meanSpeed += speed; |
|
763 row.maxSpeed = Math.max(row.maxSpeed, speed); |
|
764 } |
750 } |
765 } |
751 for (var i in histo) { |
766 for (var i in histo) { |
752 var row = histo[i]; |
767 var row = histo[i]; |
753 var n = row.n; |
768 var n = row.n; |
754 row.meanSpeed = row.meanSpeed / n; |
769 if (scoreChecked) |
755 row.meanTurn = row.meanTurn / n; |
770 row.meanScore = row.meanScore / n; |
756 row.meanScore = row.meanScore / n; |
771 if (turnChecked) |
|
772 row.meanTurn = row.meanTurn / n; |
|
773 if (speedChecked) |
|
774 row.meanSpeed = row.meanSpeed / n; |
757 } |
775 } |
758 var reportDom = document.createElement('div'); |
776 var reportDom = document.createElement('div'); |
759 reportDom.classList.add('report'); |
777 reportDom.classList.add('report'); |
760 var h5Dom = document.createElement('h5'); |
778 var h5Dom = document.createElement('h5'); |
761 h5Dom.appendChild(document.createTextNode(ui.ai.currentName)); |
779 h5Dom.appendChild(document.createTextNode(ui.ai.currentName)); |
764 var tbl = []; |
782 var tbl = []; |
765 for (var i = maxVals.length-1; i >= 0; i--) { |
783 for (var i = maxVals.length-1; i >= 0; i--) { |
766 var maxVal = maxVals[i]; |
784 var maxVal = maxVals[i]; |
767 var row = histo[maxVals[i]]; |
785 var row = histo[maxVals[i]]; |
768 var perc = parseFloat((100 * row.n / gameCnt).toPrecision(3)); |
786 var perc = parseFloat((100 * row.n / gameCnt).toPrecision(3)); |
769 var meanScore = parseFloat(row.meanScore.toPrecision(3)); |
787 var tblRow = [maxVal, row.n, perc]; |
770 tbl.push([maxVal, row.n, perc, row.minScore, meanScore, row.maxScore]); |
788 if (scoreChecked) { |
771 } |
789 tblRow.push(row.minScore); |
772 var tableDom = ui.dom.table( |
790 var meanScore = parseFloat(row.meanScore.toPrecision(3)); |
773 tbl, |
791 tblRow.push(meanScore); |
774 ['maxVal', 'n', '%', 'min score', 'mean score', 'max score'], |
792 tblRow.push(row.maxScore); |
775 { tableClass: 'report-by-maxval' }); |
793 } |
|
794 if (turnChecked) { |
|
795 tblRow.push(row.minTurn); |
|
796 tblRow.push(Math.floor(row.meanTurn)); |
|
797 tblRow.push(row.maxTurn); |
|
798 } |
|
799 if (speedChecked) { |
|
800 tblRow.push(parseFloat(row.minSpeed.toPrecision(3))); |
|
801 tblRow.push(parseFloat(row.meanSpeed.toPrecision(3))); |
|
802 tblRow.push(parseFloat(row.maxSpeed.toPrecision(3))); |
|
803 } |
|
804 tbl.push(tblRow); |
|
805 } |
|
806 var tblCols = ['maxVal', 'n', '%']; |
|
807 if (scoreChecked) { |
|
808 tblCols.push('min score'); |
|
809 tblCols.push('mean score'); |
|
810 tblCols.push('max score'); |
|
811 } |
|
812 if (turnChecked) { |
|
813 tblCols.push('min turn'); |
|
814 tblCols.push('mean turn'); |
|
815 tblCols.push('max turn'); |
|
816 } |
|
817 if (speedChecked) { |
|
818 tblCols.push('min speed'); |
|
819 tblCols.push('mean speed'); |
|
820 tblCols.push('max speed'); |
|
821 } |
|
822 var tableDom = ui.dom.table(tbl, tblCols, { tableClass: 'report-by-maxval' }); |
776 reportDom.appendChild(tableDom); |
823 reportDom.appendChild(tableDom); |
777 reportsDom.insertBefore(reportDom, reportsDom.firstChild); |
824 reportsDom.insertBefore(reportDom, reportsDom.firstChild); |
778 } |
825 } |
779 |
826 |
780 var statisticBtn = document.getElementById('statistic'); |
827 var statisticBtn = document.getElementById('statistic'); |