Merge 5efe8d8862 into 333c5e39bf
This commit is contained in:
commit
5b543cf3f9
5 changed files with 38 additions and 17 deletions
|
|
@ -149,7 +149,6 @@ module Admin
|
||||||
# get targets
|
# get targets
|
||||||
@registration_targets = @conference.get_targets(Target.units[:registrations])
|
@registration_targets = @conference.get_targets(Target.units[:registrations])
|
||||||
@submission_targets = @conference.get_targets(Target.units[:submissions])
|
@submission_targets = @conference.get_targets(Target.units[:submissions])
|
||||||
@program_minutes_targets = @conference.get_targets(Target.units[:program_minutes])
|
|
||||||
|
|
||||||
# get campaigns
|
# get campaigns
|
||||||
@campaigns = @conference.get_campaigns
|
@campaigns = @conference.get_campaigns
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ class Target < ActiveRecord::Base
|
||||||
{
|
{
|
||||||
registrations: 'Registration',
|
registrations: 'Registration',
|
||||||
submissions: 'Submission',
|
submissions: 'Submission',
|
||||||
program_minutes: 'Program minute'
|
program_hours: 'Program hours'
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -33,8 +33,8 @@ class Target < ActiveRecord::Base
|
||||||
numerator = conference.events.where('created_at < ?', due_date).count
|
numerator = conference.events.where('created_at < ?', due_date).count
|
||||||
elsif unit == Target.units[:registrations]
|
elsif unit == Target.units[:registrations]
|
||||||
numerator = conference.registrations.where('created_at < ?', due_date).count
|
numerator = conference.registrations.where('created_at < ?', due_date).count
|
||||||
elsif unit == Target.units[:program_minutes]
|
elsif unit == Target.units[:program_hours]
|
||||||
numerator = conference.current_program_minutes
|
numerator = conference.current_program_hours
|
||||||
end
|
end
|
||||||
(numerator / target_count.to_f * 100).round(0).to_s
|
(numerator / target_count.to_f * 100).round(0).to_s
|
||||||
end
|
end
|
||||||
|
|
@ -50,8 +50,8 @@ class Target < ActiveRecord::Base
|
||||||
numerator = campaign.submissions_count
|
numerator = campaign.submissions_count
|
||||||
elsif unit == Target.units[:registrations]
|
elsif unit == Target.units[:registrations]
|
||||||
numerator = campaign.registrations_count
|
numerator = campaign.registrations_count
|
||||||
elsif unit == Target.units[:program_minutes]
|
elsif unit == Target.units[:program_hours]
|
||||||
numerator = conference.current_program_minutes
|
numerator = conference.current_program_hours
|
||||||
end
|
end
|
||||||
|
|
||||||
progress = (numerator / target_count.to_f * 100).round(0).to_s
|
progress = (numerator / target_count.to_f * 100).round(0).to_s
|
||||||
|
|
|
||||||
22
db/migrate/20150317210343_convert_target_minutes_to_hours.rb
Normal file
22
db/migrate/20150317210343_convert_target_minutes_to_hours.rb
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
class ConvertTargetMinutesToHours < ActiveRecord::Migration
|
||||||
|
class TempTarget < ActiveRecord::Base
|
||||||
|
self.table_name = 'targets'
|
||||||
|
attr_accessible :target_count, :unit
|
||||||
|
end
|
||||||
|
|
||||||
|
def up
|
||||||
|
targets = TempTarget.where(unit: 'Program minute').where.not(target_count: nil)
|
||||||
|
targets.each do |target|
|
||||||
|
new_target_count = (target.target_count / 60.to_f).round
|
||||||
|
target.update_attributes(target_count: new_target_count, unit: 'Program hours')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
targets = TempTarget.where(unit: 'Program hours').where.not(target_count: nil)
|
||||||
|
targets.each do |target|
|
||||||
|
new_target_count = (target.target_count * 60.to_f).round
|
||||||
|
target.update_attributes(target_count: new_target_count, unit: 'Program minute')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -344,23 +344,23 @@ describe Conference do
|
||||||
expect(subject.get_targets(Target.units[:submissions])).to eq(result)
|
expect(subject.get_targets(Target.units[:submissions])).to eq(result)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns 0 if there is no program minute' do
|
it 'returns 0 if there is no program hour' do
|
||||||
target = build(:target, target_count: 300, unit: Target.units[:program_minutes])
|
target = build(:target, target_count: 5, unit: Target.units[:program_hours])
|
||||||
subject.targets = [target]
|
subject.targets = [target]
|
||||||
result = {
|
result = {
|
||||||
"300 Program minutes by #{target.due_date}" => '0'
|
"5 Program hours by #{target.due_date}" => '0'
|
||||||
}
|
}
|
||||||
expect(subject.get_targets(Target.units[:program_minutes])).to eq(result)
|
expect(subject.get_targets(Target.units[:program_hours])).to eq(result)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns 10 if there is 30 program minutes of 300' do
|
it 'returns 10 if there is 1 program hour of 10' do
|
||||||
target = build(:target, target_count: 300, unit: Target.units[:program_minutes])
|
target = build(:target, target_count: 10, unit: Target.units[:program_hours])
|
||||||
subject.targets = [target]
|
subject.targets = [target]
|
||||||
subject.events = [create(:event)]
|
subject.events = [create(:event)]
|
||||||
result = {
|
result = {
|
||||||
"300 Program minutes by #{target.due_date}" => '10'
|
"10 Program hours by #{target.due_date}" => '10'
|
||||||
}
|
}
|
||||||
expect(subject.get_targets(Target.units[:program_minutes])).to eq(result)
|
expect(subject.get_targets(Target.units[:program_hours])).to eq(result)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -73,15 +73,15 @@ describe Target do
|
||||||
|
|
||||||
it 'returns zero if there are no program minutes' do
|
it 'returns zero if there are no program minutes' do
|
||||||
conference = build(:conference)
|
conference = build(:conference)
|
||||||
target = build(:target, target_count: 10, unit: Target.units[:program_minutes])
|
target = build(:target, target_count: 10, unit: Target.units[:program_hours])
|
||||||
conference.targets = [target]
|
conference.targets = [target]
|
||||||
|
|
||||||
expect(target.get_progress).to eq('0')
|
expect(target.get_progress).to eq('0')
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'returns 10 if there are 30 program minutes of 300' do
|
it 'returns 10 if there are 1 program hour of 10' do
|
||||||
conference = create(:conference)
|
conference = create(:conference)
|
||||||
target = create(:target, target_count: 300, unit: Target.units[:program_minutes])
|
target = create(:target, target_count: 10, unit: Target.units[:program_hours])
|
||||||
event = create(:event)
|
event = create(:event)
|
||||||
|
|
||||||
conference.targets = [target]
|
conference.targets = [target]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue