Skip to content

Commit

Permalink
optimize and remove the unused methods in the home index action
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed May 3, 2023
1 parent 92c4bb2 commit 4c24d5c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 54 deletions.
69 changes: 19 additions & 50 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,68 +7,37 @@ class HomeController < ApplicationController
include FairScoreHelper

def index
@ontologies_views = LinkedData::Client::Models::Ontology.all(include_views: true)
@ontologies = @ontologies_views.select {|o| !o.viewOf}
@ontologies_hash = Hash[@ontologies_views.map {|o| [o.acronym, o]}]
@groups = LinkedData::Client::Models::Group.all
@notes = LinkedData::Client::Models::Note.all
@last_notes = []
unless @notes.empty?
@notes.sort! {|a,b| b.created <=> a.created }
@notes[0..20].each do |n|
ont_uri = n.relatedOntology.first
ont = LinkedData::Client::Models::Ontology.find(ont_uri)
next if ont.nil?
username = n.creator.split("/").last
note = {
:uri => n.links['ui'],
:id => n.id,
:subject => n.subject,
:body => n.body,
:created => n.created,
:author => username,
:ont_name => ont.name
}
@last_notes.push note
break if @last_notes.length >= [$HOME_LATEST_NOTES_COUNT.to_i, 5].max
end
end
# Get the latest manual mappings
# All mapping classes are bidirectional.
# Each class in the list maps to all other classes in the list.
if $DISPLAY_RECENT.nil? || $DISPLAY_RECENT == true
@recent_mappings = get_recent_mappings # application_controller
end

organize_groups
@analytics = LinkedData::Client::Analytics.last_month

# Calculate BioPortal summary statistics
@ont_count = @ontologies.length
@cls_count = LinkedData::Client::Models::Metrics.all.map { |m| m.classes.to_i }.sum
@individuals_count = LinkedData::Client::Models::Metrics.all.map {|m| m.individuals.to_i}.sum
@prop_count = 36286
@ont_count = @analytics.onts.size
metrics = LinkedData::Client::Models::Metrics.all
metrics = metrics.each_with_object(Hash.new(0)) do |h, sum|
h.to_hash.slice(:classes, :properties, :individuals).each { |k, v| sum[k] += v }
end

@cls_count = metrics[:classes]
@individuals_count = metrics[:individuals]
@prop_count = metrics[:properties]
@map_count = total_mapping_count
@analytics = LinkedData::Client::Analytics.last_month
@projects_count = LinkedData::Client::Models::Project.all.length
@users_count = LinkedData::Client::Models::User.all.length
@ontology_names = @ontologies.map { |ont| ["#{ont.name} (#{ont.acronym})", ont.acronym] }
@upload_benifits = [
"Discover new insights and connections by exploring other ontologies in the repository.",
"Contribute to the growth and development of your domain by adding new concepts and categories.",
"Use version control to manage the changes to your ontology over time and collaborate with other users.",
"Get feedback and suggestions from other users who can review and comment on your ontology.",
"Get the FAIR score and metrics for your ontology."

@upload_benefits = [
'Discover new insights and connections by exploring other ontologies in the repository.',
'Contribute to the growth and development of your domain by adding new concepts and categories.',
'Use version control to manage the changes to your ontology over time and collaborate with other users.',
'Get feedback and suggestions from other users who can review and comment on your ontology.',
'Get the FAIR score and metrics for your ontology.'
]

@anal_ont_names = {}
@anal_ont_names = []
@anal_ont_numbers = []
@analytics.onts[0..4].each do |visits|
ont = @ontologies_hash[visits[:ont].to_s]
@anal_ont_names[ont.acronym] = ont.name
@anal_ont_names << visits[:ont]
@anal_ont_numbers << visits[:views]
end


end

def render_layout_partial
Expand Down
8 changes: 4 additions & 4 deletions app/views/home/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@
%img{:src => asset_path("home-random-bubbles.svg")}/
.home-bubble.home-bubble-one
%h5
= @anal_ont_names.keys[0]
= @anal_ont_names[0]
%p
= @anal_ont_numbers[0].to_s + " visits"
.home-bubble.home-bubble-two
%h5
= @anal_ont_names.keys[1]
= @anal_ont_names[1]
%p
= @anal_ont_numbers[1].to_s + " visits"
.home-bubble.home-bubble-three
%h5
= @anal_ont_names.keys[2]
= @anal_ont_names[2]
%p
= @anal_ont_numbers[2].to_s + " visits"
%a.home-bubble.home-bubble-four{:href => "/visits"}
Expand All @@ -49,7 +49,7 @@
%p Uploading an ontology is a way of sharing your domain knowledge with others.
%p By uploading your ontology to agroportal, you can:
.home-upload-benifits
- @upload_benifits.each do |benifit|
- @upload_benefits.each do |benifit|
%div
%img{:src => asset_path("check-outlined.svg")}/
%p
Expand Down

0 comments on commit 4c24d5c

Please sign in to comment.