diff --git a/app/models/shrimpo.rb b/app/models/shrimpo.rb index 9172e1b5..63a3a22d 100644 --- a/app/models/shrimpo.rb +++ b/app/models/shrimpo.rb @@ -118,13 +118,17 @@ def tally_results! entry.update! total_score: total_score if self.mega? + # calculate score for each category self.shrimpo_voting_categories.each do |voting_category| total = entry.shrimpo_votes.where(shrimpo_voting_category: voting_category).sum(:score) - # ShrimpoVotingCategoryScore.create entry: entry, shrimpo_voting_category: voting_category, score: total + # create shrimpo_voting_category_score + # ShrimpoEntryVotingCategoryScore.create entry: entry, shrimpo_voting_category: voting_category, score: total end - # calculate score for each category - # - # create shrimpo_voting_category_score + + # calculate rank for each category + # ShrimpoEntryVotingCategoryScore.where(shrimpo_voting_category: voting_category).sort_by(&:score).reverse.each_with_index do |voting_cat_score, index| + # voting_cat_score.update! ranking: index + 1 + # end end end diff --git a/app/models/shrimpo_voting_category_score.rb b/app/models/shrimpo_voting_category_score.rb new file mode 100644 index 00000000..ec4646ef --- /dev/null +++ b/app/models/shrimpo_voting_category_score.rb @@ -0,0 +1,4 @@ +class ShrimpoVotingCategoryScore < ApplicationRecord + belongs_to :shrimpo_entry + belongs_to :shrimpo_voting_category +end diff --git a/db/migrate/20241005190710_create_shrimpo_voting_cateogry_score.rb b/db/migrate/20241005190710_create_shrimpo_voting_cateogry_score.rb new file mode 100644 index 00000000..03581ade --- /dev/null +++ b/db/migrate/20241005190710_create_shrimpo_voting_cateogry_score.rb @@ -0,0 +1,13 @@ +class CreateShrimpoVotingCateogryScore < ActiveRecord::Migration[7.0] + def change + create_table :shrimpo_voting_cateogry_scores do |t| + t.references :shrimpo_entry, null: false, index: { name: 'shrimpo_entry_score' } + t.references :shrimpo_voting_category, null: false, index: { name: 'voting_cat_score' } + + t.integer :score + t.integer :ranking + + t.timestamps + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 33923855..3a32bea1 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2024_09_15_231634) do +ActiveRecord::Schema[7.0].define(version: 2024_10_05_190710) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -476,6 +476,17 @@ t.index ["shrimpo_id"], name: "index_shrimpo_voting_categories_on_shrimpo_id" end + create_table "shrimpo_voting_cateogry_scores", force: :cascade do |t| + t.bigint "shrimpo_entry_id", null: false + t.bigint "shrimpo_voting_category_id", null: false + t.integer "score" + t.integer "ranking" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["shrimpo_entry_id"], name: "shrimpo_entry_score" + t.index ["shrimpo_voting_category_id"], name: "voting_cat_score" + end + create_table "shrimpos", force: :cascade do |t| t.bigint "user_id", null: false t.string "title", null: false diff --git a/spec/models/shrimpo_spec.rb b/spec/models/shrimpo_spec.rb index e28e0f22..304d5a42 100644 --- a/spec/models/shrimpo_spec.rb +++ b/spec/models/shrimpo_spec.rb @@ -93,6 +93,9 @@ expect(TrophyAward.where(user: entry1.user, shrimpo_entry: entry1, trophy: consolation_trophy).count).to be >= 1 end + xit 'tallys results for mega shrimpo' do + end + it 'cant vote on own entry' do dj1 = User.create role: 'dj', username: 'dakota', email: "dakota@gmail.com", password: "2boobies", time_zone: "UTC", fruit_ticket_balance: 1000, level: 3 dj2 = User.create role: 'dj', username: 'seacuke', email: "seacuke@gmail.com", password: "2boobies", time_zone: "UTC"