diff options
author | mguetlein <martin.guetlein@gmail.com> | 2011-02-07 15:38:33 +0100 |
---|---|---|
committer | mguetlein <martin.guetlein@gmail.com> | 2011-02-07 15:38:33 +0100 |
commit | d99823f61fc3b2f463bc1a51db0a952c965c2141 (patch) | |
tree | caf259594bc93a7f0eeaf14e217cc9c6a6ff06ae /reach_reports | |
parent | 67e72fe916dab5c0ee18e65d4cbc1f3e0ed64b99 (diff) |
add a&a to qmrf reports
Diffstat (limited to 'reach_reports')
-rwxr-xr-x | reach_reports/reach_application.rb | 7 | ||||
-rwxr-xr-x | reach_reports/reach_persistance.rb | 11 | ||||
-rwxr-xr-x | reach_reports/reach_service.rb | 42 | ||||
-rwxr-xr-x | reach_reports/reach_test.rb | 4 |
4 files changed, 50 insertions, 14 deletions
diff --git a/reach_reports/reach_application.rb b/reach_reports/reach_application.rb index fd77078..969ce8b 100755 --- a/reach_reports/reach_application.rb +++ b/reach_reports/reach_application.rb @@ -65,7 +65,7 @@ post '/reach_report/:type' do LOGGER.info "creating "+type+" report "+params.inspect #puts "creating "+type+" report "+params.inspect - result_uri = ReachReports.create_report(type,params,request.env["rack.input"]) + result_uri = ReachReports.create_report(type,params,@subjectid,request.env["rack.input"]) if result_uri and result_uri.task_uri? halt 202,result_uri+"\n" @@ -123,6 +123,11 @@ post '/reach_report/:type/:id' do #f.puts rep.to_xml end +delete '/reach_report/:type/:id' do + type = extract_type(params) + LOGGER.info "delete "+type+" report with id '"+params[:id].to_s+"'" + ReachReports.delete_report(type, params[:id], @subjectid) +end #get '/reach_report/:type/:id/:section' do diff --git a/reach_reports/reach_persistance.rb b/reach_reports/reach_persistance.rb index ec45ba4..3118809 100755 --- a/reach_reports/reach_persistance.rb +++ b/reach_reports/reach_persistance.rb @@ -1001,6 +1001,17 @@ module ReachReports CHAPTERS.each{ |c,clazz| has 1, c } + attr_accessor :subjectid + + after :save, :check_policy + private + def check_policy + raise "no id" unless @id + #raise "no subjectid" unless subjectid + OpenTox::Authorization.check_policy(report_uri, subjectid) + end + + public def to_yaml super(:methods => CHAPTERS) end diff --git a/reach_reports/reach_service.rb b/reach_reports/reach_service.rb index f5b4b12..028a53c 100755 --- a/reach_reports/reach_service.rb +++ b/reach_reports/reach_service.rb @@ -21,7 +21,7 @@ module ReachReports end end - def self.create_report( type, params, xml_data=nil ) + def self.create_report( type, params, subjectid, xml_data=nil ) case type when /(?i)QMRF/ @@ -30,12 +30,14 @@ module ReachReports $url_provider.url_for("/reach_report/"+type, :full) ) do |task| #, params report = ReachReports::QmrfReport.new :model_uri => params[:model_uri] + report.subjectid = subjectid build_qmrf_report(report, task) report.report_uri end result_uri = task.uri elsif xml_data and (input = xml_data.read).to_s.size>0 report = ReachReports::QmrfReport.new + report.subjectid = subjectid ReachReports::QmrfReport.from_xml(report,input) result_uri = report.report_uri else @@ -57,14 +59,11 @@ module ReachReports result_uri end - - def self.build_qmrf_report(r, task=nil) #puts r.model_uri - model = OpenTox::Model::Generic.find(r.model_uri) - raise "model not found "+r.model_uri.to_s unless model - feature_type = model.feature_type + model = OpenTox::Model::Generic.find(r.model_uri, r.subjectid) + feature_type = model.feature_type(r.subjectid) # chapter 1 r.qsar_identifier = QsarIdentifier.new @@ -132,7 +131,7 @@ module ReachReports val_datasets = [] if algorithm - cvs = Lib::Crossvalidation.find_all_uniq({:algorithm_uri => algorithm.uri, :finished => true}) + cvs = Lib::Crossvalidation.find_all_uniq({:algorithm_uri => algorithm.uri, :finished => true},r.subjectid) # PENDING: cv classification/regression hack cvs = cvs.delete_if do |cv| #val = Validation::Validation.first( :all, :conditions => { :crossvalidation_id => cv.id } ) @@ -165,7 +164,8 @@ module ReachReports lmo << "dataset (see 9.3 Validation data): "+cv.dataset_uri val_datasets << cv.dataset_uri lmo << "settings: num-folds="+cv.num_folds.to_s+", random-seed="+cv.random_seed.to_s+", stratified:"+cv.stratified.to_s - val = YAML.load( OpenTox::RestClientWrapper.get File.join(cv.crossvalidation_uri,"statistics") ) + + val = YAML.load( OpenTox::RestClientWrapper.get(File.join(cv.crossvalidation_uri,"statistics"),{:subjectid => r.subjectid}) ) case feature_type when "classification" lmo << "percent_correct: "+val[OT.classificationStatistics][OT.percentCorrect].to_s @@ -174,7 +174,8 @@ module ReachReports lmo << "root_mean_squared_error: "+val[OT.regressionStatistics][OT.rootMeanSquaredError].to_s lmo << "r_square "+val[OT.regressionStatistics][OT.rSquare].to_s end - reports = OpenTox::RestClientWrapper.get File.join(CONFIG[:services]["opentox-validation"],"report/crossvalidation?crossvalidation_uris="+cv.crossvalidation_uri) + reports = OpenTox::RestClientWrapper.get(File.join(CONFIG[:services]["opentox-validation"], + "report/crossvalidation?crossvalidation_uris="+cv.crossvalidation_uri),{:subjectid => r.subjectid}) if reports and reports.chomp.size>0 lmo << "for more info see report: "+reports.split("\n")[0] else @@ -226,10 +227,11 @@ module ReachReports v << "root_mean_squared_error: "+validation.regression_statistics[:root_mean_squared_error].to_s v << "r_square "+validation.regression_statistics[:r_square].to_s end - reports = OpenTox::RestClientWrapper.get(File.join(CONFIG[:services]["opentox-validation"], - "report/validation?validation_uris="+validation.validation_uri)) - if reports and reports.size>0 - v << "for more info see report: "+reports.split("\n")[0] + report = OpenTox::ValidationReport.find_for_validation(validation.validation_uri,r.subjectid) + #reports = OpenTox::RestClientWrapper.get(File.join(CONFIG[:services]["opentox-validation"], + # "report/validation?validation_uris="+validation.validation_uri),{:subjectid => r.subjectid}) + if report + v << "for more info see report: "+report.uri else v << "for more info see report: not yet created for '"+validation.validation_uri+"'" end @@ -299,4 +301,18 @@ module ReachReports raise OpenTox::NotFoundError.new type+" report with id '#{id}' not found." unless report return report end + + def self.delete_report(type, id, subjectid=nil) + + 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 + OpenTox::Authorization.delete_policies_from_uri(report.report_uri, subjectid) if subjectid + return report.destroy + end + end diff --git a/reach_reports/reach_test.rb b/reach_reports/reach_test.rb index 9a354e7..7d1569d 100755 --- a/reach_reports/reach_test.rb +++ b/reach_reports/reach_test.rb @@ -76,6 +76,10 @@ class ReachTest < Test::Unit::TestCase def test_it + delete '/reach_report/QMRF/3' + puts last_response.body + + exit # testResource = TestResource.new # # TestResource.info |