add measure on max delay before status (#14297)

This commit is contained in:
Benjamin Dauvergne 2019-01-18 22:45:11 +01:00
parent 568cfad036
commit e8a48812f4
3 changed files with 89 additions and 0 deletions

View File

@ -353,6 +353,12 @@
"master" : "\"field_itemOpen\"",
"name" : "itemOpen",
"table" : "formdata_demande_field_itemOpen"
},
{
"facts" : "formdata_id",
"master" : "id",
"name" : "evolution",
"table" : "evolution_demande"
}
],
"key" : "id",
@ -393,6 +399,51 @@
"label" : "localisation géographique",
"name" : "geolocation",
"type" : "point"
},
{
"expression" : "MAX(COALESCE(evolution.delay, NOW() - {fact_table}.receipt_time2)) FILTER (WHERE evolution.status_id = 0)",
"join" : [
"evolution"
],
"label" : "délai maximum avant le statut Just Submitted",
"name" : "max_delay_until_0_Just_Submitted",
"type" : "duration"
},
{
"expression" : "MAX(COALESCE(evolution.delay, NOW() - {fact_table}.receipt_time2)) FILTER (WHERE evolution.status_id = 1)",
"join" : [
"evolution"
],
"label" : "délai maximum avant le statut New",
"name" : "max_delay_until_1_New",
"type" : "duration"
},
{
"expression" : "MAX(COALESCE(evolution.delay, NOW() - {fact_table}.receipt_time2)) FILTER (WHERE evolution.status_id = 2)",
"join" : [
"evolution"
],
"label" : "délai maximum avant le statut Rejected",
"name" : "max_delay_until_2_Rejected",
"type" : "duration"
},
{
"expression" : "MAX(COALESCE(evolution.delay, NOW() - {fact_table}.receipt_time2)) FILTER (WHERE evolution.status_id = 3)",
"join" : [
"evolution"
],
"label" : "délai maximum avant le statut Accepted",
"name" : "max_delay_until_3_Accepted",
"type" : "duration"
},
{
"expression" : "MAX(COALESCE(evolution.delay, NOW() - {fact_table}.receipt_time2)) FILTER (WHERE evolution.status_id = 4)",
"join" : [
"evolution"
],
"label" : "délai maximum avant le statut Finished",
"name" : "max_delay_until_4_Finished",
"type" : "duration"
}
],
"name" : "formdata_demande"

View File

@ -1,3 +1,5 @@
import isodate
import pprint
import json
import pytest
@ -98,6 +100,21 @@ def test_wcs_fixture(wcs, postgres_db, tmpdir, olap_cmd, caplog):
expected_json_schema['pg_dsn'] = postgres_db.dsn
assert json_schema == expected_json_schema
with postgres_db.conn() as conn:
with conn.cursor() as c:
c.execute('SET search_path = olap')
c.execute('''SELECT
item.label,
COUNT(formdata.id) AS demande_count,
MAX(COALESCE(evolution.delay,
NOW() - formdata.receipt_time2))
FILTER (WHERE evolution.status_id = 1) AS demande_delai
FROM formdata_demande AS formdata
LEFT OUTER JOIN formdata_demande_field_item AS item
ON item.id = formdata.field_item
LEFT OUTER JOIN evolution_demande AS evolution
ON evolution.formdata_id = formdata.id GROUP BY item.label''')
def test_requests_exception(wcs, postgres_db, tmpdir, olap_cmd, caplog):
with mock.patch('requests.get', side_effect=requests.RequestException('wat!')):

View File

@ -997,6 +997,27 @@ class WcsFormdefFeeder(object):
cube['joins'].append(join)
cube['dimensions'].append(dimension)
# add join for evolutions
cube['joins'].append({
'name': 'evolution',
'table': self.evolution_table_name,
'master': 'id',
'facts': 'formdata_id',
})
# add measure of delay for each status since receipt_time
for status_id, status in enumerate(self.formdef.schema.workflow.statuses):
cube['measures'].append(
{
'name': 'max_delay_until_%s_%s' % (status_id, slugify(status.name)),
'label': u'délai maximum avant le statut %s' % status.name,
'type': 'duration',
'expression': 'MAX(COALESCE(evolution.delay, NOW() - {fact_table}.receipt_time2)) FILTER (WHERE evolution.status_id = %s)' % status_id,
'join': ['evolution'],
}
)
self.model['cubes'].append(cube)
if self.do_feed:
try: