Skip to content

Commit

Permalink
use Metric to optimize the metric calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
imadbourouche committed Feb 20, 2025
1 parent 57ecdf5 commit bae1917
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,12 @@ def self.valid_hash_code(inst, attr)
private

def calculate_attr_from_metrics(attr)
@submissions ||= LinkedData::Models::Ontology.where.all.map(&:latest_submission)
LinkedData::Models::OntologySubmission.where.models(@submissions).include(metrics: attr).all.sum do |sub|
sub.metrics.loaded_attributes.include?(attr) ? sub.metrics.send(attr).to_i : 0
latest_metrics = LinkedData::Models::Metric.where.include(attr).all
.group_by { |x| x.id.split('/')[-4] }
.transform_values { |metrics| metrics.max_by { |x| x.id.split('/')[-2].to_i } }

latest_metrics.values.sum do |metric|
metric.loaded_attributes.include?(attr) ? metric.send(attr).to_i : 0
end
end

Expand Down

0 comments on commit bae1917

Please sign in to comment.