get_work has a larger radius and excludes the current connections address
This commit is contained in:
parent
867ec7c53f
commit
4a76e0c983
|
|
@ -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}")
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ module JamRuby
|
|||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ class ApiScoringController < ApiController
|
|||
# if !current_user.id.eql?(conn.user.id) then render :json => {message: 'session not owned by user'}, :status => 403; return end
|
||||
|
||||
#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
|
||||
|
|
@ -26,7 +26,7 @@ class ApiScoringController < ApiController
|
|||
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
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -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