summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgebele <gebele@in-silico.ch>2019-07-11 15:59:13 +0000
committergebele <gebele@in-silico.ch>2019-07-11 15:59:13 +0000
commit5490f6214f3a22216f7980c7d46f6d9fe10a4924 (patch)
tree7da1f991c1f31048b7b55a2dbc5729da7694860d
parent5efd8128dc5bdb9ffc0aa4798f8aa303973794e6 (diff)
simplify js code;reorder js code;
-rw-r--r--application.rb7
-rw-r--r--public/javascripts/lazar-gui.js15
-rw-r--r--views/batch.haml53
-rw-r--r--views/neighbors.haml2
-rw-r--r--views/prediction.haml12
5 files changed, 44 insertions, 45 deletions
diff --git a/application.rb b/application.rb
index 4ed4a31..76137b9 100644
--- a/application.rb
+++ b/application.rb
@@ -85,6 +85,13 @@ options "*" do
end
get '/predict/?' do
+ if params[:tpid]
+ begin
+ Process.kill(9,params[:tpid].to_i) if !params[:tpid].blank?
+ rescue
+ nil
+ end
+ end
@models = OpenTox::Model::Validation.all
@endpoints = @models.collect{|m| m.endpoint}.sort.uniq
@models.count > 0 ? (haml :predict) : (haml :info)
diff --git a/public/javascripts/lazar-gui.js b/public/javascripts/lazar-gui.js
index e87b0fa..585f2ac 100644
--- a/public/javascripts/lazar-gui.js
+++ b/public/javascripts/lazar-gui.js
@@ -61,7 +61,8 @@ function getInput(){
return 0;
};
-// display wait animation
+// display wait animation after click on predict button
+// check form fields, input file or SMILES, endpoint selection
function showcircle() {
switch (getInput()){
case 0:
@@ -97,7 +98,6 @@ function showcircle() {
function checkfile() {
var fileinput = document.getElementById("fileselect");
if(fileinput.value != "") {
- //TODO check file type is csv
return true;
};
alert("Please select a file (csv).");
@@ -116,7 +116,7 @@ function checksmiles () {
return true;
};
-// check if a model was selected
+// check if an endpoint was selected
function checkboxes () {
var checked = false;
$('input[type="checkbox"]').each(function() {
@@ -190,14 +190,9 @@ progress = function(value,id) {
};
};
-remaining = function(id,tasktime,type,compoundsSize) {
+remaining = function(id,approximate) {
var est = document.getElementById("est_"+id);
var now = new Date().getTime();
- if ( type == "true" ){
- var approximate = new Date(tasktime*1000 + compoundsSize*100*(id+1));
- } else {
- var approximate = new Date(tasktime*1000 + compoundsSize*1000*(id+1));
- }
var remain = approximate - now;
var minutes = Math.floor((remain % (1000 * 60 * 60)) / (1000 * 60));
var seconds = Math.floor((remain % (1000 * 60)) / 1000);
@@ -209,7 +204,7 @@ remaining = function(id,tasktime,type,compoundsSize) {
est.innerHTML = newtime;
};
-renderTask = function(task_uri,model_id,id) {
+renderTask = function(task_uri,id) {
var uri = task_uri;
var aClient = new HttpClient();
aClient.get(uri, function(res) {
diff --git a/views/batch.haml b/views/batch.haml
index c454ac7..3f54772 100644
--- a/views/batch.haml
+++ b/views/batch.haml
@@ -6,9 +6,20 @@
%div.card-body
%h3.card-title="Batch prediction results for: #{@filename}"
+ // prepare variable values for javascript
+ // increase timer interval for large datasets
+ - ctimer = ((@compounds_size/1000) == 0 ? 1000 : ((@compounds_size/1000)*1000))
+ - approx = {}
+ - sum_approx = 0
+ // process batch predictions
- @models.each_with_index do |model,idx|
- m = Model::Validation.find model
- task = @tasks[idx].id
+ - tasktime = task.generation_time.to_i
+ // assume single compound prediction time: classification=0.1s,regression=0.5s
+ - task_approx = m.classification? ? (tasktime*1000 + @compounds_size*100) : (tasktime*1000 + @compounds_size*500)
+ - approx[idx] = task_approx + sum_approx
+ - sum_approx += (m.classification? ? @compounds_size*100 : @compounds_size*1000)
#result.card.bg-light{:id=>idx}
%div.card-body
%div.row
@@ -26,31 +37,29 @@
%div{:id=>"bar_#{idx}", :style=>"background-color: #4CAF50;width:10px;height:3px;position:absolute;"}
%p{:id=>"est_#{idx}"}
waiting ...
- - # increase interval timer for large datasets
- - ctimer = ((@compounds_size/1000) == 0 ? 1000 : ((@compounds_size/1000)*1000))
:javascript
- var timer = #{ctimer};
- var tasktime = #{task.generation_time.to_i};
- var compoundsSize = #{@compounds_size};
- var task_uri = "#{to("/prediction/task/?turi=#{task}")}";
- $(document).ready(function(){
- // check button class before execute a task
- if (#{idx} > 0){
- markers[#{idx}] = setInterval(function(){
- var button = document.getElementById("detailsbutton_#{idx-1}");
- if(!button.classList.contains('disabled')){
- renderTask(task_uri,'#{model}',#{idx});
- remaining(#{idx},tasktime,#{m.classification?},compoundsSize);
- }
- }, timer );
- }else{
- markers[#{idx}] = setInterval(function(){
- renderTask(task_uri,'#{model}',#{idx});
- remaining(#{idx},tasktime,#{m.classification?},compoundsSize);
- }, timer );
- };
+ $(document).ready(function() {
+ taskProgress('#{idx}','#{ctimer}','#{approx[idx]}','#{to("/prediction/task/?turi=#{task}")}');
});
#data-container.card.d-none.table-responsive{:id=>idx}
+ :javascript
+ taskProgress = function(idx,timer,approximate,task_uri){
+ // wait until previous task is completed
+ if (idx > 0){
+ markers[idx] = setInterval(function(){
+ var button = document.getElementById("detailsbutton_"+(idx-1));
+ if(!button.classList.contains('disabled')){
+ renderTask(task_uri,idx);
+ remaining(idx,approximate);
+ }
+ }, timer );
+ }else{
+ markers[idx] = setInterval(function(){
+ renderTask(task_uri,idx);
+ remaining(idx,approximate);
+ }, timer );
+ };
+ };
%div.modal.fade{:id=>"details", :tabindex=>"-1", :role=>"dialog"}
%div.modal-dialog.modal-lg{:role=>"document"}
%div.modal-content
diff --git a/views/neighbors.haml b/views/neighbors.haml
index 91b5f57..5f3e2bc 100644
--- a/views/neighbors.haml
+++ b/views/neighbors.haml
@@ -8,7 +8,7 @@
/ get predictionFeature type
- m = Model::Lazar.find model.model_id.to_s
%li.nav-item
- %a.nav-link{:class => ("active" if i ==0), :href => "#results_#{i+1}", :id => "linkTab#{i+1}", data: {toggle:"tab"}, :onclick=>"sortTable('#{i+1}');"}
+ %a.nav-link{:class => ("active" if i ==0), :href => "#results_#{i+1}", :id => "linkTab#{i+1}", data: {toggle:"tab"}}
= "#{model.endpoint} (#{model.species})"
%div.tab-content
- @predictions.each_with_index do |prediction,j|
diff --git a/views/prediction.haml b/views/prediction.haml
index bde2397..fe1e487 100644
--- a/views/prediction.haml
+++ b/views/prediction.haml
@@ -1,15 +1,3 @@
-:javascript
- $(document).ready(function(){
- $('[data-toggle="popover"]').popover();
- $('.modal').on('hidden.bs.modal', function () {
- $(this).removeData('bs.modal');
- });
- $('.modal').on('show.bs.modal', function(e){
- var button = $(e.relatedTarget);
- var modal = $(this);
- modal.find('.modal-content').load(button.data("remote"));
- });
- });
%div.card
%a.btn.btn-outline-info{:href => to('/predict')}
%span.fa.fa-caret-left