Projet

Général

Profil

0004-add-measure-on-max-delay-before-status-14297.patch

Benjamin Dauvergne, 18 janvier 2019 23:09

Télécharger (5,4 ko)

Voir les différences:

Subject: [PATCH 4/5] add measure on max delay before status (#14297)

 tests/olap.model   | 51 ++++++++++++++++++++++++++++++++++++++++++++++
 tests/test_wcs.py  | 15 ++++++++++++++
 wcs_olap/feeder.py | 21 +++++++++++++++++++
 3 files changed, 87 insertions(+)
tests/olap.model
329 329
               "master" : "field_field_item",
330 330
               "name" : "field_item",
331 331
               "table" : "formdata_demande_field_field_item"
332
            },
333
            {
334
               "facts" : "formdata_id",
335
               "master" : "id",
336
               "name" : "evolution",
337
               "table" : "evolution_demande"
332 338
            }
333 339
         ],
334 340
         "key" : "id",
......
369 375
               "label" : "localisation géographique",
370 376
               "name" : "geolocation",
371 377
               "type" : "point"
378
            },
379
            {
380
               "expression" : "MAX(COALESCE(evolution.delay, NOW() - {fact_table}.receipt_time2)) FILTER (WHERE evolution.status_id = 0)",
381
               "join" : [
382
                  "evolution"
383
               ],
384
               "label" : "délai maximum avant le statut Just Submitted",
385
               "name" : "max_delay_until_0_Just_Submitted",
386
               "type" : "duration"
387
            },
388
            {
389
               "expression" : "MAX(COALESCE(evolution.delay, NOW() - {fact_table}.receipt_time2)) FILTER (WHERE evolution.status_id = 1)",
390
               "join" : [
391
                  "evolution"
392
               ],
393
               "label" : "délai maximum avant le statut New",
394
               "name" : "max_delay_until_1_New",
395
               "type" : "duration"
396
            },
397
            {
398
               "expression" : "MAX(COALESCE(evolution.delay, NOW() - {fact_table}.receipt_time2)) FILTER (WHERE evolution.status_id = 2)",
399
               "join" : [
400
                  "evolution"
401
               ],
402
               "label" : "délai maximum avant le statut Rejected",
403
               "name" : "max_delay_until_2_Rejected",
404
               "type" : "duration"
405
            },
406
            {
407
               "expression" : "MAX(COALESCE(evolution.delay, NOW() - {fact_table}.receipt_time2)) FILTER (WHERE evolution.status_id = 3)",
408
               "join" : [
409
                  "evolution"
410
               ],
411
               "label" : "délai maximum avant le statut Accepted",
412
               "name" : "max_delay_until_3_Accepted",
413
               "type" : "duration"
414
            },
415
            {
416
               "expression" : "MAX(COALESCE(evolution.delay, NOW() - {fact_table}.receipt_time2)) FILTER (WHERE evolution.status_id = 4)",
417
               "join" : [
418
                  "evolution"
419
               ],
420
               "label" : "délai maximum avant le statut Finished",
421
               "name" : "max_delay_until_4_Finished",
422
               "type" : "duration"
372 423
            }
373 424
         ],
374 425
         "name" : "formdata_demande"
tests/test_wcs.py
1
import isodate
2
import pprint
1 3
import json
2 4
import pathlib2
3 5

  
......
104 106
            expected_json_schema = json.load(fd2)
105 107
            expected_json_schema['pg_dsn'] = postgres_db.dsn
106 108
            assert json_schema == expected_json_schema
109

  
110
    with postgres_db.conn() as conn:
111
        with conn.cursor() as c:
112
            c.execute('SET search_path = olap')
113
            c.execute('''SELECT
114
        item.label,
115
        COUNT(formdata.id) AS demande_count,
116
        MAX(COALESCE(evolution.delay, NOW() - formdata.receipt_time2)) FILTER (WHERE evolution.status_id = 1) AS demande_delai
117
    FROM formdata_demande AS formdata
118
    LEFT OUTER JOIN formdata_demande_field_field_item AS item
119
        ON item.id = formdata.field_field_item
120
    LEFT OUTER JOIN evolution_demande AS evolution
121
        ON evolution.formdata_id = formdata.id GROUP BY item.label''')
wcs_olap/feeder.py
916 916
                cube['joins'].append(join)
917 917
            cube['dimensions'].append(dimension)
918 918

  
919
        # add join for evolutions
920
        cube['joins'].append({
921
            'name': 'evolution',
922
            'table': self.evolution_table_name,
923
            'master': 'id',
924
            'facts': 'formdata_id',
925
        })
926

  
927
        # add measure of delay for each status since receipt_time
928
        for status_id, status in enumerate(self.formdef.schema.workflow.statuses):
929
            cube['measures'].append(
930
                {
931
                    'name': 'max_delay_until_%s_%s' % (status_id, slugify(status.name)),
932
                    'label': u'délai maximum avant le statut %s' % status.name,
933
                    'type': 'duration',
934
                    'expression': 'MAX(COALESCE(evolution.delay, NOW() - {fact_table}.receipt_time2)) FILTER (WHERE evolution.status_id = %s)' % status_id,
935
                    'join': ['evolution'],
936
                }
937
            )
938

  
939

  
919 940
        self.model['cubes'].append(cube)
920 941
        if self.do_feed:
921 942
            try:
922
-