From 94b8e7492da145b99ebfd0836523be04626fc550 Mon Sep 17 00:00:00 2001 From: Mario de Frutos Date: Mon, 9 Oct 2017 14:12:20 +0200 Subject: [PATCH 1/2] OBS_GetAvailableGeometries now receives number of geometries from input We need the number of geometries to pass them to the get score function in order to get an accurate score for the input in order to suggest what is the geometry that fits better for the input we have --- src/pg/observatory.control | 2 +- src/pg/sql/42_observatory_exploration.sql | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/pg/observatory.control b/src/pg/observatory.control index 149b6a5..84e7094 100644 --- a/src/pg/observatory.control +++ b/src/pg/observatory.control @@ -1,5 +1,5 @@ comment = 'CartoDB Observatory backend extension' -default_version = '1.7.0' +default_version = '1.8.0' requires = 'postgis' superuser = true schema = cdb_observatory diff --git a/src/pg/sql/42_observatory_exploration.sql b/src/pg/sql/42_observatory_exploration.sql index bbd5e56..272eec2 100644 --- a/src/pg/sql/42_observatory_exploration.sql +++ b/src/pg/sql/42_observatory_exploration.sql @@ -323,7 +323,8 @@ CREATE OR REPLACE FUNCTION cdb_observatory.OBS_GetAvailableGeometries( filter_tags TEXT[] DEFAULT NULL, numer_id TEXT DEFAULT NULL, denom_id TEXT DEFAULT NULL, - timespan TEXT DEFAULT NULL + timespan TEXT DEFAULT NULL, + number_geoms INTEGER DEFAULT NULL ) RETURNS TABLE ( geom_id TEXT, geom_name TEXT, @@ -390,15 +391,16 @@ BEGIN FROM observatory.obs_meta_geom o WHERE %s (geom_tags ?& $4 OR CARDINALITY($4) = 0) ), scores AS ( - SELECT * FROM cdb_observatory._OBS_GetGeometryScores($5, - (SELECT ARRAY_AGG(geom_id) FROM available_geoms) + SELECT * FROM cdb_observatory._OBS_GetGeometryScores(bounds => $5, + filter_geom_ids => (SELECT ARRAY_AGG(geom_id) FROM available_geoms), + desired_num_geoms => $6::integer ) ) SELECT DISTINCT ON (geom_id) available_geoms.*, score, numtiles, notnull_percent, numgeoms, percentfill, estnumgeoms, meanmediansize FROM available_geoms, scores WHERE available_geoms.geom_id = scores.column_id $string$, geom_clause) - USING numer_id, denom_id, timespan, filter_tags, bounds; + USING numer_id, denom_id, timespan, filter_tags, bounds, number_geoms; RETURN; END $$ LANGUAGE plpgsql; From 1da0b8cb6b737f199320c1653cac7a47631ba37f Mon Sep 17 00:00:00 2001 From: Mario de Frutos Date: Wed, 18 Oct 2017 10:00:15 +0200 Subject: [PATCH 2/2] Update doc with new field --- doc/discovery_functions.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/discovery_functions.md b/doc/discovery_functions.md index 356ddd3..697a163 100644 --- a/doc/discovery_functions.md +++ b/doc/discovery_functions.md @@ -228,7 +228,7 @@ SELECT * FROM cdb_observatory.OBS_GetAvailableDenominators( WHERE valid_timespan IS True; ``` -## OBS_GetAvailableGeometries(bounds, filter_tags, numer_id, denom_id, timespan) +## OBS_GetAvailableGeometries(bounds, filter_tags, numer_id, denom_id, timespan, number_geometries) Return available geometries within a boundary and with the specified `filter_tags`. @@ -242,6 +242,7 @@ filter_tags | Text[] | a list of filters. Only geometries for which all of thes numer_id | Text | the ID of a numerator to check whether the geometry is valid against. Will not reduce length of returned table, but will change values for `valid_numer` (optional) denom_id | Text | the ID of a denominator to check whether the geometry is valid against. Will not reduce length of returned table, but will change values for `valid_denom` (optional) timespan | Text | the ID of a timespan to check whether the geometry is valid against. Will not reduce length of returned table, but will change values for `valid_timespan` (optional) +number_geometries | Integer | Number of geometries of the source data in order to calculate more accurately the score value to know which geometry fits better with the provided extent. (optional) #### Returns