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

add reputation to seeds

parent ba03323b
No related branches found
No related tags found
No related merge requests found
......@@ -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
......@@ -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
......
......@@ -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
......
......@@ -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'
# 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
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