Projet

Général

Profil

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

Benjamin Dauvergne, 08 mars 2019 00:26

Télécharger (5,58 ko)

Voir les différences:

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

 tests/olap.model   | 51 ++++++++++++++++++++++++++++++++++++++++++++++
 tests/test_wcs.py  | 17 ++++++++++++++++
 wcs_olap/feeder.py | 21 +++++++++++++++++++
 3 files changed, 89 insertions(+)
tests/olap.model
346 346
               "master" : "field_item_open",
347 347
               "name" : "item_open",
348 348
               "table" : "formdata_demande_field_item_open"
349
            },
350
            {
351
               "facts" : "formdata_id",
352
               "master" : "id",
353
               "name" : "evolution",
354
               "table" : "evolution_demande"
349 355
            }
350 356
         ],
351 357
         "key" : "id",
......
386 392
               "label" : "localisation géographique",
387 393
               "name" : "geolocation",
388 394
               "type" : "point"
395
            },
396
            {
397
               "expression" : "MAX(COALESCE(evolution.delay, NOW() - {fact_table}.receipt_time2)) FILTER (WHERE evolution.status_id = 0)",
398
               "join" : [
399
                  "evolution"
400
               ],
401
               "label" : "délai maximum avant le statut Just Submitted",
402
               "name" : "max_delay_until_0_Just_Submitted",
403
               "type" : "duration"
404
            },
405
            {
406
               "expression" : "MAX(COALESCE(evolution.delay, NOW() - {fact_table}.receipt_time2)) FILTER (WHERE evolution.status_id = 1)",
407
               "join" : [
408
                  "evolution"
409
               ],
410
               "label" : "délai maximum avant le statut New",
411
               "name" : "max_delay_until_1_New",
412
               "type" : "duration"
413
            },
414
            {
415
               "expression" : "MAX(COALESCE(evolution.delay, NOW() - {fact_table}.receipt_time2)) FILTER (WHERE evolution.status_id = 2)",
416
               "join" : [
417
                  "evolution"
418
               ],
419
               "label" : "délai maximum avant le statut Rejected",
420
               "name" : "max_delay_until_2_Rejected",
421
               "type" : "duration"
422
            },
423
            {
424
               "expression" : "MAX(COALESCE(evolution.delay, NOW() - {fact_table}.receipt_time2)) FILTER (WHERE evolution.status_id = 3)",
425
               "join" : [
426
                  "evolution"
427
               ],
428
               "label" : "délai maximum avant le statut Accepted",
429
               "name" : "max_delay_until_3_Accepted",
430
               "type" : "duration"
431
            },
432
            {
433
               "expression" : "MAX(COALESCE(evolution.delay, NOW() - {fact_table}.receipt_time2)) FILTER (WHERE evolution.status_id = 4)",
434
               "join" : [
435
                  "evolution"
436
               ],
437
               "label" : "délai maximum avant le statut Finished",
438
               "name" : "max_delay_until_4_Finished",
439
               "type" : "duration"
389 440
            }
390 441
         ],
391 442
         "name" : "formdata_demande"
tests/test_wcs.py
1
import isodate
2
import pprint
1 3
import json
2 4

  
3 5
import pytest
......
97 99
            expected_json_schema['pg_dsn'] = postgres_db.dsn
98 100
            assert json_schema == expected_json_schema
99 101

  
102
    with postgres_db.conn() as conn:
103
        with conn.cursor() as c:
104
            c.execute('SET search_path = olap')
105
            c.execute('''SELECT
106
        item.label,
107
        COUNT(formdata.id) AS demande_count,
108
        MAX(COALESCE(evolution.delay,
109
                     NOW() - formdata.receipt_time2))
110
            FILTER (WHERE evolution.status_id = 1) AS demande_delai
111
    FROM formdata_demande AS formdata
112
    LEFT OUTER JOIN formdata_demande_field_item AS item
113
        ON item.id = formdata.field_item
114
    LEFT OUTER JOIN evolution_demande AS evolution
115
        ON evolution.formdata_id = formdata.id GROUP BY item.label''')
116

  
100 117

  
101 118
def test_requests_exception(wcs, postgres_db, tmpdir, olap_cmd, caplog):
102 119
    with mock.patch('requests.get', side_effect=requests.RequestException('wat!')):
wcs_olap/feeder.py
980 980
                cube['joins'].append(join)
981 981
            cube['dimensions'].append(dimension)
982 982

  
983
        # add join for evolutions
984
        cube['joins'].append({
985
            'name': 'evolution',
986
            'table': self.evolution_table_name,
987
            'master': 'id',
988
            'facts': 'formdata_id',
989
        })
990

  
991
        # add measure of delay for each status since receipt_time
992
        for status_id, status in enumerate(self.formdef.schema.workflow.statuses):
993
            cube['measures'].append(
994
                {
995
                    'name': 'max_delay_until_%s_%s' % (status_id, slugify(status.name)),
996
                    'label': u'délai maximum avant le statut %s' % status.name,
997
                    'type': 'duration',
998
                    'expression': 'MAX(COALESCE(evolution.delay, NOW() - {fact_table}.receipt_time2)) FILTER (WHERE evolution.status_id = %s)' % status_id,
999
                    'join': ['evolution'],
1000
                }
1001
            )
1002

  
1003

  
983 1004
        self.model['cubes'].append(cube)
984 1005
        if self.do_feed:
985 1006
            try:
986
-