From 7bbc70d38d81a5a57d90c525d90ccf7bf8f59426 Mon Sep 17 00:00:00 2001 From: Christoph Helma Date: Mon, 6 Jun 2011 16:54:56 +0000 Subject: halts (partially) substituted by OpenTox errors --- example.rb | 2 +- lib/active_record_setup.rb | 4 ++-- reach_reports/reach_application.rb | 8 ++++---- reach_reports/reach_service.rb | 2 +- report/report_application.rb | 2 +- report/report_persistance.rb | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/example.rb b/example.rb index b0b591e..636579e 100755 --- a/example.rb +++ b/example.rb @@ -80,7 +80,7 @@ class Example task.progress(10) log "upload dataset" - halt 400,"File not found: "+@@file.path.to_s unless File.exist?(@@file.path) + raise OpenTox::BadRequestError.new"File not found: "+@@file.path.to_s unless File.exist?(@@file.path) #data = File.read(@@file.path) #data_uri = OpenTox::RestClientWrapper.post(CONFIG[:services]["opentox-dataset"],{:content_type => @@file_type},data).chomp("\n") dataset = OpenTox::Dataset.create_from_csv_file(@@file.path,nil) diff --git a/lib/active_record_setup.rb b/lib/active_record_setup.rb index b43e692..5f081af 100755 --- a/lib/active_record_setup.rb +++ b/lib/active_record_setup.rb @@ -34,7 +34,7 @@ class ActiveRecord::Base unless self.column_names.include?(key) err = "no attribute found: '"+k.to_s+"'" # if $sinatra -# $sinatra.halt 400,err +# $sinatra.raise OpenTox::BadRequestError.newerr # else raise err # end @@ -47,4 +47,4 @@ class ActiveRecord::Base #puts "params after "+filter_params.inspect self.find(:all, :conditions => filter_params) end -end \ No newline at end of file +end diff --git a/reach_reports/reach_application.rb b/reach_reports/reach_application.rb index d914452..477adfb 100755 --- a/reach_reports/reach_application.rb +++ b/reach_reports/reach_application.rb @@ -25,7 +25,7 @@ require 'reach_reports/reach_service.rb' require "lib/format_util.rb" def extract_type(params) - halt 400, "illegal type, neither QMRF nor QPRF: "+params[:type] unless params[:type] && params[:type] =~ /(?i)Q(M|P)RF/ + raise OpenTox::BadRequestError.new "illegal type, neither QMRF nor QPRF: "+params[:type] unless params[:type] && params[:type] =~ /(?i)Q(M|P)RF/ params.delete("type") end @@ -96,7 +96,7 @@ get '/reach_report/:type/:id' do case request.env['HTTP_ACCEPT'].to_s when "application/rdf+xml" - halt 400, "application/rdf+xml not yet supported" + raise OpenTox::BadRequestError.new "application/rdf+xml not yet supported" owl = OpenTox::Owl.create(type+"Report",rep.report_uri) owl.set_data( rep.get_content.keys_to_rdf_format ) owl.rdf @@ -117,7 +117,7 @@ get '/reach_report/:type/:id' do content_type "application/x-yaml" rep.to_yaml else - halt 400, "MIME type '"+request.env['HTTP_ACCEPT'].to_s+"' not supported, valid Accept-Headers are \"application/rdf+xml\", \"application/x-yaml\", \"application/qmrf-xml\"." + raise OpenTox::BadRequestError.new "MIME type '"+request.env['HTTP_ACCEPT'].to_s+"' not supported, valid Accept-Headers are \"application/rdf+xml\", \"application/x-yaml\", \"application/qmrf-xml\"." end end @@ -128,7 +128,7 @@ post '/reach_report/:type/:id' do rep = ReachReports.get_report(type, params[:id]) input = request.env["rack.input"].read - halt 400, "no xml data specified" unless input && input.to_s.size>0 + raise OpenTox::BadRequestError.new "no xml data specified" unless input && input.to_s.size>0 LOGGER.debug "size of posted data: "+input.to_s.size.to_s ReachReports::QmrfReport.from_xml(rep,input) diff --git a/reach_reports/reach_service.rb b/reach_reports/reach_service.rb index 916a7a4..c93385c 100755 --- a/reach_reports/reach_service.rb +++ b/reach_reports/reach_service.rb @@ -289,7 +289,7 @@ module ReachReports # # report_content = get_report(type, id).get_content # keys.each do |k| -# $sinatra.halt 400, type+" unknown report property '#{key}'" unless report_content.is_a?(Hash) and report_content.has_key?(k) +# $sinatra.raise OpenTox::BadRequestError.new type+" unknown report property '#{key}'" unless report_content.is_a?(Hash) and report_content.has_key?(k) # report_content = report_content[k] # end # report_content diff --git a/report/report_application.rb b/report/report_application.rb index 3c8670a..debfe07 100755 --- a/report/report_application.rb +++ b/report/report_application.rb @@ -7,7 +7,7 @@ end def get_docbook_resource(filepath) perform do |rs| - halt 404,"not found: "+filepath unless File.exist?(filepath) + raise OpenTox::NotFoundError.new"not found: "+filepath unless File.exist?(filepath) types = MIME::Types.type_for(filepath) content_type(types[0].content_type) if types and types.size>0 and types[0] result = body(File.new(filepath)) diff --git a/report/report_persistance.rb b/report/report_persistance.rb index 78ae47b..e02387f 100755 --- a/report/report_persistance.rb +++ b/report/report_persistance.rb @@ -315,7 +315,7 @@ end # unless prop_names.include?(key) # err = "no attribute found: '"+k.to_s+"'" # if $sinatra -# $sinatra.halt 400,err +# $sinatra.raise OpenTox::BadRequestError.newerr # else # raise err # end -- cgit v1.2.3 From 6c43e8e019ca33b2b9fcad257d284b80b0b1fc57 Mon Sep 17 00:00:00 2001 From: mr Date: Wed, 15 Jun 2011 13:06:20 +0200 Subject: hotfix qmrf sqlite --- reach_reports/reach_application.rb | 14 ++++++++++++++ reach_reports/reach_persistance.rb | 14 ++++++++------ reach_reports/reach_service.rb | 20 ++++++++++++-------- 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/reach_reports/reach_application.rb b/reach_reports/reach_application.rb index cd0695c..9b45e8b 100755 --- a/reach_reports/reach_application.rb +++ b/reach_reports/reach_application.rb @@ -5,6 +5,20 @@ end QMRF_EDITOR_URI = "http://ortona.informatik.uni-freiburg.de/qmrfedit2/OT_QMRFEditor.jnlp" +# hack for as long as mysql lite is used +def mysql_lite_retry( n_times=15 ) + n_times.times do + begin + yield + return + rescue => ex + LOGGER.warn "datamapper error, wait and retry : "+ex.message + sleep(1+rand(3)) # wait 1-3 seconds + end + end + yield # try a last time +end + require 'reach_reports/reach_persistance.rb' require 'reach_reports/reach_service.rb' diff --git a/reach_reports/reach_persistance.rb b/reach_reports/reach_persistance.rb index b90778b..2dd687a 100755 --- a/reach_reports/reach_persistance.rb +++ b/reach_reports/reach_persistance.rb @@ -1202,11 +1202,13 @@ module ReachReports # end # end - [ QsarSoftware, QsarIdentifier, QmrfAuthor, ModelAuthor, Reference, QsarGeneralInformation, ModelEndpoint, QsarEndpoint, AlgorithmExplicit, - AlgorithmsDescriptor, DescriptorsGenerationSoftware, QsarAlgorithm, AppDomainSoftware, QsarApplicabilityDomain, TrainingSetData, - QsarRobustness, ValidationSetData, QsarPredictivity, QsarInterpretation, Bibliography, AttachmentTrainingData, AttachmentValidationData, - AttachmentDocument, QsarMiscellaneous, QmrfSummary, QmrfReport ].each do |model| - model.auto_upgrade! - model.raise_on_save_failure = true + mysql_lite_retry do + [ QsarSoftware, QsarIdentifier, QmrfAuthor, ModelAuthor, Reference, QsarGeneralInformation, ModelEndpoint, QsarEndpoint, AlgorithmExplicit, + AlgorithmsDescriptor, DescriptorsGenerationSoftware, QsarAlgorithm, AppDomainSoftware, QsarApplicabilityDomain, TrainingSetData, + QsarRobustness, ValidationSetData, QsarPredictivity, QsarInterpretation, Bibliography, AttachmentTrainingData, AttachmentValidationData, + AttachmentDocument, QsarMiscellaneous, QmrfSummary, QmrfReport ].each do |model| + model.auto_upgrade! + model.raise_on_save_failure = true + end end end \ No newline at end of file diff --git a/reach_reports/reach_service.rb b/reach_reports/reach_service.rb index 0cf4172..1ec48e8 100755 --- a/reach_reports/reach_service.rb +++ b/reach_reports/reach_service.rb @@ -277,7 +277,9 @@ module ReachReports end task.progress(90) if task - r.save + mysql_lite_retry do + r.save + end task.progress(100) if task end @@ -292,14 +294,16 @@ module ReachReports # end def self.get_report(type, id) - - case type - when /(?i)QMRF/ - report = ReachReports::QmrfReport.get(id) - when /(?i)QPRF/ - report = ReachReports::QprfReport.get(id) + report = nil + mysql_lite_retry(3) do + case type + when /(?i)QMRF/ + report = ReachReports::QmrfReport.get(id) + when /(?i)QPRF/ + report = ReachReports::QprfReport.get(id) + end + raise OpenTox::NotFoundError.new type+" report with id '#{id}' not found." unless report end - raise OpenTox::NotFoundError.new type+" report with id '#{id}' not found." unless report return report end -- cgit v1.2.3 From 59e1a2406354ce8a7e2b1a78f03d6ecaf6dbb297 Mon Sep 17 00:00:00 2001 From: mr Date: Wed, 15 Jun 2011 13:12:31 +0200 Subject: hotfix close R --- report/report_content.rb | 3 ++- report/statistical_test.rb | 19 +++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/report/report_content.rb b/report/report_content.rb index ca04f25..3e3c3d4 100755 --- a/report/report_content.rb +++ b/report/report_content.rb @@ -43,7 +43,8 @@ class Reports::ReportContent section_test = @xml_report.add_section(@current_section, section_title) @xml_report.add_paragraph(section_test, section_text) if section_text - @xml_report.add_table(section_test, test_attribute.to_s+", significance-level: "+level.to_s, table, true, true) + @xml_report.add_table(section_test, test_attribute.to_s+", significance-level: "+level.to_s, table, true, true) + Reports::ReportStatisticalTest.quit_r end def add_predictions( validation_set, diff --git a/report/statistical_test.rb b/report/statistical_test.rb index c37827e..5e5ea3a 100644 --- a/report/statistical_test.rb +++ b/report/statistical_test.rb @@ -1,29 +1,35 @@ #require "rubygems" #require "rinruby" -#R.quit module LIB class StatisticalTest - @@r = RinRuby.new(true,false) - # -1 -> array1 < array2 # 0 -> not difference # 1 -> array2 > array1 # def self.pairedTTest(array1, array2, significance_level=0.95) + + @@r = RinRuby.new(true,false) unless defined?(@@r) and @@r @@r.assign "v1",array1 @@r.assign "v2",array2 @@r.eval "ttest = t.test(v1,v2,paired=T)" t = @@r.pull "ttest$statistic" p = @@r.pull "ttest$p.value" - #@@r.quit if (1-significance_level > p) t else 0 end end + + def self.quit_r + begin + @@r.quit + @@r = nil + rescue + end + end end end @@ -68,6 +74,11 @@ module Reports LOGGER.debug "paired-t-testing "+attribute.to_s+" "+array1.inspect+" vs "+array2.inspect LIB::StatisticalTest.pairedTTest(array1, array2, significance_level) end + + def self.quit_r + LIB::StatisticalTest.quit_r + end + end end -- cgit v1.2.3