improve observability

This commit is contained in:
Motiejus Jakštys 2021-05-19 22:57:47 +03:00 committed by Motiejus Jakštys
parent d028ad2ff0
commit e9d1587c8e
2 changed files with 25 additions and 14 deletions

View File

@ -11,9 +11,9 @@ begin
end $$ LANGUAGE plpgsql; end $$ LANGUAGE plpgsql;
-- to preview this somewhat conveniently in QGIS: -- to preview this somewhat conveniently in QGIS:
-- stage || '_' || name || ' iter:' || iter || ' nbend:'|| nbend -- stage || '_' || name || ' gen:' || coalesce(gen, 'Ø')|| ' nbend:'|| lpad(nbend, 2, '0')
drop table if exists debug_wm; drop table if exists debug_wm;
create table debug_wm(stage text, name text, iter bigint, nbend bigint, way geometry, props json); create table debug_wm(stage text, name text, gen bigint, nbend bigint, way geometry, props json);
drop table if exists figures; drop table if exists figures;
create table figures (name text, way geometry); create table figures (name text, way geometry);
@ -64,7 +64,7 @@ $$ language plpgsql;
-- COMBINED -- COMBINED
drop table if exists demo_wm; drop table if exists demo_wm;
create table demo_wm (name text, i bigint, way geometry); create table demo_wm (name text, i bigint, way geometry);
insert into demo_wm (name, way) select name, ST_SimplifyWM(way, name) from figures; insert into demo_wm (name, way) select name, ST_SimplifyWM(way, name) from figures where name='fig6-combi';
do $$ do $$
declare declare
@ -125,7 +125,7 @@ begin
) from (select unnest(vcrossings) way) a) ) from (select unnest(vcrossings) way) a)
); );
elems1 = array((select way from debug_wm where stage='cinflections' and name='fig6-combi' and iter=1)); elems1 = array((select way from debug_wm where stage='cinflections' and name='fig6-combi' and gen=1));
elems2 = (select ways from inflections where name='fig6-combi'); elems2 = (select ways from inflections where name='fig6-combi');
foreach elem in array elems1 loop foreach elem in array elems1 loop

31
wm.sql
View File

@ -299,10 +299,9 @@ begin
select (res.area*(0.75/res.cmp)) into res.adjsize; select (res.area*(0.75/res.cmp)) into res.adjsize;
end if; end if;
if dbgname is not null then if dbgname is not null then
insert into debug_wm (stage, name, iter, nbend, way, props) values( insert into debug_wm (stage, name, nbend, way, props) values(
'ebendattrs', 'ebendattrs',
dbgname, dbgname,
1,
i, i,
bend, bend,
json_build_object( json_build_object(
@ -346,10 +345,10 @@ begin
dbg_stage = 1; dbg_stage = 1;
while mutated loop while mutated loop
if dbgname is not null then if dbgname is not null then
insert into debug_wm (stage, name, iter, nbend, way) values( insert into debug_wm (stage, name, gen, nbend, way) values(
'afigures', 'afigures',
dbgname, dbgname,
1, dbg_stage,
i, i,
lines[i] lines[i]
); );
@ -358,22 +357,23 @@ begin
bends = detect_bends(lines[i]); bends = detect_bends(lines[i]);
if dbgname is not null then if dbgname is not null then
insert into debug_wm(stage, name, iter, nbend, way) values( insert into debug_wm(stage, name, gen, nbend, way) values(
'bbends', 'bbends',
dbgname, dbgname,
i, dbg_stage,
generate_subscripts(bends, 1), generate_subscripts(bends, 1),
unnest(bends) unnest(bends)
); );
end if; end if;
raise notice 'before inflections: %', dbg_geomsummary(bends);
bends = fix_gentle_inflections(bends); bends = fix_gentle_inflections(bends);
if dbgname is not null then if dbgname is not null then
insert into debug_wm(stage, name, iter, nbend, way) values( insert into debug_wm(stage, name, gen, nbend, way) values(
'cinflections', 'cinflections',
dbgname, dbgname,
i, dbg_stage,
generate_subscripts(bends, 1), generate_subscripts(bends, 1),
unnest(bends) unnest(bends)
); );
@ -382,10 +382,10 @@ begin
select * from self_crossing(bends) into bends, mutated; select * from self_crossing(bends) into bends, mutated;
if dbgname is not null then if dbgname is not null then
insert into debug_wm(stage, name, iter, nbend, way) values( insert into debug_wm(stage, name, gen, nbend, way) values(
'dcrossings', 'dcrossings',
dbgname, dbgname,
i, dbg_stage,
generate_subscripts(bends, 1), generate_subscripts(bends, 1),
unnest(bends) unnest(bends)
); );
@ -410,3 +410,14 @@ begin
end if; end if;
end end
$$ language plpgsql; $$ language plpgsql;
drop function if exists dbg_geomsummary;
create function dbg_geomsummary(geoms geometry[], OUT output text) as $$
declare i int4;
begin
output = format('len: %s;', array_length(geoms, 1));
for i in 1..array_length(geoms, 1) loop
output = output || format(' %s:%s;', i, st_astext(geoms[i]));
end loop;
end
$$ language plpgsql;