-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinteractions.rb
167 lines (127 loc) · 3.87 KB
/
interactions.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
require 'active_record'
`rm interactions.db`
ActiveRecord::Base.establish_connection(
:adapter => 'sqlite3',
:database => 'interactions.db'
)
ActiveRecord::Migration.create_table :people do |t|
t.string :name
t.integer :role_id
end
ActiveRecord::Migration.create_table :roles do |t|
t.string :label
end
ActiveRecord::Migration.create_table :moments do |t|
t.integer :person_id
t.integer :interaction_id
end
ActiveRecord::Migration.create_table :interactions do |t|
t.string :label
end
ActiveRecord::Migration.create_table :perspectives do |t|
t.integer :moment_id
t.integer :satisfaction
end
ActiveRecord::Migrator.up 'nothing'
# -----
class Person < ActiveRecord::Base
belongs_to :role
has_many :moments
has_many :interactions, through: :moments
scope :random, -> { all.sample }
end
class Role < ActiveRecord::Base
has_many :people
# moonshot 1
scope :labels , ->{ all.map(&:label).map(&:downcase) }
end
class Moment < ActiveRecord::Base
belongs_to :person
belongs_to :interaction
has_one :perspective
end
class Interaction < ActiveRecord::Base
has_many :moments
has_many :people, through: :moments
has_many :perspectives, through: :moments
# moonshot 1
def method_missing(*args)
role = args.first.to_s.singularize
if Role.labels.include? role
self.people.where(role: Role.find_by(label: role.capitalize))
else
super
end
end
end
class Perspective < ActiveRecord::Base
belongs_to :moment
has_one :person, through: :moment
end
# ----
roles = %w[Student Teacher Coach]
students = %w[Charles Banu Gabriel]
teachers = %w[Sherif]
roles.map!{|label| Role.create(label: label)}
students.map!{|name| Person.create(name: name, role: Role.find_by(label: 'Student'))}
teachers.map!{|name| Person.create(name: name, role: Role.find_by(label: 'Teacher'))}
p roles
p students
p teachers
# how do we model a pairing session? (2 students)
# pair = students.sample(2)
# pairing_session = Interaction.create(label: 'AM pairing session')
# pair.each {|student| student.interactions << pairing_session}
# p Moment.all
# p Interaction.first.people
# # how do we prompt people for their perspective on an interaction?
# interaction = Interaction.first
# if interaction.perspectives.empty?
# # puts "prompt user"
# # p interaction
# interaction.moments.each do |moment|
# puts "#{moment.person.name}, please enter your perspective on #{interaction.label}"
# perspective = gets.chomp.to_i
# moment.create_perspective(satisfaction: perspective)
# end
# else
# puts "all set"
# end
# p Perspective.all.map{|perspective| "#{perspective.person.name} felt it was a #{perspective.satisfaction}"}
########################################################################
# how do we model a lecture? (1 teacher, all students)
am_lecture = Interaction.create(label: 'AM Lecture')
pm_lecture = Interaction.create(label: 'PM Lecture')
# moonshot 1
# p lecture.people.where(role: Role.find_by(label: 'Student'))
# if lecture.students.empty?
# puts "no students attended this lecture"
# end
# p lecture
# puts lecture.methods.sort - ActiveRecord::Base.instance_methods
# lecture.people.create_person(name: 'Banu')
# p Moment.all
# lecture.people << students.sample
# p Moment.all
puts "-"*20
am_lecture.people << students.sample(2) << teachers
pm_lecture.people << students.sample(3) << teachers
puts "------"
p "AM Lecture Attedance"
# p am_lecture.people.where(role: Role.find_by(label: 'Student'))
puts "teachers:"
p am_lecture.teachers.map(&:name)
puts "students:"
p am_lecture.students.map(&:name)
puts "------"
p "PM Lecture Attedance"
# p pm_lecture.people.where(role: Role.find_by(label: 'Student'))
puts "teachers:"
p pm_lecture.teachers.map(&:name)
puts "students:"
p pm_lecture.students.map(&:name)
puts "------"
p "Student History"
students.each do |student|
puts "#{student.name} attended #{student.interactions.map(&:label)}"
end