diff --git a/app/models/concerns/reviewable.rb b/app/models/concerns/reviewable.rb index 31a9580847d997fa6f6111cc62ddc281a3c92752..82d9391d3b9d2b14387de5874986e740cd986946 100644 --- a/app/models/concerns/reviewable.rb +++ b/app/models/concerns/reviewable.rb @@ -5,4 +5,8 @@ module Reviewable has_many :reviews, as: :reviewable, dependent: :destroy end + def review_ratings_average + array_average(reviews.map { |review| review.rating_average }) + end + end diff --git a/app/models/user.rb b/app/models/user.rb index 301f842067bf3edb30a0a34fdd4abc77acf1cc96..b9b89e6e7af55edd7800161e81eef3954ed33699 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -44,6 +44,11 @@ class User < ActiveRecord::Base false end + def review_approval_average + array = reviews.map { |review| review.rates_percentage } + array.inject(0.0) { |sum, el| sum + el } / array.size + end + private def default_role diff --git a/db/migrate/20160222144259_create_score_user_categories.rb b/db/migrate/20160222144259_create_score_user_categories.rb index 6367e0dcb79a38eada1125607d1b308a2ac5296f..b41e57f2e627d5d53ded3c2f86b4cab0a4d64e6b 100644 --- a/db/migrate/20160222144259_create_score_user_categories.rb +++ b/db/migrate/20160222144259_create_score_user_categories.rb @@ -3,7 +3,7 @@ class CreateScoreUserCategories < ActiveRecord::Migration create_table :score_user_categories do |t| t.references :score, index: true t.references :user_category, index: true - t.integer :value + t.float :value t.timestamps null: false end diff --git a/db/seeds.rb b/db/seeds.rb index 916611b8b8e911fdc9e148324dd05c6a324f2f97..56a5fefa4141f3bb8eb724c786dc95283122346b 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -18,8 +18,8 @@ User.create( ) # data for portalmec -require_relative "seeds/complaints" -require_relative "seeds/institutions" -require_relative "seeds/languages" -require_relative "seeds/ratings" -require_relative "seeds/scores" +require_relative 'seeds/complaints' +require_relative 'seeds/institutions' +require_relative 'seeds/languages' +require_relative 'seeds/ratings' +require_relative 'seeds/scores' diff --git a/db/seeds/scores.rb b/db/seeds/scores.rb index 9e1b66e1bc5abd30c2e9c4258f93fd2808eb0908..6668e3c1748f3ec3967921c608a9c57ee545e685 100644 --- a/db/seeds/scores.rb +++ b/db/seeds/scores.rb @@ -1,27 +1,41 @@ # objects +# reputation categories +categories = [ + { name: 'Iniciante' }, + { name: 'Novato' }, + { name: 'Amador' }, + { name: 'Profissional' }, + { name: 'Expert' } +] + # reputation -Score.first_or_create(name: 'Quantidade de envio de objetos', code: 'reputation_submitted', weight: 4) -Score.first_or_create(name: 'Avaliação média dos seus objetos', code: 'reputation_reviews_average_score', weight: 9) -Score.first_or_create(name: 'Adições a coleções bem avaliadas', code: 'reputation_added_in_best_collections', weight: 7) -Score.first_or_create(name: 'Melhor score', code: 'reputation_best_score', weight: 3) -Score.first_or_create(name: 'Score médio', code: 'reputation_average_score', weight: 7) -Score.first_or_create(name: 'Aprovação das avaliações em objetos de terceiros (% de sim)', code: 'reputation_reviews_rate', weight: 10) -# Score.first_or_create(name: 'Denúncias confirmadas', code: 'reputation_', weight: 0) -Score.first_or_create(name: 'Quantidade de seguidores', code: 'reputation_followers', weight: 6) -Score.first_or_create(name: 'Submissões recentes', code: 'reputation_submitted_recently', weight: 4) -Score.first_or_create(name: 'Score das coleções públicas', code: 'reputation_collection_score', weight: 3) +reputations = [ + { name: 'Quantidade de envio de objetos', code: 'reputation_submitted', weight: 4, active: true }, + { name: 'Avaliação média dos seus objetos', code: 'reputation_reviews_average_score', weight: 9, active: true }, + { name: 'Adições a coleções bem avaliadas', code: 'reputation_added_in_best_collections', weight: 7, active: true }, + { name: 'Melhor score', code: 'reputation_best_score', weight: 3, active: true }, + { name: 'Score médio', code: 'reputation_average_score', weight: 7, active: true }, + { name: 'Aprovação das avaliações em objetos de terceiros (% de sim)', code: 'reputation_reviews_rate', weight: 10, active: true }, + # { name: 'Denúncias confirmadas', code: 'reputation_confirmed_complaints', weight: 0, active: true }, + { name: 'Quantidade de seguidores', code: 'reputation_followers', weight: 6, active: true }, + { name: 'Submissões recentes', code: 'reputation_submitted_recently', weight: 4, active: true }, + { name: 'Score das coleções públicas', code: 'reputation_collection_score', weight: 3, active: true } +] -# [ -# [ 25, 3.0, 10, 500, 250, 70, 50, 5, 400], # Iniciante -# [ 50, 3.8, 20, 550, 350, 85, 250, 15, 600], # Novato -# [ 100, 4.2, 40, 600, 450, 90, 1000, 25, 750], # Amador -# [ 250, 4.9, 80, 680, 550, 95, 5000, 35, 800] # Expert -# ] +values = [ + [0,0,0,0,0,0,0,0,0], # Iniciante + [ 25, 3.0, 10, 500, 250, 70, 50, 5, 400], # Novato + [ 50, 3.8, 20, 550, 350, 85, 250, 15, 600], # Amador + [ 100, 4.2, 40, 600, 450, 90, 1000, 25, 750], # Profissional + [ 250, 4.9, 80, 680, 550, 95, 5000, 35, 800] # Expert +] -# reputation categories -UserCategory.first_or_create(name: 'Iniciante') -UserCategory.first_or_create(name: 'Novato') -UserCategory.first_or_create(name: 'Amador') -UserCategory.first_or_create(name: 'Profissional') -UserCategory.first_or_create(name: 'Expert') +# iterate to make associations +categories.each_with_index do |c, i| + category = UserCategory.where(c).first_or_create + reputations.each_with_index do |r, j| + reputation = Score.where(r).first_or_create + ScoreUserCategory.create(user_category: category, score: reputation, value: values[i][j]) + end +end