Project

General

Profile

0002-feeder-store-delay-since-receipt_time-in-evolution-t.patch

Benjamin Dauvergne, 18 Jan 2019 11:09 PM

Download (6.22 KB)

View differences:

Subject: [PATCH 2/5] feeder: store delay since receipt_time in evolution
 tables (#14297)

 tests/test_wcs.py   |  2 ++
 wcs_olap/feeder.py  | 16 +++++++++-------
 wcs_olap/wcs_api.py | 12 ++++++++++--
 3 files changed, 21 insertions(+), 9 deletions(-)
tests/test_wcs.py
37 37
        ('evolution', 'time'),
38 38
        ('evolution', 'date'),
39 39
        ('evolution', 'hour_id'),
40
        ('evolution', 'delay'),
40 41
        ('evolution_demande', 'id'),
41 42
        ('evolution_demande', 'status_id'),
42 43
        ('evolution_demande', 'formdata_id'),
43 44
        ('evolution_demande', 'time'),
44 45
        ('evolution_demande', 'date'),
45 46
        ('evolution_demande', 'hour_id'),
47
        ('evolution_demande', 'delay'),
46 48
        ('formdata', 'id'),
47 49
        ('formdata', 'formdef_id'),
48 50
        ('formdata', 'receipt_time'),
wcs_olap/feeder.py
422 422
            ['time', 'timestamp'],
423 423
            ['date', 'date'],
424 424
            ['hour_id', 'smallint REFERENCES {hour_table} (id)'],
425
            ['delay', 'interval'],
425 426
        ])
426 427
        self.ex('COMMENT ON TABLE {generic_evolution_table} IS %s', vars=(u'evolution générique',))
427 428

  
......
617 618
            ['time', 'timestamp'],
618 619
            ['date', 'date'],
619 620
            ['hour_id', 'smallint REFERENCES {hour_table} (id)'],
621
            ['delay', 'interval'],
620 622
        ])
621 623
        self.ex('COMMENT ON TABLE {evolution_table} IS %s',
622 624
                vars=(u'evolution des demandes %s' % self.formdef.schema.name,))
......
749 751
                status_id = self.status_mapping[status.id]
750 752
                generic_status_id = self.generic_status(status)
751 753
                evolution.append(
752
                    [0, status_id, evo.time, evo.time.date(), evo.time.hour])
754
                    [0, status_id, evo.time, evo.time.date(), evo.time.hour, evo.delay])
753 755
                if generic_status_id == last_status:
754 756
                    continue
755 757
                generic_evolution.append(
756
                    [0, generic_status_id, evo.time, evo.time.date(), evo.time.hour])
758
                    [0, generic_status_id, evo.time, evo.time.date(), evo.time.hour, evo.delay])
757 759
                last_status = generic_status_id
758 760
            generic_evolution_values.append(generic_evolution)
759 761
            evolution_values.append(evolution)
......
772 774
                generic_evolutions.append(tuple(row))
773 775
                if len(generic_evolutions) == 500:
774 776
                    self.ex('INSERT INTO {generic_evolution_table} (%s) VALUES %s' % (
775
                        ', '.join(['formdata_id', 'generic_status_id', 'time', 'date', 'hour_id']),
777
                        ', '.join(['formdata_id', 'generic_status_id', 'time', 'date', 'hour_id', 'delay']),
776 778
                        ', '.join(['%s'] * len(generic_evolutions))), vars=generic_evolutions)
777 779
                    generic_evolutions = []
778 780
        if generic_evolutions:
779 781
            self.ex('INSERT INTO {generic_evolution_table} (%s) VALUES %s' % (
780
                ', '.join(['formdata_id', 'generic_status_id', 'time', 'date', 'hour_id']),
782
                ', '.join(['formdata_id', 'generic_status_id', 'time', 'date', 'hour_id', 'delay']),
781 783
                ', '.join(['%s'] * len(generic_evolutions))), vars=generic_evolutions)
782 784

  
783 785
        # insert evolutions
......
788 790
                evolutions.append(tuple(row))
789 791
                if len(evolutions) == 500:
790 792
                    self.ex('INSERT INTO {evolution_table} (%s) VALUES %s' % (
791
                       ', '.join(['formdata_id', 'status_id', 'time', 'date', 'hour_id']),
792
                       ', '.join(['%s'] * len(evolutions))), vars=evolutions)
793
                        ', '.join(['formdata_id', 'status_id', 'time', 'date', 'hour_id', 'delay']),
794
                        ', '.join(['%s'] * len(evolutions))), vars=evolutions)
793 795
                    evolutions = []
794 796
        if evolutions:
795 797
            self.ex('INSERT INTO {evolution_table} (%s) VALUES %s' % (
796
                ', '.join(['formdata_id', 'status_id', 'time', 'date', 'hour_id']),
798
                ', '.join(['formdata_id', 'status_id', 'time', 'date', 'hour_id', 'delay']),
797 799
                ', '.join(['%s'] * len(evolutions))), vars=evolutions)
798 800

  
799 801
    def get_first_agent_in_evolution(self, formdata):
wcs_olap/wcs_api.py
43 43
    who = None
44 44
    status = None
45 45
    parts = None
46
    formdata = None
46 47

  
47
    def __init__(self, wcs_api, **kwargs):
48
    def __init__(self, wcs_api, formdata, **kwargs):
48 49
        super(Evolution, self).__init__(wcs_api, **kwargs)
50
        self.formdata = formdata
49 51
        self.time = isodate.parse_datetime(self.time)
50 52
        if self.parts:
51 53
            self.parts = [BaseObject(wcs_api, **part) for part in self.parts]
52 54
        if self.who:
53 55
            self.who = EvolutionUser(wcs_api, **self.who)
54 56

  
57
    @property
58
    def delay(self):
59
        '''Compute delay as the time when the last not endpoint status precedes an endpoint
60
           status.'''
61
        return self.time - self.formdata.receipt_time
62

  
55 63

  
56 64
class FormData(BaseObject):
57 65
    geolocations = None
......
62 70
        self.receipt_time = isodate.parse_datetime(self.receipt_time)
63 71
        self.submission = BaseObject(wcs_api, **self.submission)
64 72
        self.workflow = FormDataWorkflow(wcs_api, **self.workflow)
65
        self.evolution = [Evolution(wcs_api, **evo) for evo in self.evolution or []]
73
        self.evolution = [Evolution(wcs_api, self, **evo) for evo in self.evolution or []]
66 74
        self.functions = {}
67 75
        self.concerned_roles = []
68 76
        self.action_roles = []
69
-