Skip to content
Snippets Groups Projects
Commit 93d4b4f2 authored by Mauricio Giacomini Girardello's avatar Mauricio Giacomini Girardello
Browse files

Merge branch 'master' of gitlab.c3sl.ufpr.br:portalmec/portalmec

parents 93f9ebea fc276dcf
No related branches found
No related tags found
No related merge requests found
......@@ -26,22 +26,22 @@ class ScoreCalculatorWorker
# range to 250 points, for normalized likes ( maxLikes/actualLike => [0..1] )
score += divide_by_max(
learning_object_repository.count_likes(object),
learning_object_repository.max_likes,
learning_object_repository.count('Likes', object),
learning_object_repository.max('Likes'),
weights[:likes]
)
# range to 200 points, for normalized views ( maxLikes/actualLike => [0..1] )
score += divide_by_max(
learning_object_repository.count_views(object),
learning_object_repository.max_views,
learning_object_repository.count('Views', object),
learning_object_repository.max('Views'),
weights[:views]
)
# downloads
score += divide_by_max(
learning_object_repository.count_downloads(object),
learning_object_repository.max_downloads,
learning_object_repository.count('Downloads', object),
learning_object_repository.max('Downloads'),
weights[:downloads]
)
......
......@@ -19,6 +19,12 @@ module OrientDb
get_in_edges_count edge_class, object.id
end
def max(edge_class)
Rails.cache.fetch("max_#{edge_class}", expires_in: 6.hours) do
get_max_from_edge(edge_class, 'in')
end
end
def get_max_from_edge(edge_class, type)
max = connection.command "SELECT max(#{type}('#{edge_class}').size()) FROM LearningObject"
max["result"][0]["max"]
......@@ -26,4 +32,4 @@ module OrientDb
end
end
end
\ No newline at end of file
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment