From a12f491fc42b058168fb43b32e8769694e821658 Mon Sep 17 00:00:00 2001 From: mr Date: Wed, 6 Apr 2011 09:59:04 +0200 Subject: A&A fixes, code cleaning --- lib/algorithm.rb | 2 +- lib/helper.rb | 57 +++++++++++++++++++++++++++++--------------------------- lib/model.rb | 3 ++- 3 files changed, 33 insertions(+), 29 deletions(-) (limited to 'lib') diff --git a/lib/algorithm.rb b/lib/algorithm.rb index c8cb116..167c964 100644 --- a/lib/algorithm.rb +++ b/lib/algorithm.rb @@ -246,7 +246,7 @@ module OpenTox # Gauss kernel # @return [Float] def self.gauss(x, sigma = 0.3) - d = 1.0 - x + d = 1.0 - x.to_f Math.exp(-(d*d)/(2*sigma*sigma)) end diff --git a/lib/helper.rb b/lib/helper.rb index 3031b74..af92419 100644 --- a/lib/helper.rb +++ b/lib/helper.rb @@ -55,10 +55,7 @@ helpers do end end -end - -before do - unless !AA_SERVER or login_requests or CONFIG[:authorization][:free_request].include?(env['REQUEST_METHOD']) + def get_subjectid begin subjectid = nil subjectid = session[:subjectid] if session[:subjectid] @@ -69,31 +66,37 @@ before do subjectid = CGI.unescape(subjectid) if subjectid.include?("%23") @subjectid = subjectid rescue - #LOGGER.debug "OpenTox ruby api wrapper: helper before filter: NO subjectid for URI: #{request.env['rack.url_scheme']}://#{request.env['HTTP_HOST']}#{request.env['REQUEST_URI']}" - subjectid = "" + subjectid = nil end - @subjectid = subjectid - protected!(subjectid) - - extension = File.extname(request.path_info) # params[:id] is not yet available + end + def get_extension + extension = File.extname(request.path_info) unless extension.empty? - #request.path_info.sub!(/\.#{extension}$/,'') - case extension - when "html" - @accept = 'text/html' - when "yaml" - @accept = 'application/x-yaml' - when "csv" - @accept = 'text/csv' - when "rdfxml" - @accept = 'application/rdf+xml' - when "xls" - @accept = 'application/ms-excel' - else - halt 404, "File format #{extension} not supported." - end - end - + case extension.gsub(".","") + when "html" + @accept = 'text/html' + when "yaml" + @accept = 'application/x-yaml' + when "csv" + @accept = 'text/csv' + when "rdfxml" + @accept = 'application/rdf+xml' + when "xls" + @accept = 'application/ms-excel' + when "css" + @accept = 'text/css' + else + # halt 404, "File format #{extension} not supported." + end + end + end +end + +before do + @subjectid = get_subjectid() + @accept = get_extension() + unless !AA_SERVER or login_requests or CONFIG[:authorization][:free_request].include?(env['REQUEST_METHOD']) + protected!(@subjectid) end end diff --git a/lib/model.rb b/lib/model.rb index 74408d8..c46f2a0 100644 --- a/lib/model.rb +++ b/lib/model.rb @@ -113,9 +113,10 @@ module OpenTox # @param [optional,Hash] params Parameters for the lazar algorithm (OpenTox::Algorithm::Lazar) # @return [OpenTox::Model::Lazar] lazar model def self.create(params) + subjectid = params[:subjectid] lazar_algorithm = OpenTox::Algorithm::Generic.new File.join( CONFIG[:services]["opentox-algorithm"],"lazar") model_uri = lazar_algorithm.run(params) - OpenTox::Model::Lazar.find(model_uri, params[:subjectid]) + OpenTox::Model::Lazar.find(model_uri, subjectid) end # Get a parameter value -- cgit v1.2.3