From 2a748125c27c7f7c41a32a1dba14484c66dc351f Mon Sep 17 00:00:00 2001 From: Alex AUVOLAT Date: Fri, 9 Aug 2013 19:29:59 +0200 Subject: Minor changes... --- js/liststudy.js | 55 ++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 17 deletions(-) (limited to 'js/liststudy.js') diff --git a/js/liststudy.js b/js/liststudy.js index d4a74c8..820e35d 100644 --- a/js/liststudy.js +++ b/js/liststudy.js @@ -7,6 +7,7 @@ var items = []; var max_score = 0; var med_score = 0; +var avg_score = 0; function show_batch_table() { process_items(); @@ -15,38 +16,57 @@ function show_batch_table() { } function process_items() { + var item_idx = {}; + for (var i = 0; i < batch_data.items.length; i++) { + var d = batch_data.items[i]; + item_idx[d[0]] = items.length; items.push( - {"info": batch_data.items[i], - "win": 0, "fail": 0, "score": 0} + {"info": d, + "win": 0, "fail": 0, "score": 0, "marker": ""} ); } + + // Calculate total wins and losses for (var i = 0; i < reviews_data.length; i++) { for (var j = 0; j < reviews_data[i].results.length; j++) { var n = reviews_data[i].results[j][0]; var s = reviews_data[i].results[j][1]; - for (var k = 0; k < items.length; k++) { - if (items[k].info[0] == n) { - if (s == 1) { - items[k].win++; - items[k].score++; - } else if (s == -1) { - items[k].fail++; - items[k].score--; - } - } + var k = item_idx[n]; + if (s == 1) { + items[k].win++; + items[k].score++; + } else if (s == -1) { + items[k].fail++; + items[k].score--; } } } + + // Make marker indication : -1 (fail) -> red, 0 (dunno) -> yellow + if (reviews_data.length > 0) { + var t = reviews_data[reviews_data.length - 1].results; + for (var j = 0; j < t.length; j++) { + var s = t[j][1]; + if (s == 1) continue; + var n = t[j][0]; + var k = item_idx[n]; + items[k].marker = items[k].marker + '*'; + } + } + + + // Get max score for (var i = 0; i < items.length; i++) { if (items[i].score > max_score) max_score = items[i].score; - med_score += items[i].score; + avg_score += items[i].score; } - med_score = Math.ceil(med_score * 10 / items.length) / 10; + avg_score = Math.ceil(avg_score * 20 / items.length) / 20; + med_score = max_score / 2; } function show_contents_table() { - var html = ''; + var html = '
'; for (var i = 0; i < batch_data.columns.length; i++) { var c = batch_data.columns[i]; html += ''; @@ -54,6 +74,7 @@ function show_contents_table() { html += ''; for (var i = 0; i < items.length; i++) { html += ''; + html += ''; for (var j = 0; j < items[i].info.length; j++) { html += ''; } @@ -61,11 +82,11 @@ function show_contents_table() { html += ' 0 ? (items[i].fail > items[i].win ? ' style="background-color: #ff7777"' : ' style="background-color: #FFFF00"') : '') + '>' + items[i].fail + ''; html += ''; } html += '
' + c + ' - hidewinfailscore
' + items[i].marker + '' + items[i].info[j] + '' + items[i].score + '
'; - html += '

Medium score : ' + med_score + '

'; + html += '

Average score : ' + avg_score + '

'; $("items").innerHTML = html; } -- cgit v1.2.3