Skip to content

Commit

Permalink
Made changes, can't recall what exactly.
Browse files Browse the repository at this point in the history
But they seem good.
	new file:   .gitignore
	new file:   kermit.sql
	modified:   sql/lw_blocknodes.sql
	modified:   sql/lw_endnodes.sql
	modified:   sql/lw_generateedge.sql
	modified:   sql/lw_traceall.sql
	modified:   sql/lw_tracesource.sql
	deleted:    sql/lw_tracesource_.sql
  • Loading branch information
rhysallister committed Aug 12, 2018
1 parent c6f368d commit 488f7f0
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 84 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.swp
59 changes: 59 additions & 0 deletions kermit.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
BEGIN;
select lw_initialise('kermit',3448);

select lw_addedgeparticipant('kermit','{
"schemaname":"data",
"tablename": "ugprimaryline",
"primarykey":"objectid",
"geomcolumn": "wkb_geometry",
"labelcolumn": "dataid",
"phasecolumn": "phasingcode",
"phasemap":{"ABC":"7","AB":"6","AC":"5","BC":"3","A":"4","B":"2","C":"1"}
}') ;

select lw_addedgeparticipant('kermit','{
"schemaname":"data",
"tablename": "ohprimaryline",
"primarykey":"objectid",
"geomcolumn": "wkb_geometry",
"labelcolumn": "dataid",
"phasecolumn": "phasingcode",
"phasemap":{"ABC":"7","AB":"6","AC":"5","BC":"3","A":"4","B":"2","C":"1"}
}') ;

select lw_addnodeparticipant('kermit', $${
"schemaname":"data",
"tablename": "switchdevicebank",
"primarykey":"facilityid",
"geomcolumn": "wkb_geometry",
"sourcequery": "\"devicetype\" = 'FDR'",
"blockquery": "0 =ANY (array[\"enabled\",\"normalposa\",\"normalposb\",\"normalposc\"])",
"phasecolumn": "phasingcode",
"phasemap":{"ABC":"7","AB":"6","AC":"5","BC":"3","A":"4","B":"2","C":"1"}
}$$);

select lw_addnodeparticipant('kermit', $${
"schemaname":"data",
"tablename": "overcurrentdevicebank",
"primarykey":"facilityid",
"geomcolumn": "wkb_geometry",
"sourcequery": "\"devicetype\" = 'FDR'",
"blockquery": "0 =ANY (array[\"enabled\",\"normalposa\",\"normalposb\",\"normalposc\"])",
"phasecolumn": "phasingcode",
"phasemap":{"ABC":"7","AB":"6","AC":"5","BC":"3","A":"4","B":"2","C":"1"}
}$$);

select lw_addnodeparticipant('kermit', $${
"schemaname":"data",
"tablename": "transformerbank",
"primarykey":"facilityid",
"geomcolumn": "wkb_geometry",
"sourcequery": "1 = 2",
"blockquery": "\"enabled\" = 0",
"phasecolumn": "phasingcode",
"phasemap":{"ABC":"7","AB":"6","AC":"5","BC":"3","A":"4","B":"2","C":"1"}
}$$);

select lw_generate('kermit');

commit;
4 changes: 2 additions & 2 deletions sql/lw_blocknodes.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Gets the SRID of a livewire enabled schema */
/* Returns an array of all nodes that block */

CREATE OR REPLACE FUNCTION lw_blocknodes(
in lw_schema text,
Expand Down Expand Up @@ -46,4 +46,4 @@ END;





4 changes: 2 additions & 2 deletions sql/lw_endnodes.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Gets the SRID of a livewire enabled schema */
/* Returns an array of lw_ids that correspond to endnodes */

CREATE OR REPLACE FUNCTION lw_endnodes(
in lw_schema text,
Expand Down Expand Up @@ -68,4 +68,4 @@ END;





4 changes: 2 additions & 2 deletions sql/lw_generateedge.sql
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ BEGIN
);
GET DIAGNOSTICS diaginfo = ROW_COUNT;
IF diaginfo > 0 THEN
RAISE 'Geometry column has duplicate points';
RAISE 'Geometry column has duplicate points; Table %', tablename ;
END IF;

qrytxt := format($qrytxt$
Expand Down Expand Up @@ -124,4 +124,4 @@ EXECUTE format(
);

END;
$lw_addedgeparticipant$;
$lw_addedgeparticipant$;
7 changes: 4 additions & 3 deletions sql/lw_traceall.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ AS $lw_traceall$
declare

looprec record;
qrytxt text;
timer timestamptz;
starttime timestamptz;
zerocount bigint;
Expand All @@ -25,8 +26,8 @@ AS $lw_traceall$
select count(*) from pgr_dijkstra(
$$select lw_id id, source, target, st_length(g) * multiplier as cost
from %1$I.lines $$,
(select lw_sourcenodes('%1$s'),
(select lw_sourcenodes('%1$s'),
(select lw_sourcenodes('%1$s')),
(select lw_sourcenodes('%1$s')),
false
)
$_$;
Expand All @@ -41,7 +42,7 @@ AS $lw_traceall$
for looprec in EXECUTE(format($$select lw_id from %I.nodes where status = 'SOURCE'$$, lw_schema)) LOOP
RAISE NOTICE 'SOURCE: %', looprec.lw_id;
timer := clock_timestamp();
perform lw_tracesource(lw_schema,looprec.lw_id::int);
perform lw_tracesource(lw_schema,looprec.lw_id::int, 50000, False);
RAISE NOTICE '% | Elapsed time is %', clock_timestamp() - timer, clock_timestamp() - starttime;
END LOOP;
end;
Expand Down
12 changes: 12 additions & 0 deletions sql/lw_tracesource.sql
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ end if;
)
$_$;

qrytxt:= $_$
select array_agg(lw_id) from (
select lw_id from %1$I.nodes
where status = 'BLOCK'
order by g <-> (
select st_collect(g)
from %1$I.lines where lw_id in (
select unnest(edges) from %1$I.livewire where nodes[1] = %2$s
))
limit 10) as foo$_$;


execute format(qrytxt,lw_schema,source) into closeblocks;

foreach closeblock in array closeblocks loop
Expand Down
75 changes: 0 additions & 75 deletions sql/lw_tracesource_.sql

This file was deleted.

0 comments on commit 488f7f0

Please sign in to comment.