16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/splut/models/experiment.rb', line 16
def participate!(splutable_thing)
if self.variations.none?
raise "participate! was called on experiment #{self.name} (id #{self.id} but there are no variations)"
end
segment_participant = Splut::SegmentParticipant.find_by(
variation_id: self.variations.collect(&:id),
splutable: splutable_thing)
if !segment_participant
random = rand(self.variations.count).floor
this_variation = self.variations[random]
segment_participant = this_variation.segment_participants.create!(splutable: splutable_thing)
else
puts " #{splutable_thing} was already in variation #{this_variation}"
this_variation = segment_participant.variation
end
impression = this_variation.impressions.create!(splutable: splutable_thing,
segment_participant: segment_participant)
impression
end
|