mirror of
https://github.com/edcommonwealth/sqm-dashboards.git
synced 2026-03-13 09:20:38 -07:00
testing scheduling
This commit is contained in:
parent
a0646ba70f
commit
0cdf38fcc0
10 changed files with 163 additions and 1 deletions
8
app/models/attempt.rb
Normal file
8
app/models/attempt.rb
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
class Attempt < ApplicationRecord
|
||||
|
||||
belongs_to :schedule
|
||||
belongs_to :recipient
|
||||
belongs_to :recipient_schedule
|
||||
belongs_to :question
|
||||
|
||||
end
|
||||
|
|
@ -4,6 +4,8 @@ class Recipient < ApplicationRecord
|
|||
belongs_to :school
|
||||
validates_associated :school
|
||||
|
||||
has_many :attempts
|
||||
|
||||
validates :name, presence: true
|
||||
|
||||
def self.import(school, file)
|
||||
|
|
|
|||
29
app/models/recipient_schedule.rb
Normal file
29
app/models/recipient_schedule.rb
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
class RecipientSchedule < ApplicationRecord
|
||||
|
||||
belongs_to :recipient
|
||||
belongs_to :schedule
|
||||
has_many :attempts
|
||||
|
||||
def next_question
|
||||
upcoming = upcoming_question_ids.split(/,/)
|
||||
Question.where(id: upcoming.first).first
|
||||
end
|
||||
|
||||
def make_attempt(question: next_question)
|
||||
sent_at = Time.new
|
||||
recipient.attempts.create(
|
||||
schedule: schedule,
|
||||
recipient_schedule: self,
|
||||
question: question,
|
||||
sent_at: sent_at
|
||||
)
|
||||
|
||||
upcoming = upcoming_question_ids.split(/,/)[1..-1].join(',')
|
||||
attempted = (attempted_question_ids.split(/,/) + [question.id]).join(',')
|
||||
update_attributes(
|
||||
upcoming_question_ids: upcoming,
|
||||
attempted_question_ids: attempted,
|
||||
last_attempt_at: sent_at
|
||||
)
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue