summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormr <mr@mrautenberg.de>2011-04-06 09:59:04 +0200
committermr <mr@mrautenberg.de>2011-04-06 10:06:06 +0200
commita12f491fc42b058168fb43b32e8769694e821658 (patch)
tree73b603818b1ef5cb99bcf96c68d4afb81abd44ba
parentc0bef2dc83d2ce1fea6434ca73586d49865bb810 (diff)
A&A fixes, code cleaning
-rw-r--r--lib/algorithm.rb2
-rw-r--r--lib/helper.rb57
-rw-r--r--lib/model.rb3
3 files changed, 33 insertions, 29 deletions
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