fixed duplicities
This commit is contained in:
parent
45e30973a0
commit
7c4849d62e
@ -28,8 +28,8 @@ DECLARE
|
|||||||
s bigint;
|
s bigint;
|
||||||
BEGIN
|
BEGIN
|
||||||
|
|
||||||
-- init salesmen weights to zero
|
-- init salesmen weights to 1
|
||||||
we := array_fill(0, ARRAY[array_length(salesmen_id,1)]);
|
we := array_fill(1, ARRAY[array_length(salesmen_id,1)]);
|
||||||
|
|
||||||
-- init results
|
-- init results
|
||||||
results := array_fill(''::text, ARRAY[array_length(salesmen_id,1)]);
|
results := array_fill(''::text, ARRAY[array_length(salesmen_id,1)]);
|
||||||
@ -141,10 +141,12 @@ BEGIN
|
|||||||
results[s] := cids[i]::text;
|
results[s] := cids[i]::text;
|
||||||
we[s] := we[s] + cws[i];
|
we[s] := we[s] + cws[i];
|
||||||
flag := true;
|
flag := true;
|
||||||
|
EXIT;
|
||||||
ELSEIF (we[s] + cws[i]) <= lim::numeric THEN
|
ELSEIF (we[s] + cws[i]) <= lim::numeric THEN
|
||||||
results[s] := results[s] || ',' || cids[i]::text;
|
results[s] := results[s] || ',' || cids[i]::text;
|
||||||
we[s] := we[s] + cws[i];
|
we[s] := we[s] + cws[i];
|
||||||
flag := true;
|
flag := true;
|
||||||
|
EXIT;
|
||||||
ELSE
|
ELSE
|
||||||
CONTINUE;
|
CONTINUE;
|
||||||
END IF;
|
END IF;
|
||||||
@ -190,14 +192,14 @@ BEGIN
|
|||||||
d.sales_id as salesman,
|
d.sales_id as salesman,
|
||||||
0.0 as dist
|
0.0 as dist
|
||||||
FROM d LEFT JOIN a
|
FROM d LEFT JOIN a
|
||||||
ON d.c_id::bigint = a.id;
|
ON d.c_id::bigint = a.id::bigint;
|
||||||
END;
|
END;
|
||||||
$$ language plpgsql;
|
$$ language plpgsql;
|
||||||
|
|
||||||
|
|
||||||
-- ====================== ^^^ ====================================
|
-- ====================== ^^^ ====================================
|
||||||
-- test
|
-- test 1
|
||||||
-- ====================== ^^^ ====================================
|
-- ====================== ^^^ ====================================
|
||||||
WITH
|
WITH
|
||||||
a0 AS (
|
a0 AS (
|
||||||
with gs as (SELECT generate_series(1001,1100) as g) select array_agg(g::bigint) as id from gs
|
with gs as (SELECT generate_series(1001,1100) as g) select array_agg(g::bigint) as id from gs
|
||||||
@ -224,4 +226,36 @@ CDB_SalesForce(
|
|||||||
a0.id
|
a0.id
|
||||||
) test;
|
) test;
|
||||||
|
|
||||||
|
-- ====================== ^^^ ====================================
|
||||||
|
-- test 2
|
||||||
|
-- ====================== ^^^ ====================================
|
||||||
|
|
||||||
|
with
|
||||||
|
clients as(
|
||||||
|
SELECT
|
||||||
|
array_agg(cartodb_id) as id,
|
||||||
|
array_agg(the_geom) as geo,
|
||||||
|
array_agg(plugs::numeric) as w
|
||||||
|
FROM abel.charging_stations
|
||||||
|
where cartodb_id % 8 = 0 limit 250
|
||||||
|
),
|
||||||
|
salesreps as(
|
||||||
|
SELECT
|
||||||
|
array_agg(cartodb_id) as id,
|
||||||
|
array_agg(the_geom) as geo
|
||||||
|
FROM abel.base where country = 'Spain' and the_geom is not null
|
||||||
|
)
|
||||||
|
SELECT
|
||||||
|
test.*
|
||||||
|
FROM
|
||||||
|
clients,
|
||||||
|
salesreps,
|
||||||
|
CDB_SalesForce(
|
||||||
|
salesreps.geo,
|
||||||
|
salesreps.id,
|
||||||
|
clients.geo,
|
||||||
|
clients.id
|
||||||
|
) test
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user