From e9d1587c8e6fc7ee7ad3cdd558d24d8cae6eccbd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Wed, 19 May 2021 22:57:47 +0300 Subject: [PATCH] improve observability --- tests.sql | 8 ++++---- wm.sql | 31 +++++++++++++++++++++---------- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/tests.sql b/tests.sql index ba8db29..fac49bb 100644 --- a/tests.sql +++ b/tests.sql @@ -11,9 +11,9 @@ begin end $$ LANGUAGE plpgsql; -- 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; -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; create table figures (name text, way geometry); @@ -64,7 +64,7 @@ $$ language plpgsql; -- COMBINED drop table if exists demo_wm; 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 $$ declare @@ -125,7 +125,7 @@ begin ) 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'); foreach elem in array elems1 loop diff --git a/wm.sql b/wm.sql index 8948ed0..7c16cb4 100644 --- a/wm.sql +++ b/wm.sql @@ -299,10 +299,9 @@ begin select (res.area*(0.75/res.cmp)) into res.adjsize; end if; 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', dbgname, - 1, i, bend, json_build_object( @@ -346,10 +345,10 @@ begin dbg_stage = 1; while mutated loop 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', dbgname, - 1, + dbg_stage, i, lines[i] ); @@ -358,22 +357,23 @@ begin bends = detect_bends(lines[i]); 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', dbgname, - i, + dbg_stage, generate_subscripts(bends, 1), unnest(bends) ); end if; + raise notice 'before inflections: %', dbg_geomsummary(bends); bends = fix_gentle_inflections(bends); 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', dbgname, - i, + dbg_stage, generate_subscripts(bends, 1), unnest(bends) ); @@ -382,10 +382,10 @@ begin select * from self_crossing(bends) into bends, mutated; 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', dbgname, - i, + dbg_stage, generate_subscripts(bends, 1), unnest(bends) ); @@ -410,3 +410,14 @@ begin end if; end $$ 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;