Skip to content

Commit

Permalink
shrimpo_voting_category_score
Browse files Browse the repository at this point in the history
  • Loading branch information
mcfiredrill committed Oct 5, 2024
1 parent e3a6512 commit ff91af2
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 5 deletions.
12 changes: 8 additions & 4 deletions app/models/shrimpo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions app/models/shrimpo_voting_category_score.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class ShrimpoVotingCategoryScore < ApplicationRecord
belongs_to :shrimpo_entry
belongs_to :shrimpo_voting_category
end
13 changes: 13 additions & 0 deletions db/migrate/20241005190710_create_shrimpo_voting_cateogry_score.rb
Original file line number Diff line number Diff line change
@@ -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
13 changes: 12 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions spec/models/shrimpo_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: "[email protected]", password: "2boobies", time_zone: "UTC", fruit_ticket_balance: 1000, level: 3
dj2 = User.create role: 'dj', username: 'seacuke', email: "[email protected]", password: "2boobies", time_zone: "UTC"
Expand Down

0 comments on commit ff91af2

Please sign in to comment.