finish up mods for geocoding based on scores
This commit is contained in:
parent
3bdf12c981
commit
6f57265a0d
|
|
@ -133,21 +133,31 @@ module JamRuby
|
|||
# city - defunct
|
||||
# remote_ip - defunct
|
||||
def self.musician_filter(params={}, user=nil, conn=nil)
|
||||
rel = User.musicians
|
||||
rel = User.musicians_geocoded
|
||||
sel_str = 'users.*'
|
||||
|
||||
unless (instrument = params[:instrument]).blank?
|
||||
rel = rel.joins("RIGHT JOIN musicians_instruments AS minst ON minst.user_id = users.id")
|
||||
.where(['minst.instrument_id = ? AND users.id IS NOT NULL', instrument])
|
||||
end
|
||||
|
||||
locidispid = (conn ? conn.locidispid : (user ? user.last_jam_locidispid : 0))
|
||||
# to find appropriate musicians we need to join users with scores to get to those with no scores or bad scores
|
||||
# weeded out
|
||||
|
||||
# to find appropriate musicians we need to join users with connections to get to their locidispid,
|
||||
# then join scores with alocidispid found above with the musicians' locidispid to weed out users
|
||||
# with no scores or bad scores
|
||||
score_limit = 60
|
||||
# todo scott filter out scores using selections from params
|
||||
|
||||
# todo scott - rel = MaxMindGeo.where_latlng(rel, params, user)
|
||||
locidispid = (conn and conn.client_type == 'client' ? conn.locidispid : (user and user.musician ? user.last_jam_locidispid : nil))
|
||||
|
||||
unless locidispid.nil?
|
||||
rel = rel.joins('inner join scores on users.last_jam_locidispid = scores.alocidispid')
|
||||
.where(['scores.blocidispid = ?', locidispid])
|
||||
.where(['scores.score <= ?', score_limit])
|
||||
.order('scores.score') # best scores first
|
||||
|
||||
sel_str << ', scores.score'
|
||||
end
|
||||
|
||||
sel_str = 'users.*'
|
||||
case ordering = self.order_param(params)
|
||||
when :plays # FIXME: double counting?
|
||||
sel_str = "COUNT(records)+COUNT(sessions) AS play_count, #{sel_str}"
|
||||
|
|
|
|||
|
|
@ -42,19 +42,19 @@ describe 'Musician search' do
|
|||
context 'default filter settings' do
|
||||
|
||||
it "finds all musicians" do
|
||||
# expects all the musicians
|
||||
# expects all the musicians (geocoded)
|
||||
results = Search.musician_filter
|
||||
results.search_type.should == :musicians_filter
|
||||
results.results.count.should == @musicians.length
|
||||
results.results.should eq @musicians.reverse
|
||||
results.results.count.should == @geomusicians.length
|
||||
results.results.should eq @geomusicians.reverse
|
||||
end
|
||||
|
||||
it "finds all musicians page 1" do
|
||||
# expects all the musicians
|
||||
results = Search.musician_filter({page: 1})
|
||||
results.search_type.should == :musicians_filter
|
||||
results.results.count.should == @musicians.length
|
||||
results.results.should eq @musicians.reverse
|
||||
results.results.count.should == @geomusicians.length
|
||||
results.results.should eq @geomusicians.reverse
|
||||
end
|
||||
|
||||
it "finds all musicians page 2" do
|
||||
|
|
@ -69,15 +69,15 @@ describe 'Musician search' do
|
|||
results = Search.musician_filter({per_page: 3})
|
||||
results.search_type.should == :musicians_filter
|
||||
results.results.count.should == 3
|
||||
results.results.should eq @musicians.reverse.slice(0, 3)
|
||||
results.results.should eq @geomusicians.reverse.slice(0, 3)
|
||||
end
|
||||
|
||||
it "finds all musicians page 2 per_page 3" do
|
||||
# expects two of the musicians
|
||||
results = Search.musician_filter({page: 2, per_page: 3})
|
||||
results.search_type.should == :musicians_filter
|
||||
results.results.count.should == 3
|
||||
results.results.should eq @musicians.reverse.slice(3, 3)
|
||||
results.results.count.should == 2
|
||||
results.results.should eq @geomusicians.reverse.slice(3, 3)
|
||||
end
|
||||
|
||||
it "finds all musicians page 3 per_page 3" do
|
||||
|
|
@ -87,15 +87,6 @@ describe 'Musician search' do
|
|||
results.results.count.should == 0
|
||||
end
|
||||
|
||||
it "finds musicians with proper ordering" do
|
||||
# the ordering should be create_at desc since no followers exist
|
||||
expect(Follow.count).to eq(0)
|
||||
results = Search.musician_filter({ :per_page => User.musicians.count })
|
||||
results.results.each_with_index do |uu, idx|
|
||||
expect(uu.id).to eq(@musicians.reverse[idx].id)
|
||||
end
|
||||
end
|
||||
|
||||
it "sorts musicians by followers" do
|
||||
# establish sorting order
|
||||
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ describe "Notification Highlighter", :js => true, :type => :feature, :capybara_f
|
|||
subject { page }
|
||||
|
||||
|
||||
let(:user) { FactoryGirl.create(:user) }
|
||||
let(:user2) { FactoryGirl.create(:user) }
|
||||
let(:user) { FactoryGirl.create(:user, last_jam_locidispid: 1) }
|
||||
let(:user2) { FactoryGirl.create(:user, last_jam_locidispid: 2) }
|
||||
|
||||
|
||||
shared_examples_for :notification_badge do |options|
|
||||
|
|
@ -143,6 +143,9 @@ describe "Notification Highlighter", :js => true, :type => :feature, :capybara_f
|
|||
# we should see the count go to 1, but once the notification is accepted, which causes it to delete,
|
||||
# we should see the count go back down to 0.
|
||||
|
||||
JamRuby::Score.delete_all
|
||||
JamRuby::Score.createx(1, 'a', 1, 2, 'b', 2, 10)
|
||||
|
||||
in_client(user) do
|
||||
sign_in_poltergeist(user)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ describe "Text Message", :js => true, :type => :feature, :capybara_feature => tr
|
|||
end
|
||||
|
||||
before(:each) do
|
||||
@user1 = FactoryGirl.create(:user)
|
||||
@user2 = FactoryGirl.create(:user, first_name: 'bone_crusher')
|
||||
@user1 = FactoryGirl.create(:user, last_jam_locidispid: 1)
|
||||
@user2 = FactoryGirl.create(:user, last_jam_locidispid: 2, first_name: 'bone_crusher')
|
||||
sign_in_poltergeist(@user1)
|
||||
|
||||
end
|
||||
|
|
@ -25,6 +25,9 @@ describe "Text Message", :js => true, :type => :feature, :capybara_feature => tr
|
|||
end
|
||||
|
||||
it "on find musician in musician's tile" do
|
||||
JamRuby::Score.delete_all
|
||||
JamRuby::Score.createx(1, 'a', 1, 2, 'b', 2, 10)
|
||||
|
||||
musician = find_musician(@user2)
|
||||
find(".result-list-button-wrapper[data-musician-id='#{@user2.id}'] .search-m-message").trigger(:click)
|
||||
find('h1', text: 'conversation with ' + @user2.name)
|
||||
|
|
|
|||
|
|
@ -17,10 +17,13 @@ describe "Musician Search API", :type => :api do
|
|||
before(:each) do
|
||||
2.downto(1) { FactoryGirl.create(:geocoder) }
|
||||
@users = []
|
||||
@users << @user1 = FactoryGirl.create(:user)
|
||||
@users << @user2 = FactoryGirl.create(:user)
|
||||
@users << @user3 = FactoryGirl.create(:user)
|
||||
@users << @user4 = FactoryGirl.create(:user)
|
||||
@users << @user1 = FactoryGirl.create(:user, last_jam_locidispid: 1)
|
||||
@users << @user2 = FactoryGirl.create(:user, last_jam_locidispid: 1)
|
||||
@users << @user3 = FactoryGirl.create(:user, last_jam_locidispid: 1)
|
||||
@users << @user4 = FactoryGirl.create(:user, last_jam_locidispid: 1)
|
||||
|
||||
Score.delete_all
|
||||
Score.createx(1, 'a', 1, 1, 'a', 1, 10)
|
||||
|
||||
post '/sessions', "session[email]" => user.email, "session[password]" => user.password
|
||||
expect(rack_mock_session.cookie_jar["remember_token"]).to eq(user.remember_token)
|
||||
|
|
|
|||
Loading…
Reference in New Issue