From c20b9fb92b56c7818a4f24b22eead665b1dd1143 Mon Sep 17 00:00:00 2001 From: gebele Date: Thu, 17 Sep 2015 16:46:32 +0200 Subject: save stadium --- application.rb | 59 +++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 15 deletions(-) (limited to 'application.rb') diff --git a/application.rb b/application.rb index acf3c73..0214db4 100644 --- a/application.rb +++ b/application.rb @@ -6,6 +6,10 @@ include OpenTox # Date: 18/11/2013 set :protection, :except => :path_traversal +configure :development do + $logger = Logger.new(STDOUT) +end + helpers do class Numeric def percent_of(n) @@ -195,24 +199,49 @@ get '/predict/:dataset/?' do end post '/predict/?' do + + # process batch prediction + if !params[:fileselect].blank? + File.open('tmp/' + params[:fileselect][:filename], "w") do |f| + f.write(params[:fileselect][:tempfile].read) + end + input = OpenTox::Dataset.from_csv_file File.join "tmp", params[:fileselect][:filename] + dataset = OpenTox::Dataset.find input.id + @compounds = dataset.compounds + @models = [] + @predictions = [] + @compounds.each do |compound| + params[:selection].keys.each do |model_id| + model = Model::Prediction.find model_id + @models << model + @predictions << model.predict(compound) + end + end + input.delete + return haml :batch + end + # validate identifier input # transfered input - @identifier = params[:identifier] - begin - # get compound from SMILES - @compound = Compound.from_smiles @identifier - rescue - @error_report = "Attention, '#{params[:identifier]}' is not a valid SMILES string." - return haml :error - end - @models = [] - @predictions = [] - params[:selection].keys.each do |model_id| - model = Model::Prediction.find model_id - @models << model - @predictions << model.predict(@compound) + if !params[:identifier].blank? + @identifier = params[:identifier] + begin + # get compound from SMILES + @compound = Compound.from_smiles @identifier + rescue + @error_report = "Attention, '#{params[:identifier]}' is not a valid SMILES string." + return haml :error + end + + @models = [] + @predictions = [] + params[:selection].keys.each do |model_id| + model = Model::Prediction.find model_id + @models << model + @predictions << model.predict(@compound) + end + haml :prediction end - haml :prediction end get '/style.css' do -- cgit v1.2.3