From 74332693fed1d5ecb695dd6ae0c2fc611d14c4d7 Mon Sep 17 00:00:00 2001 From: gebele Date: Fri, 9 Aug 2019 12:28:19 +0000 Subject: do not delete batch tr_dataset if one of model tr_dataset;error message if dataset has no compounds --- application.rb | 4 ++-- helper.rb | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/application.rb b/application.rb index 246efe1..064c488 100644 --- a/application.rb +++ b/application.rb @@ -184,7 +184,7 @@ post '/predict/?' do raise "Wrong file extension for '#{params[:fileselect][:filename]}'. Please upload a CSV file." end @filename = params[:fileselect][:filename] - File.open('tmp/' + params[:fileselect][:filename], "w") do |f| + File.open('tmp/' + @filename, "w") do |f| f.write(params[:fileselect][:tempfile].read) end # check CSV structure by parsing and header check @@ -198,6 +198,7 @@ post '/predict/?' do unless params[:batchfile].blank? dataset = Dataset.from_csv_file File.join("tmp", params[:batchfile]) + raise "No compounds in Dataset. Please read the HELP page." if dataset.compounds.size == 0 response['Content-Type'] = "application/json" return {:dataset_id => dataset.id.to_s, :models => params[:models]}.to_json end @@ -233,7 +234,6 @@ post '/predict/?' do maintask[:subTasks] = @tasks.collect{|t| t.id} maintask.save @pid = maintask.pid - File.delete File.join(dataset.source) response['Content-Type'] = "text/html" return haml :batch else diff --git a/helper.rb b/helper.rb index 82482d4..a5ce15e 100644 --- a/helper.rb +++ b/helper.rb @@ -31,10 +31,11 @@ helpers do predictionDataset = Dataset.find t.dataset_id if t.dataset_id if predictionDataset && idx == 0 trainingDataset = Dataset.find predictionDataset.source - source = trainingDataset.source - trainingDataset.delete - File.delete File.join(source) if File.exists? File.join(source) predictionDataset.delete + # delete training dataset unless it is one used for prediction models + models = Model::Validation.all + training_datasets = models.collect{|m| m.training_dataset.id.to_s} + trainingDataset.delete unless training_datasets.include?(trainingDataset.id.to_s) elsif predictionDataset predictionDataset.delete end -- cgit v1.2.3