Created
March 29, 2019 17:47
-
-
Save aditya95sriram/d509f3ee91dccde96e321703ff800abc to your computer and use it in GitHub Desktop.
Optil Summary Bookmarklet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.error_regex = /(\w*):.*\s*<\/pre>/igm; | |
function init() { | |
var a = $('.content:first .row:first').clone(); | |
a.find('.alert').replaceWith("<h4>Summary <span id='rownumspan'></span></h4><pre id='hack'></pre>"); | |
$('.content:last').append(a); | |
a = $('.content:first .row:first').clone(); | |
a.empty(); | |
a.append("<div class='col-xs-6 col-sm-6 col-md-6 col-lg-6'><h4>Errors</h4><pre id='errlog'></pre></div><div class='col-xs-6 col-sm-6 col-md-6 col-lg-6'><h4>Error Summary</h4><pre id='errsum' style='white-space: pre-wrap;'>No runtime errors</pre></div>"); | |
$('.content:last').append(a); | |
var els = jQuery('#myRunsTable tbody td:first-of-type'); | |
for (var i=0; i<els.length; i++) { | |
els.eq(i).html('<button class="btn btn-info" onclick="summarize_row(' + (i+1) + ')">' + els.eq(i).html() + '</button>'); | |
} | |
} | |
function cleanup() { | |
$('#hack').empty(); | |
$('#errlog').empty(); | |
$('#errsum').html('No runtime errors'); | |
} | |
window.summarize_row = function(n) { | |
cleanup(); | |
$('span#rownumspan').text('(' + n + ')'); | |
var res = jQuery('#myRunsTable tbody tr:nth-child(' + n + ') .res-column'); | |
var data = {RTE: 0, MLE: 0, TLE: 0, WA: 0, OLE: 0, IE: 0, PLE: 0}; | |
var num_correct = 0; | |
var errs = {} | |
var re = /(.*):.*\s*<\/pre>/igm; | |
var flag = false; | |
for (var idx=0; idx<res.length; idx++) { | |
var t = res.eq(idx).text().trim(); | |
if (isNaN(parseFloat(t))) { | |
if (t in data) | |
data[t]++; | |
else | |
console.warn("unknown message", t); | |
if (t == 'RTE') { | |
flag = true; | |
var url = res.eq(idx).find('a')[0].href; | |
var xhr = jQuery.get(url).done(function(data, state, req){ | |
error_regex.lastIndex = 0; | |
var errname = error_regex.exec(data); | |
if (errname == null) { | |
errname = 'unknown'; | |
console.warn("couldn't recognize error", req.url, 'idx'); | |
} else { | |
errname = errname[1]; | |
} | |
$('#errlog').append("#" + req.idx + ":" + errname + '<br>'); | |
if (errname in errs) errs[errname]++; | |
else errs[errname] = 1; | |
$('#errsum').text(JSON.stringify(errs)); | |
}); | |
xhr.idx = idx+1; | |
xhr.url = url; | |
} | |
} else { | |
num_correct++; | |
} | |
} | |
for (var d in data) { | |
if (data[d] > 0) { | |
$('#hack').append("<b>" + d + ":</b> " + data[d] + "<br>") | |
} | |
} | |
$('#hack').append("<b> AC</b>: " + num_correct); | |
if (!flag) $('#errlog').append("No runtime errors"); | |
} | |
init(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:(function(){function init(){var r=$(".content:first .row:first").clone();r.find(".alert").replaceWith("<h4>Summary <span id='rownumspan'></span></h4><pre id='hack'></pre>"),$(".content:last").append(r),(r=$(".content:first .row:first").clone()).empty(),r.append("<div class='col-xs-6 col-sm-6 col-md-6 col-lg-6'><h4>Errors</h4><pre id='errlog'></pre></div><div class='col-xs-6 col-sm-6 col-md-6 col-lg-6'><h4>Error Summary</h4><pre id='errsum' style='white-space: pre-wrap;'>No runtime errors</pre></div>"),$(".content:last").append(r);for(var e=jQuery("#myRunsTable tbody td:first-of-type"),n=0;n<e.length;n++)e.eq(n).html('<button class="btn btn-info" onclick="summarize_row('+(n+1)+')">'+e.eq(n).html()+"</button>")}function cleanup(){$("#hack").empty(),$("#errlog").empty(),$("#errsum").html("No runtime errors")}window.error_regex=/(\w*):.*\s*<\/pre>/gim,window.summarize_row=function(r){cleanup(),$("span#rownumspan").text("("+r+")");for(var e=jQuery("#myRunsTable tbody tr:nth-child("+r+") .res-column"),n={RTE:0,MLE:0,TLE:0,WA:0,OLE:0,IE:0,PLE:0},o=0,t={},i=!1,a=0;a<e.length;a++){var s=e.eq(a).text().trim();if(isNaN(parseFloat(s))){if(s in n?n[s]++:console.warn("unknown message",s),"RTE"==s){i=!0;var l=e.eq(a).find("a")[0].href,p=jQuery.get(l).done(function(r,e,n){error_regex.lastIndex=0;var o=error_regex.exec(r);null==o?(o="unknown",console.warn("couldn't recognize error",n.url,"idx")):o=o[1],$("#errlog").append("#"+n.idx+":"+o+"<br>"),o in t?t[o]++:t[o]=1,$("#errsum").text(JSON.stringify(t))});p.idx=a+1,p.url=l}}else o++}for(var c in n)0<n[c]&&$("#hack").append("<b>"+c+":</b> "+n[c]+"<br>");$("#hack").append("<b> AC</b>: "+o),i||$("#errlog").append("No runtime errors")},init();})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment