Merge remote-tracking branch 'origin/develop' into develop
Conflicts: monitor/spec/production_spec.rb
This commit is contained in:
commit
44c895b704
|
|
@ -155,3 +155,4 @@ session_ratings.sql
|
|||
scheduled_sessions.sql
|
||||
add_last_jam_user_fields.sql
|
||||
remove_lat_lng_user_fields.sql
|
||||
update_get_work_for_larger_radius.sql
|
||||
|
|
|
|||
|
|
@ -0,0 +1,16 @@
|
|||
DROP FUNCTION get_work (mylocidispid BIGINT);
|
||||
CREATE FUNCTION get_work (mylocidispid BIGINT, myaddr BIGINT) RETURNS TABLE (client_id VARCHAR(64)) ROWS 5 VOLATILE AS $$
|
||||
BEGIN
|
||||
CREATE TEMPORARY TABLE foo (locidispid BIGINT, locid INT);
|
||||
INSERT INTO foo SELECT DISTINCT locidispid, locidispid/1000000 FROM connections WHERE client_type = 'client';
|
||||
DELETE FROM foo WHERE locidispid IN (SELECT DISTINCT blocidispid FROM current_scores WHERE alocidispid = mylocidispid AND (current_timestamp - score_dt) < INTERVAL '24 hours');
|
||||
DELETE FROM foo WHERE locid NOT IN (SELECT locid FROM geoiplocations WHERE geog && st_buffer((SELECT geog FROM geoiplocations WHERE locid = mylocidispid/1000000), 4023360));
|
||||
CREATE TEMPORARY TABLE bar (client_id VARCHAR(64), locidispid BIGINT, r DOUBLE PRECISION);
|
||||
INSERT INTO bar SELECT l.client_id, l.locidispid, random() FROM connections l, foo f WHERE l.locidispid = f.locidispid AND l.client_type = 'client' AND addr != myaddr;
|
||||
DROP TABLE foo;
|
||||
DELETE FROM bar b WHERE r != (SELECT MAX(r) FROM bar b0 WHERE b0.locidispid = b.locidispid);
|
||||
RETURN QUERY SELECT b.client_id FROM bar b ORDER BY r LIMIT 5;
|
||||
DROP TABLE bar;
|
||||
RETURN;
|
||||
END;
|
||||
$$ LANGUAGE plpgsql;
|
||||
|
|
@ -4,4 +4,4 @@ dropdb jam_db_build
|
|||
dropdb jam_ruby_test
|
||||
dropdb jam_web_test
|
||||
dropdb jam_websocket_test
|
||||
createdb -Upostgres jam
|
||||
sudo su postgres -c "createdb jam"
|
||||
|
|
|
|||
|
|
@ -3,15 +3,15 @@ module JamRuby
|
|||
|
||||
self.table_name = "connections"
|
||||
|
||||
def self.get_work(mylocidispid)
|
||||
list = self.get_work_list(mylocidispid)
|
||||
def self.get_work(mylocidispid, myaddr)
|
||||
list = self.get_work_list(mylocidispid, myaddr)
|
||||
return nil if list.nil?
|
||||
return nil if list.length == 0
|
||||
return list[0]
|
||||
end
|
||||
|
||||
def self.get_work_list(mylocidispid)
|
||||
r = GetWork.select(:client_id).find_by_sql("select get_work(#{mylocidispid}) as client_id")
|
||||
def self.get_work_list(mylocidispid, myaddr)
|
||||
r = GetWork.select(:client_id).find_by_sql("select get_work(#{mylocidispid}, #{myaddr}) as client_id")
|
||||
#puts("r = #{r}")
|
||||
a = r.map {|i| i.client_id}
|
||||
#puts("a = #{a}")
|
||||
|
|
|
|||
|
|
@ -9,8 +9,10 @@ module JamRuby
|
|||
|
||||
default_scope order('score_dt desc')
|
||||
|
||||
def self.createx(alocidispid, anodeid, aaddr, blocidispid, bnodeid, baddr, score, score_dt)
|
||||
def self.createx(alocidispid, anodeid, aaddr, blocidispid, bnodeid, baddr, score, score_dt=nil)
|
||||
score_dt = Time.new.utc if score_dt.nil?
|
||||
score = score.ceil
|
||||
raise "score must be positive" if score <= 0
|
||||
Score.create(alocidispid: alocidispid, anodeid: anodeid, aaddr: aaddr, blocidispid: blocidispid, bnodeid: bnodeid, baddr: baddr, score: score, scorer: 0, score_dt: score_dt)
|
||||
Score.create(alocidispid: blocidispid, anodeid: bnodeid, aaddr: baddr, blocidispid: alocidispid, bnodeid: anodeid, baddr: aaddr, score: score, scorer: 1, score_dt: score_dt) if alocidispid != blocidispid
|
||||
end
|
||||
|
|
@ -25,5 +27,9 @@ module JamRuby
|
|||
return -1 if s.nil?
|
||||
return s.score
|
||||
end
|
||||
|
||||
def self.score_conns(c1, c2, score)
|
||||
self.createx(c1.locidispid, c1.client_id, c1.addr, c2.locidispid, c2.client_id, c2.addr, score)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -120,14 +120,32 @@ module JamRuby
|
|||
ordering.blank? ? keys[0] : keys.detect { |oo| oo.to_s == ordering }
|
||||
end
|
||||
|
||||
def self.musician_filter(params={}, current_user=nil)
|
||||
# produce a list of musicians (users where musician is true)
|
||||
# params:
|
||||
# instrument - instrument to search for or blank
|
||||
# handled by relation_pagination:
|
||||
# page - page number to fetch (origin 1)
|
||||
# per_page - number of entries per page
|
||||
# handled by order_param:
|
||||
# orderby - ??? (followed, plays, playing)
|
||||
# handled by where_latlng:
|
||||
# distance - defunct
|
||||
# city - defunct
|
||||
# remote_ip - defunct
|
||||
def self.musician_filter(params={}, user=nil, conn=nil)
|
||||
rel = User.musicians
|
||||
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
|
||||
|
||||
# todo scott - rel = MaxMindGeo.where_latlng(rel, params, current_user)
|
||||
locidispid = (conn ? conn.locidispid : (user ? user.last_jam_locidispid : 0))
|
||||
|
||||
# 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
|
||||
|
||||
# todo scott - rel = MaxMindGeo.where_latlng(rel, params, user)
|
||||
|
||||
sel_str = 'users.*'
|
||||
case ordering = self.order_param(params)
|
||||
|
|
@ -157,7 +175,7 @@ module JamRuby
|
|||
srch = Search.new
|
||||
srch.search_type = :musicians_filter
|
||||
srch.page_num, srch.page_count = page, objs.total_pages
|
||||
srch.musician_results_for_user(objs, current_user)
|
||||
srch.musician_results_for_user(objs, user)
|
||||
end
|
||||
|
||||
def self.relation_pagination(rel, params)
|
||||
|
|
|
|||
|
|
@ -7,13 +7,13 @@ describe GetWork do
|
|||
end
|
||||
|
||||
it "get_work_1" do
|
||||
x = GetWork.get_work(1)
|
||||
x = GetWork.get_work(1, 0)
|
||||
#puts x.inspect
|
||||
x.should be_nil
|
||||
end
|
||||
|
||||
it "get_work_list_1" do
|
||||
x = GetWork.get_work_list(1)
|
||||
x = GetWork.get_work_list(1, 0)
|
||||
#puts x.inspect
|
||||
x.should eql([])
|
||||
end
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ require 'spec_helper'
|
|||
describe 'Musician search' do
|
||||
|
||||
before(:each) do
|
||||
@geocode1 = FactoryGirl.create(:geocoder)
|
||||
@geocode2 = FactoryGirl.create(:geocoder)
|
||||
# @geocode1 = FactoryGirl.create(:geocoder)
|
||||
# @geocode2 = FactoryGirl.create(:geocoder)
|
||||
@users = []
|
||||
@users << @user1 = FactoryGirl.create(:user)
|
||||
@users << @user2 = FactoryGirl.create(:user)
|
||||
|
|
|
|||
|
|
@ -92,4 +92,31 @@ describe Score do
|
|||
Score.findx(3456, 3456).should == -1
|
||||
end
|
||||
|
||||
it "test shortcut for making scores from connections" do
|
||||
user1 = FactoryGirl.create(:user)
|
||||
conn1 = FactoryGirl.create(:connection, user: user1, addr: 0x01020304, locidispid: 5)
|
||||
user2 = FactoryGirl.create(:user)
|
||||
conn2 = FactoryGirl.create(:connection, user: user2, addr: 0x11121314, locidispid: 6)
|
||||
user3 = FactoryGirl.create(:user)
|
||||
conn3 = FactoryGirl.create(:connection, user: user3, addr: 0x21222324, locidispid: 7)
|
||||
|
||||
Score.findx(5, 6).should == -1
|
||||
Score.findx(6, 5).should == -1
|
||||
Score.findx(5, 7).should == -1
|
||||
Score.findx(7, 5).should == -1
|
||||
Score.findx(6, 7).should == -1
|
||||
Score.findx(7, 6).should == -1
|
||||
|
||||
Score.score_conns(conn1, conn2, 12)
|
||||
Score.score_conns(conn1, conn3, 13)
|
||||
Score.score_conns(conn2, conn3, 23)
|
||||
|
||||
Score.findx(5, 6).should == 12
|
||||
Score.findx(6, 5).should == 12
|
||||
Score.findx(5, 7).should == 13
|
||||
Score.findx(7, 5).should == 13
|
||||
Score.findx(6, 7).should == 23
|
||||
Score.findx(7, 6).should == 23
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,13 +7,12 @@ class ApiScoringController < ApiController
|
|||
clientid = params[:clientid]
|
||||
if clientid.nil? then render :json => {message: 'clientid not specified'}, :status => 400; return end
|
||||
|
||||
conn = Connection.where(client_id: clientid).first
|
||||
conn = Connection.where(client_id: clientid, user_id: current_user.id).first
|
||||
if conn.nil? then render :json => {message: 'session not found'}, :status => 404; return end
|
||||
if !current_user.id.eql?(conn.user.id) then render :json => {message: 'session not owned by user'}, :status => 403; return end
|
||||
# if !current_user.id.eql?(conn.user.id) then render :json => {message: 'session not owned by user'}, :status => 403; return end
|
||||
|
||||
# todo this method is a stub
|
||||
#puts "ApiScoringController#work(#{clientid}) => locidispid #{c.locidispid}"
|
||||
result_client_id = JamRuby::GetWork.get_work(conn.locidispid)
|
||||
result_client_id = JamRuby::GetWork.get_work(conn.locidispid, conn.addr)
|
||||
#result_client_id = clientid+'peer'
|
||||
|
||||
render :json => {:clientid => result_client_id}, :status => 200
|
||||
|
|
@ -23,12 +22,11 @@ class ApiScoringController < ApiController
|
|||
clientid = params[:clientid]
|
||||
if clientid.nil? then render :json => {message: 'clientid not specified'}, :status => 400; return end
|
||||
|
||||
conn = Connection.where(client_id: clientid).first
|
||||
conn = Connection.where(client_id: clientid, user_id: current_user.id).first
|
||||
if conn.nil? then render :json => {message: 'session not found'}, :status => 404; return end
|
||||
if !current_user.id.eql?(conn.user.id) then render :json => {message: 'session not owned by user'}, :status => 403; return end
|
||||
# if !current_user.id.eql?(conn.user.id) then render :json => {message: 'session not owned by user'}, :status => 403; return end
|
||||
|
||||
# todo this method is a stub
|
||||
result_client_ids = JamRuby::GetWork.get_work_list(conn.locidispid)
|
||||
result_client_ids = JamRuby::GetWork.get_work_list(conn.locidispid, conn.addr)
|
||||
#result_client_ids = [clientid+'peer1', clientid+'peer2']
|
||||
|
||||
render :json => {:clientids => result_client_ids}, :status => 200
|
||||
|
|
@ -61,10 +59,10 @@ class ApiScoringController < ApiController
|
|||
|
||||
if !score.is_a? Numeric then render :json => {message: 'score not valid numeric'}, :status => 400; return end
|
||||
|
||||
aconn = Connection.where(client_id: aclientid).first
|
||||
aconn = Connection.where(client_id: aclientid, user_id: current_user.id).first
|
||||
if aconn.nil? then render :json => {message: 'a\'s session not found'}, :status => 404; return end
|
||||
if aAddr != aconn.addr then render :json => {message: 'a\'s session addr does not match aAddr'}, :status => 403; return end
|
||||
if !current_user.id.eql?(aconn.user.id) then render :json => {message: 'a\'s session not owned by user'}, :status => 403; return end
|
||||
# if !current_user.id.eql?(aconn.user.id) then render :json => {message: 'a\'s session not found'}, :status => 403; return end
|
||||
|
||||
bconn = Connection.where(client_id: bclientid).first
|
||||
if bconn.nil? then render :json => {message: 'b\'s session not found'}, :status => 404; return end
|
||||
|
|
|
|||
|
|
@ -9,13 +9,14 @@ class ApiSearchController < ApiController
|
|||
if 1 == params[Search::PARAM_MUSICIAN].to_i || 1 == params[Search::PARAM_BAND].to_i
|
||||
query = params.clone
|
||||
query[:remote_ip] = request.remote_ip
|
||||
if 1 == params[Search::PARAM_MUSICIAN].to_i
|
||||
@search = Search.musician_filter(query, current_user)
|
||||
if 1 == query[Search::PARAM_MUSICIAN].to_i
|
||||
clientid = params[:clientid]
|
||||
conn = (clientid ? Connection.where(client_id: clientid, user_id: current_user.id).first : nil)
|
||||
@search = Search.musician_filter(query, current_user, conn)
|
||||
else
|
||||
@search = Search.band_filter(query, current_user)
|
||||
end
|
||||
respond_with @search, responder: ApiResponder, :status => 200
|
||||
|
||||
elsif 1 == params[Search::PARAM_SESSION_INVITE].to_i
|
||||
@search = Search.session_invite_search(params[:query], current_user)
|
||||
else
|
||||
|
|
|
|||
|
|
@ -9,15 +9,15 @@ describe ApiScoringController do
|
|||
|
||||
MARY_IP_ADDRESS = '75.92.54.210' # 1264334546, 4B.5C.36.D2
|
||||
MARY_ADDR = 1264334546
|
||||
MARY_LOCIDISPID = 17192008423
|
||||
MARY_LOCIDISPID = 1807000004
|
||||
|
||||
MIKE_IP_ADDRESS = '173.172.108.1' # 2913758209, AD.AC.6C.01
|
||||
MIKE_ADDR = 2913758209
|
||||
MIKE_LOCIDISPID = 17192043640
|
||||
MIKE_LOCIDISPID = 1539000002
|
||||
|
||||
JOHN_IP_ADDRESS = '255.255.1.2' # 4294902018, FF.FF.01.02
|
||||
JOHN_ADDR = 4294902018
|
||||
JOHN_LOCIDISPID = 0
|
||||
JOHN_LOCIDISPID = 98765432
|
||||
|
||||
before do
|
||||
@mary = FactoryGirl.create(:user, first_name: 'mary')
|
||||
|
|
@ -83,8 +83,9 @@ describe ApiScoringController do
|
|||
response.should be_success
|
||||
json = JSON.parse(response.body, :symbolize_names => true)
|
||||
json.length.should == 1
|
||||
json[:clientid].should_not be_nil
|
||||
[@mary_client_id, @mike_client_id].should include(json[:clientid])
|
||||
clientid = json[:clientid]
|
||||
clientid.should_not be_nil
|
||||
[@mike_client_id].should include(clientid)
|
||||
end
|
||||
|
||||
it 'try work with mike login and mike' do
|
||||
|
|
@ -93,8 +94,9 @@ describe ApiScoringController do
|
|||
response.should be_success
|
||||
json = JSON.parse(response.body, :symbolize_names => true)
|
||||
json.length.should == 1
|
||||
json[:clientid].should_not be_nil
|
||||
[@mary_client_id, @mike_client_id].should include(json[:clientid])
|
||||
clientid = json[:clientid]
|
||||
clientid.should_not be_nil
|
||||
[@mary_client_id].should include(clientid)
|
||||
end
|
||||
|
||||
it 'try work with mary login and mike' do
|
||||
|
|
@ -103,7 +105,7 @@ describe ApiScoringController do
|
|||
response.should_not be_success
|
||||
json = JSON.parse(response.body, :symbolize_names => true)
|
||||
json.length.should == 1
|
||||
json[:message].should eql('session not owned by user')
|
||||
json[:message].should eql('session not found')
|
||||
end
|
||||
|
||||
it 'try work with mike login and mary' do
|
||||
|
|
@ -112,7 +114,7 @@ describe ApiScoringController do
|
|||
response.should_not be_success
|
||||
json = JSON.parse(response.body, :symbolize_names => true)
|
||||
json.length.should == 1
|
||||
json[:message].should eql('session not owned by user')
|
||||
json[:message].should eql('session not found')
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -152,13 +154,11 @@ describe ApiScoringController do
|
|||
response.should be_success
|
||||
json = JSON.parse(response.body, :symbolize_names => true)
|
||||
json.length.should == 1
|
||||
json[:clientids].should_not be_nil
|
||||
json[:clientids].should_receive :length
|
||||
json[:clientids].length == 2
|
||||
[@mary_client_id, @mike_client_id].should include(json[:clientids][0])
|
||||
[@mary_client_id, @mike_client_id].should include(json[:clientids][1])
|
||||
json[:clientids][0].should_not eql(json[:clientids][1])
|
||||
|
||||
clientids = json[:clientids]
|
||||
clientids.should_not be_nil
|
||||
clientids.should respond_to :length
|
||||
clientids.length.should == 1
|
||||
[@mike_client_id].should include(clientids[0])
|
||||
end
|
||||
|
||||
it 'try worklist with mike login and mike' do
|
||||
|
|
@ -167,12 +167,11 @@ describe ApiScoringController do
|
|||
response.should be_success
|
||||
json = JSON.parse(response.body, :symbolize_names => true)
|
||||
json.length.should == 1
|
||||
json[:clientids].should_not be_nil
|
||||
json[:clientids].should_receive :length
|
||||
json[:clientids].length == 2
|
||||
[@mary_client_id, @mike_client_id].should include(json[:clientids][0])
|
||||
[@mary_client_id, @mike_client_id].should include(json[:clientids][1])
|
||||
json[:clientids][0].should_not eql(json[:clientids][1])
|
||||
clientids = json[:clientids]
|
||||
clientids.should_not be_nil
|
||||
clientids.should respond_to :length
|
||||
clientids.length.should == 1
|
||||
[@mary_client_id].should include(clientids[0])
|
||||
end
|
||||
|
||||
it 'try worklist with mary login and mike' do
|
||||
|
|
@ -181,7 +180,7 @@ describe ApiScoringController do
|
|||
response.should_not be_success
|
||||
json = JSON.parse(response.body, :symbolize_names => true)
|
||||
json.length.should == 1
|
||||
json[:message].should eql('session not owned by user')
|
||||
json[:message].should eql('session not found')
|
||||
end
|
||||
|
||||
end
|
||||
|
|
@ -302,7 +301,7 @@ describe ApiScoringController do
|
|||
response.should_not be_success
|
||||
json = JSON.parse(response.body, :symbolize_names => true)
|
||||
json.length.should == 1
|
||||
json[:message].should eql('a\'s session not owned by user')
|
||||
json[:message].should eql('a\'s session not found')
|
||||
end
|
||||
|
||||
it 'record with mary login, mary, mary_addr, mary, mary_addr, score' do
|
||||
|
|
@ -359,12 +358,15 @@ describe ApiScoringController do
|
|||
json[:message].should eql('b\'s location or isp not found')
|
||||
end
|
||||
|
||||
it 'record with mary login, mary, mary_addr, mike, mike_addr, score' do
|
||||
it 'record with mary login, mary, mary_addr, mike, mike_addr, score (integer)' do
|
||||
controller.current_user = @mary
|
||||
post :record, {:format => 'json', :aclientid => @mary_client_id, :aAddr => MARY_IP_ADDRESS, :bclientid => @mike_client_id, :bAddr => MIKE_IP_ADDRESS, :score => 20}
|
||||
response.should be_success
|
||||
json = JSON.parse(response.body, :symbolize_names => true)
|
||||
json.length.should == 0
|
||||
score = Score.findx(MARY_LOCIDISPID, MIKE_LOCIDISPID)
|
||||
score.should_not be_nil
|
||||
score.should eq(20)
|
||||
end
|
||||
|
||||
it 'record with mary login, mary, mary_addr, mike, mike_addr, score (floating pt)' do
|
||||
|
|
@ -373,6 +375,9 @@ describe ApiScoringController do
|
|||
response.should be_success
|
||||
json = JSON.parse(response.body, :symbolize_names => true)
|
||||
json.length.should == 0
|
||||
score = Score.findx(MARY_LOCIDISPID, MIKE_LOCIDISPID)
|
||||
score.should_not be_nil
|
||||
score.should eq(22)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue