:javascript function progress(model,idx,total) { var p = 100/total; var percent = Math.round((idx+1)*p); var bar = document.getElementById("bar_"+model); var prog = document.getElementById("progress_"+model); bar.style.width = percent + '%'; if (percent == 100){ prog.style.display = "none"; }; } var HttpClient = function() { this.get = function(aUrl, aCallback) { var anHttpRequest = new XMLHttpRequest(); anHttpRequest.onreadystatechange = function() { if (anHttpRequest.readyState == 4 && anHttpRequest.status == 200) aCallback(anHttpRequest.responseText); } anHttpRequest.open( "GET", aUrl, true ); anHttpRequest.send( null ); } }; function renderResponse(model,idx,compound,last,total,tmppath) { // create request if (model == "Cramer"){ var dataset = '#{@dataset.id}'; var uri = "#{to("/batch/")}" + model + '/?dataset=' + escape(dataset) + '&tmppath=' + tmppath; } else { var dataset = '#{@dataset.id}'; var uri = "#{to("/batch/")}" + model + '/?compound=' + escape(compound) + '&dataset=' + dataset + '&idx=' + idx + '&tmppath=' + tmppath; }; var aClient = new HttpClient(); aClient.get(uri, function(res) { // progress bar function progress(model,idx,total); var response = JSON.parse(res); var td = document.getElementById("prediction_"+compound+'_'+model+'_'+idx); //td.innerHTML = ""; if (model != "Cramer"){ // init general structure a = ["title", "type", "db_hit", "measurements", "prediction", "interval", "probability", "warnings", "info"]; // handles consesus mutagenicity if (response['sa_prediction'] != false){ var p = document.createElement("p"); var h = document.createElement("h5"); p.id = "sa"; // Consensus mutagenicity var t = document.createTextNode("Consensus mutagenicity"); h.appendChild(t); p.appendChild(h); // handle db_hit first if (response['db_hit'] != false){ var value = document.createTextNode(response['db_hit']); p.appendChild(value); var h2 = document.createElement("h5"); var t = document.createTextNode("Measurements:"); h2.appendChild(t); p.appendChild(h2); for (var i=0; i to('/predict')} %span.glyphicon.glyphicon-menu-left{:aria=>{:hidden=>"true"}} New Prediction / show file name %topline %div.row %div.col-md-4 %h3 Batch Prediction Results: %div.col-md-8 %h3= @filename / displays prediction result in table tabs #tabs %ul.nav.nav-tabs.nav-justified{:id=>"batchTabs", :role=>"tablist"} - @models.each_with_index do |model,i| - m = Model::Validation.find model unless model == "Cramer" %li{:class => ("active" if i == 0)} %a{:href => "#results_#{i+1}", :id => "linkTab#{i+1}", data: {toggle:"tab"}} = (model == "Cramer") ? "Oral toxicity (Cramer rules)" : "#{m.endpoint} (#{m.species})" %img.dlwait{:src=>"/images/wait30trans.gif", :id=>"circle_#{model}", :class=>"circle", :alt=>"wait", :style=>"display:none;"} %a.csv.btn{:id => "downbutton_#{model}", :href=>"#{to("/predict/#{@tmppaths[model]}/#{model}/#{@filename}")}", :title=>"download", :style=>"display:none;"} %span.glyphicon.glyphicon-download-alt CSV %div.tab-content - csize = @compounds.size - msize = @models.size - timer = 0 - @models.each_with_index do |model,j| #results.tab-pane{:id=>"#{j+1}", :class => ("active" if j == 0)} %div{:id=>"progress_"+model, :style=>"width:100%;height:2px;position:relative;background-color:#ccc;"} %div{:id=>"bar_"+model, :style=>"background-color: #4CAF50;width:10px;height:2px;position:absolute;"} %table.table.table-bordered %tbody - @compounds.each_with_index do |compound,cidx| - timer += 800 :javascript $(document).ready(function() { $("img.circle").show(); var model = '#{model}', msize = #{msize}, idx = #{j+1}, last = false, compound = '#{compound.id}', csize = #{csize}, cidx = #{cidx}, timer = #{timer}, tmppath = '#{@tmppaths[model]}'; // check for last request; if (cidx+1 == csize) { last = true; }; setTimeout(function(){ if (model != "Cramer"){ renderResponse(model,cidx,compound,last,csize,tmppath); } else if (model == "Cramer" && cidx == 0){ renderResponse(model,cidx,compound,last,csize,tmppath); }; }, timer ); }); // table layout: // one row per prediction; // first col compound; sec col results %tr{:id=>model} // compound %td.col-md-6{:id=>"compound"} %p=embedded_svg(compound.svg, title: compound.smiles) %p=compound.smiles // prediction values from js function %td.col-md-6{:id=>"prediction_#{compound.id}_#{model}_#{cidx}", :style => "vertical-align:top;"}