wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
import copy
|
|
|
|
import os
|
|
|
|
import json
|
|
|
|
import hashlib
|
2016-04-28 14:51:55 +02:00
|
|
|
from utils import Whatever
|
|
|
|
import psycopg2
|
2016-01-09 22:04:36 +01:00
|
|
|
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
from wcs_olap.wcs_api import WcsApiError
|
|
|
|
|
|
|
|
|
|
|
|
def slugify(s):
|
|
|
|
return s.replace('-', '_').replace(' ', '_')
|
|
|
|
|
|
|
|
|
|
|
|
class Context(object):
|
|
|
|
def __init__(self):
|
|
|
|
self.stack = []
|
|
|
|
|
|
|
|
def __getitem__(self, key):
|
|
|
|
if not self.stack:
|
|
|
|
raise KeyError(key)
|
|
|
|
for d in self.stack[::-1]:
|
|
|
|
try:
|
|
|
|
return d[key]
|
|
|
|
except KeyError:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
raise KeyError(key)
|
|
|
|
|
|
|
|
def push(self, d):
|
|
|
|
self.stack.append(d)
|
|
|
|
|
|
|
|
def pop(self):
|
|
|
|
self.stack = self.stack[:-1]
|
|
|
|
|
|
|
|
def as_dict(self):
|
|
|
|
r = {}
|
|
|
|
for d in self.stack:
|
|
|
|
r.update(d)
|
|
|
|
return r
|
|
|
|
|
2016-01-09 22:04:36 +01:00
|
|
|
|
|
|
|
class WcsOlapFeeder(object):
|
2016-05-12 21:31:16 +02:00
|
|
|
def __init__(self, api, pg_dsn, schema, logger=None, config=None, do_feed=True):
|
2016-01-09 22:04:36 +01:00
|
|
|
self.api = api
|
2016-04-28 14:51:55 +02:00
|
|
|
self.logger = logger or Whatever()
|
|
|
|
self.schema = schema
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
self.connection = psycopg2.connect(dsn=pg_dsn)
|
|
|
|
self.connection.autocommit = True
|
2016-04-28 14:51:55 +02:00
|
|
|
self.cur = self.connection.cursor()
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
self.formdefs = api.formdefs
|
2016-04-28 14:51:55 +02:00
|
|
|
self.roles = api.roles
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
self.categories = api.categories
|
2016-05-12 21:31:16 +02:00
|
|
|
self.do_feed = do_feed
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
self.ctx = Context()
|
|
|
|
self.ctx.push({
|
2016-04-28 14:51:55 +02:00
|
|
|
'schema': self.schema,
|
|
|
|
'role_table': 'role',
|
|
|
|
'channel_table': 'channel',
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
'category_table': 'category',
|
|
|
|
'form_table': 'formdef',
|
|
|
|
'generic_formdata_table': 'formdata',
|
|
|
|
'generic_status_table': 'status',
|
|
|
|
'year_table': 'year',
|
|
|
|
'month_table': 'month',
|
|
|
|
'day_table': 'day',
|
|
|
|
'dow_table': 'dow',
|
|
|
|
'hour_table': 'hour',
|
|
|
|
})
|
|
|
|
self.config = config or {}
|
|
|
|
self.model = {
|
|
|
|
'label': self.config.get('cubes_label', schema),
|
|
|
|
'name': schema,
|
2016-05-12 21:31:16 +02:00
|
|
|
'search_path': [schema, 'public'],
|
|
|
|
'pg_dsn': pg_dsn,
|
|
|
|
'cubes': [],
|
|
|
|
}
|
|
|
|
cube = {
|
|
|
|
'name': 'all_formdata',
|
|
|
|
'label': u'Tous les formulaires',
|
|
|
|
'fact_table': 'formdata',
|
|
|
|
'key': 'id',
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
'joins': [
|
|
|
|
{
|
|
|
|
'name': 'receipt_time',
|
2016-05-12 21:31:16 +02:00
|
|
|
'table': 'dates',
|
|
|
|
'detail': 'date',
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
'master': 'receipt_time',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
'name': 'channel',
|
2016-05-12 21:31:16 +02:00
|
|
|
'table': 'channel',
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
'master': 'channel_id',
|
2016-05-12 21:31:16 +02:00
|
|
|
'detail': 'id',
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
'name': 'formdef',
|
2016-05-12 21:31:16 +02:00
|
|
|
'table': 'formdef',
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
'master': 'formdef_id',
|
2016-05-12 21:31:16 +02:00
|
|
|
'detail': 'id',
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
'name': 'category',
|
2016-05-12 21:31:16 +02:00
|
|
|
'table': 'category',
|
|
|
|
'master': 'formdef.category_id',
|
|
|
|
'detail': 'id',
|
|
|
|
'kind': 'left',
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
'name': 'hour',
|
2016-05-12 21:31:16 +02:00
|
|
|
'table': 'hour',
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
'master': 'hour_id',
|
2016-05-12 21:31:16 +02:00
|
|
|
'detail': 'id',
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
'name': 'generic_status',
|
2016-05-12 21:31:16 +02:00
|
|
|
'table': 'status',
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
'master': 'generic_status_id',
|
2016-05-12 21:31:16 +02:00
|
|
|
'detail': 'id',
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
},
|
|
|
|
],
|
|
|
|
'dimensions': [
|
|
|
|
{
|
|
|
|
'name': 'receipt_time',
|
2016-05-12 21:31:16 +02:00
|
|
|
'label': 'date de la demande',
|
|
|
|
'join': ['receipt_time'],
|
|
|
|
'type': 'date',
|
|
|
|
'value': 'receipt_time.date',
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
},
|
|
|
|
{
|
2016-05-12 21:31:16 +02:00
|
|
|
'name': 'channel',
|
|
|
|
'label': 'canal',
|
|
|
|
'join': ['channel'],
|
|
|
|
'type': 'integer',
|
|
|
|
'value': 'channel.id',
|
|
|
|
'value_label': 'channel.label',
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
},
|
|
|
|
{
|
2016-05-12 21:31:16 +02:00
|
|
|
'name': 'category',
|
|
|
|
'label': 'catégorie',
|
|
|
|
'join': ['formdef', 'category'],
|
|
|
|
'type': 'integer',
|
|
|
|
'value': 'category.id',
|
|
|
|
'value_label': 'category.label',
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
'name': 'formdef',
|
2016-05-12 21:31:16 +02:00
|
|
|
'label': 'formulaire',
|
|
|
|
'join': ['formdef'],
|
|
|
|
'type': 'integer',
|
|
|
|
'value': 'formdef.id',
|
|
|
|
'value_label': 'formdef.label',
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
},
|
|
|
|
{
|
2016-05-12 21:31:16 +02:00
|
|
|
'name': 'generic_status',
|
2016-06-18 09:25:35 +02:00
|
|
|
'label': 'statut simplifié',
|
2016-05-12 21:31:16 +02:00
|
|
|
'join': ['generic_status'],
|
|
|
|
'type': 'integer',
|
|
|
|
'value': 'generic_status.id',
|
|
|
|
'value_label': 'generic_status.label',
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
},
|
|
|
|
{
|
2016-05-12 21:31:16 +02:00
|
|
|
'name': 'hour',
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
'label': 'heure',
|
2016-05-12 21:31:16 +02:00
|
|
|
'join': ['hour'],
|
|
|
|
'type': 'integer',
|
|
|
|
'value': 'hour.id',
|
|
|
|
'filter': False,
|
2016-06-18 09:30:10 +02:00
|
|
|
},
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
],
|
2016-05-12 21:31:16 +02:00
|
|
|
'measures': [
|
|
|
|
{
|
|
|
|
'name': 'count',
|
|
|
|
'label': 'nombre de demandes',
|
|
|
|
'type': 'integer',
|
|
|
|
'expression': 'count({fact_table}.id)',
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
},
|
2016-05-12 21:31:16 +02:00
|
|
|
{
|
|
|
|
'name': 'avg_endpoint_delay',
|
|
|
|
'label': 'délai de traitement moyen',
|
|
|
|
'type': 'duration',
|
|
|
|
'expression': 'avg(endpoint_delay)',
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
},
|
2016-05-12 21:31:16 +02:00
|
|
|
{
|
|
|
|
'name': 'max_endpoint_delay',
|
|
|
|
'label': 'délai de traitement maximum',
|
|
|
|
'type': 'duration',
|
|
|
|
'expression': 'max(endpoint_delay)',
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
},
|
|
|
|
{
|
2016-05-12 21:31:16 +02:00
|
|
|
'name': 'min_endpoint_delay',
|
|
|
|
'label': 'délai de traitement minimum',
|
|
|
|
'type': 'duration',
|
|
|
|
'expression': 'min(endpoint_delay)',
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
},
|
2016-05-12 21:31:16 +02:00
|
|
|
{
|
|
|
|
'name': 'percent',
|
2016-05-25 10:24:51 +02:00
|
|
|
'label': 'pourcentage des demandes',
|
2016-05-12 21:31:16 +02:00
|
|
|
'type': 'percent',
|
|
|
|
"expression": 'count({fact_table}.id) * 100. '
|
|
|
|
'/ (select count({fact_table}.id) from {table_expression} '
|
|
|
|
'where {where_conditions})',
|
|
|
|
}
|
|
|
|
]
|
2016-04-28 14:51:55 +02:00
|
|
|
}
|
2016-05-12 21:31:16 +02:00
|
|
|
self.model['cubes'].append(cube)
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
self.base_cube = self.model['cubes'][0]
|
|
|
|
|
|
|
|
def hash_table_name(self, table_name):
|
|
|
|
table_name = table_name.format(**self.default_ctx)
|
|
|
|
if len(table_name) < 64:
|
|
|
|
return table_name
|
|
|
|
else:
|
|
|
|
return table_name[:57] + hashlib.md5(table_name).hexdigest()[:6]
|
|
|
|
|
|
|
|
@property
|
|
|
|
def default_ctx(self):
|
|
|
|
return self.ctx.as_dict()
|
2016-04-28 14:51:55 +02:00
|
|
|
|
|
|
|
def ex(self, query, ctx=None, vars=None):
|
|
|
|
ctx = ctx or {}
|
|
|
|
ctx.update(self.default_ctx)
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
sql = query.format(**(ctx or {}))
|
|
|
|
self.logger.debug('SQL: %s VARS: %s', sql, vars)
|
|
|
|
self.cur.execute(sql, vars=vars)
|
2016-04-28 14:51:55 +02:00
|
|
|
|
|
|
|
def exmany(self, query, varslist, ctx=None):
|
|
|
|
ctx = ctx or {}
|
|
|
|
ctx.update(self.default_ctx)
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
sql = query.format(**(ctx or {}))
|
|
|
|
self.logger.debug('SQL: %s VARSLIST: %s', sql, varslist)
|
|
|
|
self.cur.executemany(sql, varslist)
|
2016-04-28 14:51:55 +02:00
|
|
|
|
|
|
|
def do_schema(self):
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
self.logger.debug('dropping schema %s', self.schema)
|
2016-04-28 14:51:55 +02:00
|
|
|
self.ex('SET search_path = public')
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
self.ex('DROP SCHEMA IF EXISTS {schema} CASCADE')
|
|
|
|
self.logger.debug('creating schema %s', self.schema)
|
|
|
|
self.ex('CREATE SCHEMA {schema}')
|
2016-04-28 14:51:55 +02:00
|
|
|
self.ex('SET search_path = {schema},public')
|
|
|
|
|
|
|
|
channels = [
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
[1, 'web', u'web'],
|
2016-04-28 14:51:55 +02:00
|
|
|
[2, 'mail', u'courrier'],
|
|
|
|
[3, 'phone', u'téléphone'],
|
|
|
|
[4, 'counter', u'guichet'],
|
2016-06-18 09:28:47 +02:00
|
|
|
[5, 'backoffice', u'backoffice'],
|
2016-04-28 14:51:55 +02:00
|
|
|
]
|
|
|
|
channel_to_id = dict((c[1], c[0]) for c in channels)
|
|
|
|
id_to_channel = dict((c[0], c[1]) for c in channels)
|
|
|
|
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
status = [
|
|
|
|
[1, 'Nouveau'],
|
|
|
|
[2, 'En cours'],
|
|
|
|
[3, 'Terminé'],
|
|
|
|
]
|
|
|
|
status_to_id = dict((c[1], c[0]) for c in channels)
|
|
|
|
id_to_status = dict((c[0], c[1]) for c in channels)
|
|
|
|
|
|
|
|
def create_table(self, name, columns, inherits=None, comment=None):
|
|
|
|
sql = 'CREATE TABLE %s' % name
|
|
|
|
sql += '(' + ', '.join('%s %s' % (n, t) for n, t in columns) + ')'
|
|
|
|
if inherits:
|
|
|
|
sql += ' INHERITS (%s)' % inherits
|
|
|
|
self.ex(sql)
|
|
|
|
if comment:
|
|
|
|
self.ex('COMMENT ON TABLE %s IS %%s' % name, vars=(comment,))
|
|
|
|
|
|
|
|
def create_labeled_table(self, name, labels, comment=None):
|
|
|
|
self.create_table(name,
|
|
|
|
[
|
|
|
|
['id', 'smallint primary key'],
|
|
|
|
['label', 'varchar']
|
|
|
|
], comment=comment)
|
|
|
|
values = ', '.join(self.cur.mogrify('(%s, %s)', [_id, _label]) for _id, _label in labels)
|
|
|
|
if not values:
|
|
|
|
return
|
|
|
|
self.ex('INSERT INTO %s (id, label) VALUES %s' % (str(name), values))
|
|
|
|
|
|
|
|
def tpl(self, o, ctx=None):
|
|
|
|
ctx = ctx or {}
|
|
|
|
ctx.update(self.default_ctx)
|
|
|
|
|
|
|
|
def helper(o):
|
|
|
|
if isinstance(o, basestring):
|
|
|
|
return o.format(**ctx)
|
|
|
|
elif isinstance(o, dict):
|
|
|
|
return dict((k, helper(v)) for k, v in o.iteritems())
|
|
|
|
elif isinstance(o, list):
|
|
|
|
return [helper(v) for v in o]
|
|
|
|
elif isinstance(o, (bool, int, float)):
|
|
|
|
return o
|
|
|
|
else:
|
|
|
|
assert False, '%s is not a valid value for JSON' % o
|
|
|
|
return helper(o)
|
|
|
|
|
|
|
|
def add_dim(self, **kwargs):
|
|
|
|
self.dimensions.append(self.tpl(kwargs))
|
|
|
|
|
2016-04-28 14:51:55 +02:00
|
|
|
def do_base_table(self):
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
# channels
|
2016-06-18 09:26:46 +02:00
|
|
|
self.create_labeled_table('{channel_table}', [[c[0], c[2]] for c in self.channels],
|
|
|
|
comment=u'canal')
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
|
|
|
|
# roles
|
|
|
|
roles = dict((i, role.name) for i, role in enumerate(self.roles))
|
2016-06-18 09:26:46 +02:00
|
|
|
self.create_labeled_table('{role_table}', roles.items(), comment=u'role')
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
self.role_mapping = dict((role.id, i) for i, role in enumerate(self.roles))
|
|
|
|
|
|
|
|
# categories
|
2016-06-18 09:26:46 +02:00
|
|
|
self.create_labeled_table('{category_table}', enumerate(c.name for c in self.categories),
|
|
|
|
comment=u'catégorie')
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
self.categories_mapping = dict((c.id, i) for i, c in enumerate(self.categories))
|
|
|
|
|
2016-06-18 09:26:46 +02:00
|
|
|
self.create_labeled_table('{hour_table}', zip(range(0, 24), map(str, range(0, 24))),
|
|
|
|
comment=u'heures')
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
|
2016-06-18 09:26:46 +02:00
|
|
|
self.create_labeled_table('{generic_status_table}', self.status,
|
|
|
|
comment=u'statuts simplifiés')
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
self.ex('CREATE TABLE {form_table} (id serial PRIMARY KEY,'
|
|
|
|
' category_id integer REFERENCES {category_table} (id),'
|
|
|
|
' label varchar)')
|
2016-06-18 09:26:46 +02:00
|
|
|
self.ex('COMMENT ON TABLE {form_table} IS %s', vars=(u'types de formulaire',))
|
2016-06-18 09:30:10 +02:00
|
|
|
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
self.columns = [
|
|
|
|
['id', 'serial primary key'],
|
|
|
|
['formdef_id', 'smallint REFERENCES {form_table} (id)'],
|
|
|
|
['receipt_time', 'date'],
|
|
|
|
['hour_id', 'smallint REFERENCES {hour_table} (id)'],
|
|
|
|
['channel_id', 'smallint REFERENCES {channel_table} (id)'],
|
|
|
|
['backoffice', 'boolean'],
|
|
|
|
['generic_status_id', 'smallint REFERENCES {generic_status_table} (id)'],
|
2016-05-12 21:31:16 +02:00
|
|
|
['endpoint_delay', 'interval'],
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
]
|
|
|
|
self.comments = {
|
2016-05-12 21:31:16 +02:00
|
|
|
'formdef_id': u'formulaire',
|
|
|
|
'receipt_time': u'date de réception',
|
|
|
|
'hour_id': u'heure',
|
|
|
|
'channel_id': u'canal',
|
|
|
|
'backoffice': u'soumission backoffce',
|
2016-06-18 09:25:35 +02:00
|
|
|
'generic_status_id': u'statut simplifié',
|
2016-05-12 21:31:16 +02:00
|
|
|
'endpoint_delay': u'délai de traitement',
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
}
|
|
|
|
self.create_table('{generic_formdata_table}', self.columns)
|
|
|
|
for at, comment in self.comments.iteritems():
|
|
|
|
self.ex('COMMENT ON COLUMN {generic_formdata_table}.%s IS %%s' % at, vars=(comment,))
|
2016-06-18 09:26:46 +02:00
|
|
|
self.ex('COMMENT ON TABLE {generic_formdata_table} IS %s', vars=(u'tous les formulaires',))
|
2016-01-09 22:04:36 +01:00
|
|
|
|
|
|
|
def feed(self):
|
2016-05-12 21:31:16 +02:00
|
|
|
if self.do_feed:
|
|
|
|
self.do_schema()
|
|
|
|
self.do_base_table()
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
for formdef in self.formdefs:
|
|
|
|
try:
|
2016-05-12 21:31:16 +02:00
|
|
|
formdef_feeder = WcsFormdefFeeder(self, formdef, do_feed=self.do_feed)
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
formdef_feeder.feed()
|
|
|
|
except WcsApiError, e:
|
|
|
|
# ignore authorization errors
|
|
|
|
if (len(e.args) > 2 and hasattr(e.args[2], 'response')
|
|
|
|
and e.args[2].response.status_code == 403):
|
|
|
|
continue
|
|
|
|
self.logger.error('failed to retrieve formdef %s', formdef.slug)
|
2016-05-12 21:31:16 +02:00
|
|
|
if 'cubes_model_dirs' in self.config:
|
|
|
|
model_path = os.path.join(self.config['cubes_model_dirs'], '%s.model' % self.schema)
|
|
|
|
with open(model_path, 'w') as f:
|
|
|
|
json.dump(self.model, f, indent=2, sort_keys=True)
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
|
2016-01-09 22:04:36 +01:00
|
|
|
|
2016-04-28 14:51:55 +02:00
|
|
|
class WcsFormdefFeeder(object):
|
2016-05-12 21:31:16 +02:00
|
|
|
def __init__(self, olap_feeder, formdef, do_feed=True):
|
2016-04-28 14:51:55 +02:00
|
|
|
self.olap_feeder = olap_feeder
|
|
|
|
self.formdef = formdef
|
|
|
|
self.status_mapping = {}
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
self.items_mappings = {}
|
2016-05-12 21:31:16 +02:00
|
|
|
self.do_feed = do_feed
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
self.fields = []
|
2016-04-28 14:51:55 +02:00
|
|
|
|
|
|
|
@property
|
|
|
|
def table_name(self):
|
2016-05-21 13:13:08 +02:00
|
|
|
return self.hash_table_name('formdata_%s' % self.formdef.slug.replace('-', '_'))
|
2016-04-28 14:51:55 +02:00
|
|
|
|
|
|
|
@property
|
|
|
|
def status_table_name(self):
|
2016-05-21 13:13:08 +02:00
|
|
|
return self.hash_table_name('status_%s' % self.formdef.slug.replace('-', '_'))
|
2016-04-28 14:51:55 +02:00
|
|
|
|
|
|
|
def __getattr__(self, name):
|
|
|
|
return getattr(self.olap_feeder, name)
|
|
|
|
|
|
|
|
def do_statuses(self):
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
statuses = self.formdef.schema.workflow.statuses
|
|
|
|
self.olap_feeder.create_labeled_table(self.status_table_name,
|
2016-06-18 09:26:46 +02:00
|
|
|
enumerate([s.name for s in statuses]),
|
|
|
|
comment=u'statuts du formulaire « %s »' %
|
|
|
|
self.formdef.schema.name)
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
self.status_mapping = dict((s.id, i) for i, s in enumerate(statuses))
|
2016-04-28 14:51:55 +02:00
|
|
|
|
|
|
|
def do_data_table(self):
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
self.ex('INSERT INTO {form_table} (category_id, label) VALUES (%s, %s) RETURNING (id)',
|
|
|
|
vars=[self.categories_mapping.get(self.formdef.schema.category_id),
|
|
|
|
self.formdef.schema.name])
|
|
|
|
self.formdef_sql_id = self.cur.fetchone()[0]
|
|
|
|
|
|
|
|
columns = [['status_id', 'smallint REFERENCES {status_table} (id)']]
|
|
|
|
|
|
|
|
comments = {}
|
|
|
|
|
|
|
|
# add item fields
|
|
|
|
for field in self.formdef.schema.fields:
|
|
|
|
if not field.items and not field.options:
|
|
|
|
continue
|
|
|
|
if not field.varname:
|
|
|
|
continue
|
|
|
|
self.fields.append(field)
|
2016-06-18 09:26:46 +02:00
|
|
|
comment = (u'valeurs du champ « %s » du formulaire %s'
|
|
|
|
% (field.label, self.formdef.schema.name))
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
table_name = self.hash_table_name('{formdata_table}_field_%s' % field.varname)
|
|
|
|
# create table and mapping
|
|
|
|
if field.items:
|
|
|
|
self.create_labeled_table(table_name, enumerate(field.items),
|
|
|
|
comment=comment)
|
|
|
|
self.items_mappings[field.varname] = dict(
|
|
|
|
(item, i) for i, item in enumerate(field.items))
|
|
|
|
elif field.options:
|
|
|
|
options = enumerate(field.options)
|
|
|
|
for option in field.options:
|
|
|
|
self.create_labeled_table(table_name,
|
|
|
|
[(i, o['label']) for i, o in options],
|
|
|
|
comment=comment)
|
|
|
|
self.items_mappings[field.varname] = dict((o['value'], i) for i, o in options)
|
|
|
|
|
|
|
|
at = 'field_%s' % field.varname
|
|
|
|
columns.append([at, 'smallint REFERENCES %s (id)' % table_name])
|
2016-06-18 09:26:46 +02:00
|
|
|
comments[at] = field.label
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
|
|
|
|
# add geolocation fields
|
|
|
|
for geolocation, label in self.formdef.schema.geolocations:
|
|
|
|
at = 'geolocation_%s' % geolocation
|
|
|
|
columns.append([at, 'point'])
|
2016-06-18 09:26:46 +02:00
|
|
|
comments[at] = label
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
|
|
|
|
# add function fields
|
|
|
|
for function, name in self.formdef.schema.workflow.functions.iteritems():
|
|
|
|
at = 'function_%s' % slugify(function)
|
|
|
|
columns.append([at, 'smallint REFERENCES {role_table} (id)'])
|
2016-06-18 09:26:46 +02:00
|
|
|
comments[at] = u'fonction « %s »' % name
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
|
|
|
|
self.columns = ([name for name, _type in self.olap_feeder.columns]
|
|
|
|
+ [name for name, _type in columns])
|
|
|
|
self.create_table('{formdata_table}', columns, inherits='{generic_formdata_table}',
|
2016-06-18 09:26:46 +02:00
|
|
|
comment=u'formulaire %s' % self.formdef.schema.name)
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
for at, comment in comments.iteritems():
|
|
|
|
self.ex('COMMENT ON COLUMN {formdata_table}.%s IS %%s' % at, vars=(comment,))
|
|
|
|
# PostgreSQL does not propagate foreign key constraints to child tables
|
|
|
|
# so we must recreate them manually
|
|
|
|
for name, _type in self.olap_feeder.columns:
|
|
|
|
if 'REFERENCES' not in _type:
|
|
|
|
continue
|
|
|
|
i = _type.index('REFERENCES')
|
|
|
|
constraint = '%s_fk_constraint FOREIGN KEY (%s) %s' % (name, name, _type[i:])
|
|
|
|
self.ex('ALTER TABLE {formdata_table} ADD CONSTRAINT %s' % constraint)
|
|
|
|
|
|
|
|
def do_data(self):
|
|
|
|
values = []
|
|
|
|
for data in self.formdef.datas:
|
|
|
|
|
|
|
|
# ignore formdata without status
|
|
|
|
if not data.workflow.status:
|
|
|
|
continue
|
|
|
|
|
|
|
|
status = data.formdef.schema.workflow.statuses_map[data.workflow.status.id]
|
2016-06-18 09:28:47 +02:00
|
|
|
channel = data.submission.channel.lower()
|
|
|
|
if channel == 'web' and data.submission.backoffice:
|
|
|
|
channel = 'backoffice'
|
2016-06-18 09:29:07 +02:00
|
|
|
# Simplify status
|
|
|
|
if status.endpoint:
|
|
|
|
generic_status = 3
|
|
|
|
elif status.startpoint:
|
|
|
|
generic_status = 1
|
|
|
|
else:
|
|
|
|
generic_status = 2
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
row = {
|
|
|
|
'formdef_id': self.formdef_sql_id,
|
|
|
|
'receipt_time': data.receipt_time,
|
|
|
|
'hour_id': data.receipt_time.hour,
|
2016-06-18 09:28:47 +02:00
|
|
|
'channel_id': self.channel_to_id[channel],
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
'backoffice': data.submission.backoffice,
|
|
|
|
# FIXME "En cours"/2 is never used
|
|
|
|
'generic_status_id': 3 if status.endpoint else 1,
|
|
|
|
'status_id': self.status_mapping[data.workflow.status.id],
|
2016-05-12 21:31:16 +02:00
|
|
|
'endpoint_delay': data.endpoint_delay,
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
}
|
|
|
|
# add form fields value
|
|
|
|
for field in self.fields:
|
|
|
|
v = None
|
|
|
|
if field.type == 'item':
|
|
|
|
# map items to sql id
|
|
|
|
v = self.items_mappings[field.varname].get(data.fields.get(field.varname))
|
|
|
|
row['field_%s' % field.varname] = v
|
|
|
|
# add geolocation fields value
|
|
|
|
for geolocation, label in self.formdef.schema.geolocations:
|
|
|
|
v = (data.geolocations or {}).get(geolocation)
|
|
|
|
row['geolocation_%s' % geolocation] = v
|
|
|
|
# add function fields value
|
|
|
|
for function, name in self.formdef.schema.workflow.functions.iteritems():
|
|
|
|
try:
|
|
|
|
v = data.functions[function]
|
|
|
|
except KeyError:
|
|
|
|
v = None
|
|
|
|
else:
|
2016-05-19 14:37:08 +02:00
|
|
|
v = v and self.olap_feeder.role_mapping[v.id]
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
at = 'function_%s' % slugify(function)
|
|
|
|
row[at] = v
|
|
|
|
|
|
|
|
tpl = '(' + ', '.join(['%s'] * len(self.columns[1:])) + ')'
|
|
|
|
value = self.cur.mogrify(tpl, [row[column] for column in self.columns[1:]])
|
|
|
|
values.append(value)
|
|
|
|
if not values:
|
|
|
|
self.logger.warning('no data')
|
|
|
|
return
|
|
|
|
self.ex('INSERT INTO {formdata_table} (%s) VALUES %s' % (
|
|
|
|
', '.join(self.columns[1:]), # skip the id column
|
|
|
|
', '.join(values)))
|
2016-04-28 14:51:55 +02:00
|
|
|
|
|
|
|
def feed(self):
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
self.olap_feeder.ctx.push({
|
|
|
|
'formdata_table': self.table_name,
|
|
|
|
'status_table': self.status_table_name,
|
|
|
|
})
|
|
|
|
|
|
|
|
# create cube
|
2016-05-12 21:31:16 +02:00
|
|
|
cube = self.cube = copy.deepcopy(self.base_cube)
|
|
|
|
cube.update({
|
|
|
|
'name': self.table_name,
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
'label': self.formdef.schema.name,
|
2016-05-12 21:31:16 +02:00
|
|
|
'fact_table': self.table_name,
|
|
|
|
'key': 'id',
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
})
|
2016-05-12 21:31:16 +02:00
|
|
|
cube['dimensions'] = [dimension for dimension in cube['dimensions']
|
|
|
|
if dimension['name'] not in ('category', 'formdef')]
|
|
|
|
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
# add dimension for status
|
2016-05-12 21:31:16 +02:00
|
|
|
cube['joins'].append({
|
|
|
|
'name': 'status',
|
|
|
|
'table': self.status_table_name,
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
'master': 'status_id',
|
2016-05-12 21:31:16 +02:00
|
|
|
'detail': 'id',
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
})
|
2016-05-12 21:31:16 +02:00
|
|
|
cube['dimensions'].append({
|
|
|
|
'name': 'status',
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
'label': 'statut',
|
2016-05-12 21:31:16 +02:00
|
|
|
'join': ['status'],
|
|
|
|
'type': 'integer',
|
|
|
|
'value': 'status.id',
|
|
|
|
'value_label': 'status.label',
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
# add dimension for function
|
|
|
|
for function, name in self.formdef.schema.workflow.functions.iteritems():
|
|
|
|
at = 'function_%s' % slugify(function)
|
2016-05-12 21:31:16 +02:00
|
|
|
cube['joins'].append({
|
|
|
|
'name': at,
|
|
|
|
'table': 'role',
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
'master': at,
|
2016-05-12 21:31:16 +02:00
|
|
|
'detail': 'id',
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
})
|
2016-05-12 21:31:16 +02:00
|
|
|
cube['dimensions'].append({
|
|
|
|
'name': at,
|
2016-05-25 10:24:51 +02:00
|
|
|
'label': u'fonction %s' % name.lower(),
|
2016-05-12 21:31:16 +02:00
|
|
|
'join': [at],
|
|
|
|
'type': 'integer',
|
|
|
|
'value': '%s.id' % at,
|
|
|
|
'value_label': '%s.label' % at,
|
|
|
|
'filter': False,
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
# add dimensions for item fields
|
2016-05-25 10:13:17 +02:00
|
|
|
for field in self.formdef.schema.fields:
|
|
|
|
if not field.items and not field.options:
|
|
|
|
continue
|
|
|
|
if not field.varname:
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
continue
|
|
|
|
table_name = self.hash_table_name('{formdata_table}_field_%s' % field.varname)
|
2016-05-12 21:31:16 +02:00
|
|
|
cube['joins'].append({
|
|
|
|
'name': field.varname,
|
2016-05-25 10:13:17 +02:00
|
|
|
'table': table_name,
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
'master': 'field_%s' % field.varname,
|
2016-05-25 10:13:17 +02:00
|
|
|
'detail': 'id',
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
})
|
2016-05-12 21:31:16 +02:00
|
|
|
cube['dimensions'].append({
|
|
|
|
'name': field.varname,
|
2016-05-25 10:24:51 +02:00
|
|
|
'label': field.label.lower(),
|
2016-05-12 21:31:16 +02:00
|
|
|
'join': [field.varname],
|
|
|
|
'type': 'integer',
|
|
|
|
'value': '%s.id' % field.varname,
|
|
|
|
'value_label': '%s.label' % field.varname,
|
|
|
|
'filter': field.in_filters,
|
wcs-olap: build a start schema from data exported by w.c.s. API
Given such an .INI file:
[https://demarches.triffouilly.fr/]
orig = bi.triffouilly.fr
key = 452b8964
pg_dsn = dbname=publik-bi
email = bi@entrouvert.com
schema = triffouilly
# slugs = recette-technique-ajout-d-un-enfant
It builds a schema named 'triffouilly' in the pre-existing database named 'publik-bi', the schema will contains tables named:
channel (label varchar)
role (label varchar)
category (label varchar)
form (category, label)
formdata : parent table of all formdata tables)
(form, receipt_time, year, month, dow, hour, channel, backoffice, generic_status)
status (generic statuses: new, in progress & closed
label
for each formdef tables named:
formdata_{formdef.slug}
status_{formdef.slug}
for each anonymisable
2016-05-10 16:53:17 +02:00
|
|
|
})
|
2016-05-12 21:31:16 +02:00
|
|
|
|
|
|
|
self.model['cubes'].append(cube)
|
|
|
|
if self.do_feed:
|
|
|
|
try:
|
|
|
|
self.logger.info('feed formdef %s', self.formdef.slug)
|
|
|
|
self.do_statuses()
|
|
|
|
self.do_data_table()
|
|
|
|
self.do_data()
|
|
|
|
finally:
|
|
|
|
self.olap_feeder.ctx.pop()
|