Skip to content

Commit

Permalink
optimize metric calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
imadbourouche committed Feb 18, 2025
1 parent f7498ac commit e7a0e8f
Showing 1 changed file with 2 additions and 14 deletions.
16 changes: 2 additions & 14 deletions lib/ontologies_linked_data/models/mod/semantic_artefact_catalog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,21 +263,9 @@ def self.valid_hash_code(inst, attr)
private

def calculate_attr_from_metrics(attr)
attr_to_get = attr.to_sym
submissions = LinkedData::Models::OntologySubmission.where.include(OntologySubmission.goo_attrs_to_load([attr_to_get]))
metrics_to_include = LinkedData::Models::Metric.goo_attrs_to_load([attr_to_get])
LinkedData::Models::OntologySubmission.where.models(submissions).include(metrics: metrics_to_include).all
somme = 0
submissions.each do |x|
if x.metrics
begin
somme += x.metrics.send(attr_to_get)
rescue
next
end
end
LinkedData::Models::Metric.where.include(attr).all.sum do |metric|
metric.loaded_attributes.include?(attr) ? metric.send(attr).to_i : 0
end
somme
end

end
Expand Down

0 comments on commit e7a0e8f

Please sign in to comment.