33module MappingStatistics
44 extend ActiveSupport ::Concern
55
6- MAPPING_STATISTICS_URL = "#{ LinkedData ::Client . settings . rest_url } /mappings/statistics/ontologies/ "
6+ MAPPING_STATISTICS_URL = "#{ LinkedData ::Client . settings . rest_url } /mappings/statistics/ontologies"
77
88 def mapping_counts ( source_acronym )
99 mapping_counts = [ ]
@@ -13,10 +13,11 @@ def mapping_counts(source_acronym)
1313 display_links : false ,
1414 display_context : false
1515 )
16+ ontologies_by_acronym = ontologies . index_by ( &:acronym )
1617
17- statistics = LinkedData ::Client ::HTTP . get ( MAPPING_STATISTICS_URL + source_acronym )
18+ statistics = LinkedData ::Client ::HTTP . get ( " #{ MAPPING_STATISTICS_URL } / #{ source_acronym } " )
1819 statistics &.each_pair do |target_acronym , count |
19- ont = ontologies . find { | o | o . acronym . eql? target_acronym . to_s }
20+ ont = ontologies_by_acronym [ target_acronym . to_s ]
2021 # Handle the case where statistics are still present for a deleted ontology
2122 next if ont . nil? || ont . summaryOnly
2223
@@ -25,4 +26,17 @@ def mapping_counts(source_acronym)
2526
2627 mapping_counts . sort! { |a , b | a [ :target_ontology ] . name . downcase <=> b [ :target_ontology ] . name . downcase }
2728 end
29+
30+ def total_mapping_count ( ont_acronyms )
31+ stats = LinkedData ::Client ::HTTP . get ( MAPPING_STATISTICS_URL )
32+ return 0 if stats . blank?
33+
34+ stats = stats . to_h . compact
35+ stats = stats . select { |k , _ | ont_acronyms . include? ( k . to_s ) }
36+ stats . transform_values! ( &:to_i )
37+ stats . values . sum
38+ rescue StandardError => e
39+ Log . add :error , e . message
40+ 0
41+ end
2842end
0 commit comments