From deab3b0fd3e26e3eb6e4c65a3c081d2cf56c9611 Mon Sep 17 00:00:00 2001 From: Mateus Rambo Strey <mars11@inf.ufpr.br> Date: Wed, 24 Feb 2016 10:54:39 -0300 Subject: [PATCH] add reputation to seeds --- app/models/concerns/reviewable.rb | 4 ++ app/models/user.rb | 5 ++ ...0222144259_create_score_user_categories.rb | 2 +- db/seeds.rb | 10 ++-- db/seeds/scores.rb | 58 ++++++++++++------- 5 files changed, 51 insertions(+), 28 deletions(-) diff --git a/app/models/concerns/reviewable.rb b/app/models/concerns/reviewable.rb index 31a95808..82d9391d 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 301f8420..b9b89e6e 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 6367e0dc..b41e57f2 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 916611b8..56a5fefa 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 9e1b66e1..6668e3c1 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 -- GitLab