Projet

Général

Profil

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

Benjamin Dauvergne, 24 septembre 2019 15:28

Télécharger (5,58 ko)

Voir les différences:

Subject: [PATCH 5/7] 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
353 353
               "master" : "\"field_itemOpen\"",
354 354
               "name" : "itemOpen",
355 355
               "table" : "formdata_demande_field_itemOpen"
356
            },
357
            {
358
               "facts" : "formdata_id",
359
               "master" : "id",
360
               "name" : "evolution",
361
               "table" : "evolution_demande"
356 362
            }
357 363
         ],
358 364
         "key" : "id",
......
393 399
               "label" : "localisation géographique",
394 400
               "name" : "geolocation",
395 401
               "type" : "point"
402
            },
403
            {
404
               "expression" : "MAX(COALESCE(evolution.delay, NOW() - {fact_table}.receipt_time2)) FILTER (WHERE evolution.status_id = 0)",
405
               "join" : [
406
                  "evolution"
407
               ],
408
               "label" : "délai maximum avant le statut Just Submitted",
409
               "name" : "max_delay_until_0_Just_Submitted",
410
               "type" : "duration"
411
            },
412
            {
413
               "expression" : "MAX(COALESCE(evolution.delay, NOW() - {fact_table}.receipt_time2)) FILTER (WHERE evolution.status_id = 1)",
414
               "join" : [
415
                  "evolution"
416
               ],
417
               "label" : "délai maximum avant le statut New",
418
               "name" : "max_delay_until_1_New",
419
               "type" : "duration"
420
            },
421
            {
422
               "expression" : "MAX(COALESCE(evolution.delay, NOW() - {fact_table}.receipt_time2)) FILTER (WHERE evolution.status_id = 2)",
423
               "join" : [
424
                  "evolution"
425
               ],
426
               "label" : "délai maximum avant le statut Rejected",
427
               "name" : "max_delay_until_2_Rejected",
428
               "type" : "duration"
429
            },
430
            {
431
               "expression" : "MAX(COALESCE(evolution.delay, NOW() - {fact_table}.receipt_time2)) FILTER (WHERE evolution.status_id = 3)",
432
               "join" : [
433
                  "evolution"
434
               ],
435
               "label" : "délai maximum avant le statut Accepted",
436
               "name" : "max_delay_until_3_Accepted",
437
               "type" : "duration"
438
            },
439
            {
440
               "expression" : "MAX(COALESCE(evolution.delay, NOW() - {fact_table}.receipt_time2)) FILTER (WHERE evolution.status_id = 4)",
441
               "join" : [
442
                  "evolution"
443
               ],
444
               "label" : "délai maximum avant le statut Finished",
445
               "name" : "max_delay_until_4_Finished",
446
               "type" : "duration"
396 447
            }
397 448
         ],
398 449
         "name" : "formdata_demande"
tests/test_wcs.py
1
import isodate
2
import pprint
1 3
import json
2 4

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

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

  
101 118

  
102 119
def test_requests_exception(wcs, postgres_db, tmpdir, olap_cmd, caplog):
103 120
    with mock.patch('requests.get', side_effect=requests.RequestException('wat!')):
wcs_olap/feeder.py
997 997
                cube['joins'].append(join)
998 998
            cube['dimensions'].append(dimension)
999 999

  
1000
        # add join for evolutions
1001
        cube['joins'].append({
1002
            'name': 'evolution',
1003
            'table': self.evolution_table_name,
1004
            'master': 'id',
1005
            'facts': 'formdata_id',
1006
        })
1007

  
1008
        # add measure of delay for each status since receipt_time
1009
        for status_id, status in enumerate(self.formdef.schema.workflow.statuses):
1010
            cube['measures'].append(
1011
                {
1012
                    'name': 'max_delay_until_%s_%s' % (status_id, slugify(status.name)),
1013
                    'label': u'délai maximum avant le statut %s' % status.name,
1014
                    'type': 'duration',
1015
                    'expression': 'MAX(COALESCE(evolution.delay, NOW() - {fact_table}.receipt_time2)) FILTER (WHERE evolution.status_id = %s)' % status_id,
1016
                    'join': ['evolution'],
1017
                }
1018
            )
1019

  
1020

  
1000 1021
        self.model['cubes'].append(cube)
1001 1022
        if self.do_feed:
1002 1023
            try:
1003
-