Class: SpreeCmCommissioner::VotingLeaderboards::CombinedResult
- Inherits:
-
Object
- Object
- SpreeCmCommissioner::VotingLeaderboards::CombinedResult
- Includes:
- Spree::ServiceModule::Base
- Defined in:
- app/services/spree_cm_commissioner/voting_leaderboards/combined_result.rb
Overview
Combines vote counts from a parent voting session and all its finalized pre-vote children.
Pre-vote sessions are always finalized before the parent session starts, so their data is always read from DB snapshots (voting_contestant.vote_count / unique_voter_count). The parent (live) session reads from Redis when still running, DB when finalized.
Returns an array of rows keyed by show_contestant_id, each containing:
- contestant_id VotingContestant.id from the live session
- show_contestant_id ShowContestant.id
- vote_count combined total across all sessions
- unique_voters combined total across all sessions (per-session sum, not deduplicated)
- session_data per-session breakdown array; session_data[0] is always the live session
- confirmed_rank, eliminated, name, contestant_number
Instance Method Summary collapse
Instance Method Details
#call(voting_session:) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/services/spree_cm_commissioner/voting_leaderboards/combined_result.rb', line 21 def call(voting_session:) pre_vote_sessions = SpreeCmCommissioner::VotingSession .where(parent_id: voting_session.id) .order(:position) unfinalized = pre_vote_sessions.reject { |session| session_finalized?(session) } if unfinalized.any? names = unfinalized.map(&:name).join(', ') return failure(nil, I18n.t('spree_cm_commissioner.voting_leaderboards.combined_result.pre_vote_not_finalized', names: names)) end pre_vote_data = load_pre_vote_data(pre_vote_sessions) live_data = load_live_data(voting_session) success(build_rows(voting_session, live_data, pre_vote_data, pre_vote_sessions)) end |