From 437f4924d2f88a4be6182280f34730c8b418c03e Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Wed, 1 Mar 2017 16:59:15 +0100 Subject: [PATCH] declare geolocation fields in schema files (fixes #14572) It's declared as a measure whose value is the array aggregate of the points. --- README.rst | 5 +++++ wcs_olap/feeder.py | 13 ++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index adc3a1d..d678688 100644 --- a/README.rst +++ b/README.rst @@ -24,3 +24,8 @@ cube. --key KEY HMAC key for signatures --pg-dsn PG_DSN Psycopg2 DB DSN --schema SCHEMA schema name + +Requirements +------------ + +PostgreSQL > 9.4 is required. diff --git a/wcs_olap/feeder.py b/wcs_olap/feeder.py index eeb164a..946708f 100644 --- a/wcs_olap/feeder.py +++ b/wcs_olap/feeder.py @@ -227,6 +227,12 @@ class WcsOlapFeeder(object): 'count({fact_table}.id) * 100. / (select ' 'count({fact_table}.id) from {table_expression} where ' '{where_conditions}) end', + }, + { + 'name': 'geolocation', + 'label': 'localisation géographique', + 'type': 'point', + 'expression': 'array_agg("{fact_table}".geolocation_base) FILTER (WHERE "{fact_table}".geolocation_base IS NOT NULL)', } ] } @@ -383,6 +389,7 @@ CREATE TABLE public.dates AS (SELECT ['generic_status_id', 'smallint REFERENCES {generic_status_table} (id)'], ['endpoint_delay', 'interval'], ['first_agent_id', 'smallint REFERENCES {agent_table} (id)'], + ['geolocation_base', 'POINT NULL'], ['json_data', 'JSONB NULL'], ] self.comments = { @@ -393,6 +400,7 @@ CREATE TABLE public.dates AS (SELECT 'backoffice': u'soumission backoffce', 'generic_status_id': u'statut simplifié', 'endpoint_delay': u'délai de traitement', + 'geolocation_base': u'position géographique', } self.create_table('{generic_formdata_table}', self.columns) for at, comment in self.comments.iteritems(): @@ -561,6 +569,8 @@ class WcsFormdefFeeder(object): self.columns = ([name for name, _type in self.olap_feeder.columns] + [name for name, _type in columns]) + self.columns.remove('geolocation_base') + self.create_table('{formdata_table}', columns, inherits='{generic_formdata_table}', comment=u'formulaire %s' % self.formdef.schema.name) for at, comment in comments.iteritems(): @@ -589,7 +599,8 @@ class WcsFormdefFeeder(object): ['date', 'date'], ['hour_id', 'smallint REFERENCES {hour_table} (id)'], ]) - self.ex('COMMENT ON TABLE {evolution_table} IS %s', vars=(u'evolution des demandes %s' % self.formdef.schema.name,)) + self.ex('COMMENT ON TABLE {evolution_table} IS %s', + vars=(u'evolution des demandes %s' % self.formdef.schema.name,)) def insert_item_value(self, field, value): table_name = self.hash_table_name('{formdata_table}_field_%s' % field.varname)