added attribute accessors for music_session_id and latency; added access to ams_users_tmp via ams_users method in ActiveMusicSession; added test of same in the spec
This commit is contained in:
parent
ab2ad1b93c
commit
07c1a4c85d
|
|
@ -314,7 +314,7 @@ module JamRuby
|
|||
return query
|
||||
end
|
||||
|
||||
# initialize the two temporary tables we use to drive ams_index
|
||||
# initialize the two temporary tables we use to drive ams_index and ams_users
|
||||
def self.ams_init(current_user, options = {})
|
||||
client_id = options[:client_id]
|
||||
|
||||
|
|
@ -326,8 +326,9 @@ module JamRuby
|
|||
end
|
||||
|
||||
# Generate a list of music sessions (that are active) filtered by genre, language, keyword, and sorted
|
||||
# (and tagged) by rsvp'd (1st), invited (2nd), and musician can join (3rd). within a group
|
||||
# tagged the same, sorted by score. date seems irrelevant as these are active sessions.
|
||||
# (and tagged) by rsvp'd (1st), invited (2nd), and musician can join (3rd). within a group tagged the
|
||||
# same, sorted by score. date seems irrelevant as these are active sessions. ams_init must be called
|
||||
# first.
|
||||
def self.ams_index(current_user, options = {})
|
||||
client_id = options[:client_id]
|
||||
genre = options[:genre]
|
||||
|
|
@ -392,7 +393,7 @@ module JamRuby
|
|||
|
||||
unless keyword.nil? or keyword.length < 3 or keyword.length > 100
|
||||
w = keyword.split(/\W+/)
|
||||
if w.length > 0 and w.length >= 3
|
||||
if w.length > 0 and w[0].length >= 3
|
||||
query = query.where("music_sessions.description like '%#{w[0]}%'")
|
||||
end
|
||||
end
|
||||
|
|
@ -404,6 +405,21 @@ module JamRuby
|
|||
return query
|
||||
end
|
||||
|
||||
# returns the set of users in a music_sessions and the music_session they are in and their latency.
|
||||
# ams_init must be called first.
|
||||
def self.ams_users()
|
||||
return User.select('users.*, ams_users_tmp.music_session_id, ams_users_tmp.latency')
|
||||
.joins(
|
||||
%Q{
|
||||
INNER JOIN
|
||||
ams_users_tmp
|
||||
ON
|
||||
ams_users_tmp.user_id = users.id
|
||||
}
|
||||
)
|
||||
.order('ams_users_tmp.music_session_id, ams_users_tmp.user_id')
|
||||
end
|
||||
|
||||
def self.participant_create user, music_session_id, client_id, as_musician, tracks
|
||||
music_session = MusicSession.find(music_session_id)
|
||||
|
||||
|
|
|
|||
|
|
@ -292,11 +292,22 @@ module JamRuby
|
|||
end
|
||||
|
||||
def joined_score
|
||||
nil unless has_attribute?(:score)
|
||||
return nil unless has_attribute?(:score)
|
||||
a = read_attribute(:score)
|
||||
a.nil? ? nil : a.to_i
|
||||
end
|
||||
|
||||
def music_session_id
|
||||
return nil unless has_attribute?(:music_session_id)
|
||||
read_attribute(:music_session_id)
|
||||
end
|
||||
|
||||
def latency
|
||||
return nil unless has_attribute?(:latency)
|
||||
a = read_attribute(:latency)
|
||||
a.nil? ? nil : a.to_i
|
||||
end
|
||||
|
||||
# mods comes back as text; so give ourselves a parsed version
|
||||
def mods_json
|
||||
@mods_json ||= mods ? JSON.parse(mods, symbolize_names: true) : {}
|
||||
|
|
|
|||
|
|
@ -364,6 +364,23 @@ describe ActiveMusicSession do
|
|||
music_sessions[1].tag.should_not be_nil
|
||||
music_sessions[1].latency.should_not be_nil
|
||||
|
||||
users = ActiveMusicSession.ams_users()
|
||||
users.should_not be_nil
|
||||
users.length.should == 2
|
||||
if users[0].music_session_id == earlier_session.id
|
||||
users[0].user_id.should == creator.id
|
||||
users[0].latency.should == 15 # (5 + 20 + 5) / 2
|
||||
users[1].music_session_id == later_session.id
|
||||
users[1].user_id.should == creator2.id
|
||||
users[1].latency.should == 22 # (5 + 30 + 10) / 2
|
||||
else
|
||||
users[0].music_session_id.should == later_session.id
|
||||
users[0].id.should == creator2.id
|
||||
users[0].latency.should == 22 # (5 + 30 + 10) / 2
|
||||
users[1].music_session_id == earlier_session.id
|
||||
users[1].id.should == creator.id
|
||||
users[1].latency.should == 15 # (5 + 20 + 5) / 2
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue