summaryrefslogtreecommitdiff
path: root/report
diff options
context:
space:
mode:
authormguetlein <martin.guetlein@gmail.com>2011-04-08 15:39:55 +0200
committermguetlein <martin.guetlein@gmail.com>2011-05-03 11:46:30 +0200
commit78751b778a5dabfac142a017fc1e0d8d1c045acd (patch)
tree6257c90d38d1082637a65e3846944bd313464edd /report
parentd5fe870fa184ef44390a0311664b7813360a44f5 (diff)
switch from datamapper/mysql to redis (sqlite for qmrf)
Diffstat (limited to 'report')
-rwxr-xr-xreport/environment.rb2
-rwxr-xr-xreport/report_factory.rb6
-rwxr-xr-xreport/report_persistance.rb49
-rwxr-xr-xreport/validation_access.rb20
-rwxr-xr-xreport/validation_data.rb50
5 files changed, 61 insertions, 66 deletions
diff --git a/report/environment.rb b/report/environment.rb
index 12e3272..aa8ab56 100755
--- a/report/environment.rb
+++ b/report/environment.rb
@@ -13,7 +13,7 @@ end
require "lib/ot_predictions.rb"
#require "lib/active_record_setup.rb"
-require "lib/data_mapper_util.rb"
+#require "lib/data_mapper_util.rb"
require "report/plot_factory.rb"
require "report/xml_report.rb"
diff --git a/report/report_factory.rb b/report/report_factory.rb
index e770d2f..f48d11a 100755
--- a/report/report_factory.rb
+++ b/report/report_factory.rb
@@ -76,7 +76,7 @@ module Reports::ReportFactory
end
task.progress(90) if task
- report.add_result(validation_set, Lib::ALL_PROPS, "All Results", "All Results")
+ report.add_result(validation_set, Validation::ALL_PROPS, "All Results", "All Results")
report.add_predictions( validation_set )
task.progress(100) if task
report
@@ -89,7 +89,7 @@ module Reports::ReportFactory
validation_set.get_values(:crossvalidation_id,false).inspect) if validation_set.unique_value(:crossvalidation_id)==nil
validation_set.load_cv_attributes
raise OpenTox::BadRequestError.new("num validations ("+validation_set.size.to_s+") is not equal to num folds ("+
- validation_set.unique_value(:num_folds).to_s+")") unless validation_set.unique_value(:num_folds)==validation_set.size
+ validation_set.unique_value(:num_folds).to_s+")") unless validation_set.unique_value(:num_folds).to_i==validation_set.size
raise OpenTox::BadRequestError.new("num different folds is not equal to num validations") unless validation_set.num_different_values(:crossvalidation_fold)==validation_set.size
raise OpenTox::BadRequestError.new("validations must have unique feature type, i.e. must be either all regression, "+
+"or all classification validations") unless validation_set.unique_feature_type
@@ -116,7 +116,7 @@ module Reports::ReportFactory
end
task.progress(90) if task
- report.add_result(validation_set, Lib::ALL_PROPS, "All Results", "All Results")
+ report.add_result(validation_set, Validation::ALL_PROPS, "All Results", "All Results")
report.add_predictions( validation_set ) #, [:crossvalidation_fold] )
task.progress(100) if task
report
diff --git a/report/report_persistance.rb b/report/report_persistance.rb
index df4930c..9097fa3 100755
--- a/report/report_persistance.rb
+++ b/report/report_persistance.rb
@@ -188,22 +188,21 @@ module Reports
# serialize :model_uris
# alias_attribute :date, :created_at
- class ReportData
- include DataMapper::Resource
+ class ReportData < Ohm::Model
- property :id, Serial
- property :report_type, String, :length => 255
- property :created_at, DateTime
- property :validation_uris, Object
- property :crossvalidation_uris, Object
- property :model_uris, Object
- property :algorithm_uris, Object
+ attribute :report_type
+ attribute :created_at
+ attribute :validation_uris
+ attribute :crossvalidation_uris
+ attribute :model_uris
+ attribute :algorithm_uris
+
+ index :report_type
attr_accessor :subjectid
- after :save, :check_policy
- private
- def check_policy
+ def save
+ super
OpenTox::Authorization.check_policy(report_uri, subjectid)
end
@@ -245,32 +244,30 @@ module Reports
report.subjectid = subjectid
report.report_type = type
report.save
+ OpenTox::Authorization.check_policy(report.report_uri, subjectid)
new_report_with_id(report_content, type, report.id)
end
def list_reports(type, filter_params={})
- filter_params["report_type"]=type unless filter_params.has_key?("report_type")
- #ReportData.find_like(filter_params).delete_if{|r| r.report_type!=type}.collect{ |r| r.id }
-
- filter_params = Lib::DataMapperUtil.check_params(ReportData, filter_params)
+ LOGGER.debug "find reports for params: "+filter_params.inspect
# unfortunately, datamapper does not allow searching in Objects
# do filtering for list = Object params manually
list_params = {}
[:validation_uris, :crossvalidation_uris, :algorithm_uris, :model_uris].each do |l|
list_params[l] = filter_params.delete(l) if filter_params.has_key?(l)
end
-
- reports = ReportData.all(filter_params).delete_if{|r| r.report_type!=type}
+ reports = ReportData.find( :report_type => type )
list_params.each do |k,v|
- reports = reports.delete_if{ |r| !r.send(k).include?(v) }
+ reports = reports.collect{|x| x}.delete_if{ |r| !r.send(k).include?(v) }
end
reports.collect{ |r| r.id }
end
def get_report(type, id, format, force_formating, params)
- report = ReportData.first({:id => id, :report_type => type})
- raise OpenTox::NotFoundError.new("Report with id='"+id.to_s+"' and type='"+type.to_s+"' not found.") unless report
+ report = ReportData[id]
+ raise OpenTox::NotFoundError.new("Report with id='"+id.to_s+"' and type='"+type.to_s+"' not found.") if
+ report==nil or report.report_type!=type
# begin
# report = ReportData.find(:first, :conditions => {:id => id, :report_type => type})
# rescue ActiveRecord::RecordNotFound
@@ -294,9 +291,10 @@ module Reports
# raise OpenTox::NotFoundError.new("Report with id='"+id.to_s+"' and type='"+type.to_s+"' not found.")
# end
# ReportData.delete(id)
- report = ReportData.first({:id => id, :report_type => type})
- raise OpenTox::NotFoundError.new("Report with id='"+id.to_s+"' and type='"+type.to_s+"' not found.") unless report
- report.destroy
+ report = ReportData[id]
+ raise OpenTox::NotFoundError.new("Report with id='"+id.to_s+"' and type='"+type.to_s+"' not found.") if
+ report==nil || report.report_type!=type
+ report.delete
if (subjectid)
begin
res = OpenTox::Authorization.delete_policies_from_uri(report.report_uri, subjectid)
@@ -310,9 +308,6 @@ module Reports
end
end
-Reports::ReportData.auto_upgrade!
-Reports::ReportData.raise_on_save_failure = true
-
#module Reports
# def self.check_filter_params(model, filter_params)
# prop_names = model.properties.collect{|p| p.name.to_s}
diff --git a/report/validation_access.rb b/report/validation_access.rb
index 53ecc46..96dfbf3 100755
--- a/report/validation_access.rb
+++ b/report/validation_access.rb
@@ -21,11 +21,11 @@ class Reports::ValidationDB
# rescue => ex
# raise "could not access crossvalidation with id "+validation_id.to_s+", error-msg: "+ex.message
# end
- cv = Lib::Crossvalidation.get( cv_id )
+ cv = Validation::Crossvalidation.get( cv_id )
raise OpenTox::NotFoundError.new "crossvalidation with id "+cv_id.to_s+" not found" unless cv
raise OpenTox::BadRequestError.new("crossvalidation with id '"+cv_id.to_s+"' not finished") unless cv.finished
- #res += Lib::Validation.find( :all, :conditions => { :crossvalidation_id => cv_id } ).collect{|v| v.validation_uri.to_s}
- res += Lib::Validation.all( :crossvalidation_id => cv_id ).collect{|v| v.validation_uri.to_s }
+ #res += Validation::Validation.find( :all, :conditions => { :crossvalidation_id => cv_id } ).collect{|v| v.validation_uri.to_s}
+ res += Validation::Validation.find( :crossvalidation_id => cv_id ).collect{|v| v.validation_uri.to_s }
else
res += [u.to_s]
end
@@ -42,16 +42,16 @@ class Reports::ValidationDB
v = nil
raise OpenTox::NotAuthorizedError.new "Not authorized: GET "+uri.to_s if
AA_SERVER and !OpenTox::Authorization.authorized?(uri,"GET",subjectid)
- v = Lib::Validation.get(validation_id)
+ v = Validation::Validation.get(validation_id)
raise OpenTox::NotFoundError.new "validation with id "+validation_id.to_s+" not found" unless v
raise OpenTox::BadRequestError.new "validation with id "+validation_id.to_s+" is not finished yet" unless v.finished
- (Lib::VAL_PROPS + Lib::VAL_CV_PROPS).each do |p|
+ (Validation::VAL_PROPS + Validation::VAL_CV_PROPS).each do |p|
validation.send("#{p.to_s}=".to_sym, v.send(p))
end
- {:classification_statistics => Lib::VAL_CLASS_PROPS,
- :regression_statistics => Lib::VAL_REGR_PROPS}.each do |subset_name,subset_props|
+ {:classification_statistics => Validation::VAL_CLASS_PROPS,
+ :regression_statistics => Validation::VAL_REGR_PROPS}.each do |subset_name,subset_props|
subset = v.send(subset_name)
subset_props.each{ |prop| validation.send("#{prop.to_s}=".to_sym, subset[prop]) } if subset
end
@@ -60,11 +60,11 @@ class Reports::ValidationDB
def init_cv(validation)
#cv = Lib::Crossvalidation.find(validation.crossvalidation_id)
- cv = Lib::Crossvalidation.get(validation.crossvalidation_id)
+ cv = Validation::Crossvalidation.get(validation.crossvalidation_id)
raise OpenTox::BadRequestError.new "no crossvalidation found with id "+validation.crossvalidation_id.to_s unless cv
- Lib::CROSS_VAL_PROPS.each do |p|
- validation.send("#{p.to_s}=".to_sym, cv[p])
+ Validation::CROSS_VAL_PROPS.each do |p|
+ validation.send("#{p.to_s}=".to_sym, cv.send(p.to_s))
end
end
diff --git a/report/validation_data.rb b/report/validation_data.rb
index 15d51ec..9212c98 100755
--- a/report/validation_data.rb
+++ b/report/validation_data.rb
@@ -51,13 +51,13 @@ end
module Reports
- # = Reports::Validation
+ # = ReportValidation
#
# contains all values of a validation object
#
- class Validation
+ class ReportValidation
- @@validation_access = Reports::ValidationDB.new
+ @@validation_access = ValidationDB.new
# for overwriting validation source (other than using webservices)
def self.reset_validation_access(validation_access)
@@ -69,7 +69,7 @@ module Reports
end
# create member variables for all validation properties
- @@validation_attributes = Lib::ALL_PROPS +
+ @@validation_attributes = Validation::ALL_PROPS +
VAL_ATTR_VARIANCE.collect{ |a| (a.to_s+"_variance").to_sym } +
VAL_ATTR_RANKING.collect{ |a| (a.to_s+"_ranking").to_sym }
@@validation_attributes.each{ |a| attr_accessor a }
@@ -85,7 +85,7 @@ module Reports
# returns/creates predictions, cache to save rest-calls/computation time
#
# call-seq:
- # get_predictions => Reports::Predictions
+ # get_predictions => Predictions
#
def get_predictions( task=nil )
if @predictions
@@ -127,13 +127,13 @@ module Reports
@@validation_access.init_cv(self)
end
- @@persistance = Reports::ReportService.persistance
+ @@persistance = ReportService.persistance
def validation_report_uri
#puts "searching for validation report: "+self.validation_uri.to_s
return @validation_report_uri if @validation_report_uri!=nil
ids = @@persistance.list_reports("validation",{:validation_uris=>validation_uri })
- @validation_report_uri = Reports::ReportService.instance.get_uri("validation",ids[-1]) if ids and ids.size>0
+ @validation_report_uri = ReportService.instance.get_uri("validation",ids[-1]) if ids and ids.size>0
end
def cv_report_uri
@@ -142,7 +142,7 @@ module Reports
raise "no cv uri "+to_yaml unless self.crossvalidation_uri
ids = @@persistance.list_reports("crossvalidation",{:crossvalidation=>self.crossvalidation_uri.to_s })
#puts "-> "+ids.inspect
- @cv_report_uri = Reports::ReportService.instance.get_uri("crossvalidation",ids[-1]) if ids and ids.size>0
+ @cv_report_uri = ReportService.instance.get_uri("crossvalidation",ids[-1]) if ids and ids.size>0
end
def clone_validation
@@ -160,9 +160,9 @@ module Reports
def initialize(validation_uris=nil, subjectid=nil)
@unique_values = {}
- validation_uris = Reports::Validation.resolve_cv_uris(validation_uris, subjectid) if validation_uris
+ validation_uris = ReportValidation.resolve_cv_uris(validation_uris, subjectid) if validation_uris
@validations = Array.new
- validation_uris.each{|u| @validations.push(Reports::Validation.new(u, subjectid))} if validation_uris
+ validation_uris.each{|u| @validations.push(ReportValidation.new(u, subjectid))} if validation_uris
end
@@ -249,12 +249,12 @@ module Reports
def get_domain_for_attr( attribute )
class_domain = get_class_domain()
- if Lib::Validation.classification_property?(attribute) and
- !Lib::Validation.depends_on_class_value?(attribute)
+ if Validation::Validation.classification_property?(attribute) and
+ !Validation::Validation.depends_on_class_value?(attribute)
[ nil ]
- elsif Lib::Validation.classification_property?(attribute) and
+ elsif Validation::Validation.classification_property?(attribute) and
class_domain.size==2 and
- Lib::Validation.complement_exists?(attribute)
+ Validation::Validation.complement_exists?(attribute)
[ class_domain[0] ]
else
class_domain
@@ -270,10 +270,10 @@ module Reports
# returns a new set with all validation that have values as specified in the map
#
# call-seq:
- # filter(map) => Reports::ValidationSet
+ # filter(map) => ValidationSet
#
def filter(map)
- new_set = Reports::ValidationSet.new
+ new_set = ValidationSet.new
validations.each{ |v| new_set.validations.push(v) if v.has_values?(map) }
return new_set
end
@@ -282,10 +282,10 @@ module Reports
# e.g. create set with predictions: collect{ |validation| validation.get_predictions!=null }
#
# call-seq:
- # filter_proc(proc) => Reports::ValidationSet
+ # filter_proc(proc) => ValidationSet
#
def collect
- new_set = Reports::ValidationSet.new
+ new_set = ValidationSet.new
validations.each{ |v| new_set.validations.push(v) if yield(v) }
return new_set
end
@@ -398,19 +398,19 @@ module Reports
# to_array(attributes) => array
#
def merge(equal_attributes)
- new_set = Reports::ValidationSet.new
+ new_set = ValidationSet.new
# unique values stay unique when merging
# derive unique values before, because model dependent props cannot be accessed later (when mergin validations from different models)
new_set.unique_values = @unique_values
#compute grouping
- grouping = Reports::Util.group(@validations, equal_attributes)
+ grouping = Util.group(@validations, equal_attributes)
#puts "groups "+grouping.size.to_s
- Lib::MergeObjects.register_merge_attributes( Reports::Validation,
- Lib::VAL_MERGE_AVG,Lib::VAL_MERGE_SUM,Lib::VAL_MERGE_GENERAL) unless
- Lib::MergeObjects.merge_attributes_registered?(Reports::Validation)
+ Lib::MergeObjects.register_merge_attributes( ReportValidation,
+ Validation::VAL_MERGE_AVG,Validation::VAL_MERGE_SUM,Validation::VAL_MERGE_GENERAL) unless
+ Lib::MergeObjects.merge_attributes_registered?(ReportValidation)
#merge
grouping.each do |g|
@@ -438,12 +438,12 @@ module Reports
def compute_ranking(equal_attributes, ranking_attribute, class_value=nil )
#puts "compute_ranking("+equal_attributes.inspect+", "+ranking_attribute.inspect+", "+class_value.to_s+" )"
- new_set = Reports::ValidationSet.new
+ new_set = ValidationSet.new
(0..@validations.size-1).each do |i|
new_set.validations.push(@validations[i].clone_validation)
end
- grouping = Reports::Util.group(new_set.validations, equal_attributes)
+ grouping = Util.group(new_set.validations, equal_attributes)
grouping.each do |group|
# put indices and ranking values for current group into hash