Project

General

Profile

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

Benjamin Dauvergne, 08 Mar 2019 12:26 AM

Download (6.27 KB)

View differences:

Subject: [PATCH 1/4] 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
25 25
        ('evolution', 'time'),
26 26
        ('evolution', 'date'),
27 27
        ('evolution', 'hour_id'),
28
        ('evolution', 'delay'),
28 29
        ('evolution_demande', 'id'),
29 30
        ('evolution_demande', 'status_id'),
30 31
        ('evolution_demande', 'formdata_id'),
31 32
        ('evolution_demande', 'time'),
32 33
        ('evolution_demande', 'date'),
33 34
        ('evolution_demande', 'hour_id'),
35
        ('evolution_demande', 'delay'),
34 36
        ('formdata', 'id'),
35 37
        ('formdata', 'formdef_id'),
36 38
        ('formdata', 'receipt_time'),
wcs_olap/feeder.py
488 488
            ['time', 'timestamp'],
489 489
            ['date', 'date'],
490 490
            ['hour_id', 'smallint REFERENCES {hour_table} (id)'],
491
            ['delay', 'interval'],
491 492
        ])
492 493
        self.ex('COMMENT ON TABLE {generic_evolution_table} IS %s', vars=(u'evolution générique',))
493 494

  
......
672 673
            ['time', 'timestamp'],
673 674
            ['date', 'date'],
674 675
            ['hour_id', 'smallint REFERENCES {hour_table} (id)'],
676
            ['delay', 'interval'],
675 677
        ])
676 678
        self.ex('COMMENT ON TABLE {evolution_table} IS %s',
677 679
                vars=(u'evolution des demandes %s' % self.formdef.schema.name,))
......
809 811
                status_id = self.status_mapping[status.id]
810 812
                generic_status_id = self.generic_status(status)
811 813
                evolution.append(
812
                    [0, status_id, evo.time, evo.time.date(), evo.time.hour])
814
                    [0, status_id, evo.time, evo.time.date(), evo.time.hour, evo.delay])
813 815
                if generic_status_id == last_status:
814 816
                    continue
815 817
                generic_evolution.append(
816
                    [0, generic_status_id, evo.time, evo.time.date(), evo.time.hour])
818
                    [0, generic_status_id, evo.time, evo.time.date(), evo.time.hour, evo.delay])
817 819
                last_status = generic_status_id
818 820
            generic_evolution_values.append(generic_evolution)
819 821
            evolution_values.append(evolution)
......
832 834
                generic_evolutions.append(tuple(row))
833 835
                if len(generic_evolutions) == 500:
834 836
                    self.ex('INSERT INTO {generic_evolution_table} (%s) VALUES %s' % (
835
                        ', '.join(['formdata_id', 'generic_status_id', 'time', 'date', 'hour_id']),
837
                        ', '.join(['formdata_id', 'generic_status_id', 'time', 'date', 'hour_id', 'delay']),
836 838
                        ', '.join(['%s'] * len(generic_evolutions))), vars=generic_evolutions)
837 839
                    generic_evolutions = []
838 840
        if generic_evolutions:
839 841
            self.ex('INSERT INTO {generic_evolution_table} (%s) VALUES %s' % (
840
                ', '.join(['formdata_id', 'generic_status_id', 'time', 'date', 'hour_id']),
842
                ', '.join(['formdata_id', 'generic_status_id', 'time', 'date', 'hour_id', 'delay']),
841 843
                ', '.join(['%s'] * len(generic_evolutions))), vars=generic_evolutions)
842 844

  
843 845
        # insert evolutions
......
848 850
                evolutions.append(tuple(row))
849 851
                if len(evolutions) == 500:
850 852
                    self.ex('INSERT INTO {evolution_table} (%s) VALUES %s' % (
851
                       ', '.join(['formdata_id', 'status_id', 'time', 'date', 'hour_id']),
852
                       ', '.join(['%s'] * len(evolutions))), vars=evolutions)
853
                        ', '.join(['formdata_id', 'status_id', 'time', 'date', 'hour_id', 'delay']),
854
                        ', '.join(['%s'] * len(evolutions))), vars=evolutions)
853 855
                    evolutions = []
854 856
        if evolutions:
855 857
            self.ex('INSERT INTO {evolution_table} (%s) VALUES %s' % (
856
                ', '.join(['formdata_id', 'status_id', 'time', 'date', 'hour_id']),
858
                ', '.join(['formdata_id', 'status_id', 'time', 'date', 'hour_id', 'delay']),
857 859
                ', '.join(['%s'] * len(evolutions))), vars=evolutions)
858 860

  
859 861
    def get_first_agent_in_evolution(self, formdata):
wcs_olap/wcs_api.py
79 79
    who = None
80 80
    status = None
81 81
    parts = None
82
    formdata = None
82 83

  
83
    def __init__(self, wcs_api, **kwargs):
84
    def __init__(self, wcs_api, formdata, **kwargs):
84 85
        super(Evolution, self).__init__(wcs_api, **kwargs)
86
        self.formdata = formdata
85 87
        self.time = isodate.parse_datetime(self.time)
86 88
        if self.parts:
87 89
            self.parts = [BaseObject(wcs_api, **part) for part in self.parts]
88 90
        if self.who:
89 91
            self.who = EvolutionUser(wcs_api, **self.who)
90 92

  
93
    @property
94
    def delay(self):
95
        '''Compute delay as the time when the last not endpoint status precedes an endpoint
96
           status.'''
97
        return self.time - self.formdata.receipt_time
98

  
91 99

  
92 100
class FormData(BaseObject):
93 101
    geolocations = None
......
98 106
        self.receipt_time = isodate.parse_datetime(self.receipt_time)
99 107
        self.submission = BaseObject(wcs_api, **self.submission)
100 108
        self.workflow = FormDataWorkflow(wcs_api, **self.workflow)
101
        self.evolution = [Evolution(wcs_api, **evo) for evo in self.evolution or []]
109
        self.evolution = [Evolution(wcs_api, self, **evo) for evo in self.evolution or []]
102 110
        self.functions = {}
103 111
        self.concerned_roles = []
104 112
        self.action_roles = []
105
-