Skip to content
Snippets Groups Projects
Commit b84762ee authored by Mateus Rambo Strey's avatar Mateus Rambo Strey
Browse files

fix score

parent 2b38e16c
No related branches found
No related tags found
No related merge requests found
......@@ -322,7 +322,7 @@ module OrientDb
end
def get_max_from_edge(edge_class, type)
max = connection.command 'SELECT max(#{type}("#{edge_class}").size()) FROM LearningObject'
max = connection.command "SELECT max(#{type}('#{edge_class}').size()) FROM LearningObject"
max["result"][0]["max"]
end
......
......@@ -25,17 +25,37 @@ class ScoreCalculatorWorker
score += weights[:description] unless object.description.blank?
# range to 250 points, for normalized likes ( maxLikes/actualLike => [0..1] )
likes = learning_object_repository.count_likes(object)
score += (likes / learning_object_repository.max_likes)*weights[:likes] unless likes < 1
score += divide_by_max(
learning_object_repository.count_likes(object),
learning_object_repository.max_likes,
weights[:likes]
)
# range to 200 points, for normalized views ( maxLikes/actualLike => [0..1] )
views = learning_object_repository.count_views(object)
score += (views / learning_object_repository.max_views)*weights[:views] unless views < 1
downloads = learning_object_repository.count_downloads(object)
score += (downloads / learning_object_repository.max_downloads)*weights[:downloads] unless downloads < 1
score += divide_by_max(
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,
weights[:downloads]
)
learning_object_repository.update_property(object, 'score', score)
end
end
private
def divide_by_max(i, max, weight)
if (i > 0 && max > 0) && (i <= max)
(i / max) * weight
else
0
end
end
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