feeder: store delay since receipt_time in evolution tables (#14297)
This commit is contained in:
parent
3238830c31
commit
83c9d7adaf
|
@ -25,12 +25,14 @@ def test_wcs_fixture(wcs, postgres_db, tmpdir, olap_cmd, caplog):
|
|||
('evolution', 'time'),
|
||||
('evolution', 'date'),
|
||||
('evolution', 'hour_id'),
|
||||
('evolution', 'delay'),
|
||||
('evolution_demande', 'id'),
|
||||
('evolution_demande', 'status_id'),
|
||||
('evolution_demande', 'formdata_id'),
|
||||
('evolution_demande', 'time'),
|
||||
('evolution_demande', 'date'),
|
||||
('evolution_demande', 'hour_id'),
|
||||
('evolution_demande', 'delay'),
|
||||
('formdata', 'id'),
|
||||
('formdata', 'formdef_id'),
|
||||
('formdata', 'receipt_time'),
|
||||
|
|
|
@ -500,6 +500,7 @@ CREATE TABLE public.dates AS (SELECT
|
|||
['time', 'timestamp'],
|
||||
['date', 'date'],
|
||||
['hour_id', 'smallint REFERENCES {hour_table} (id)'],
|
||||
['delay', 'interval'],
|
||||
])
|
||||
self.ex('COMMENT ON TABLE {generic_evolution_table} IS %s', vars=(u'evolution générique',))
|
||||
|
||||
|
@ -687,6 +688,7 @@ class WcsFormdefFeeder(object):
|
|||
['time', 'timestamp'],
|
||||
['date', 'date'],
|
||||
['hour_id', 'smallint REFERENCES {hour_table} (id)'],
|
||||
['delay', 'interval'],
|
||||
])
|
||||
self.ex('COMMENT ON TABLE "{evolution_table}" IS %s',
|
||||
vars=(u'evolution des demandes %s' % self.formdef.schema.name,))
|
||||
|
@ -826,11 +828,11 @@ class WcsFormdefFeeder(object):
|
|||
status_id = self.status_mapping[status.id]
|
||||
generic_status_id = self.generic_status(status)
|
||||
evolution.append(
|
||||
[0, status_id, evo.time, evo.time.date(), evo.time.hour])
|
||||
[0, status_id, evo.time, evo.time.date(), evo.time.hour, evo.delay])
|
||||
if generic_status_id == last_status:
|
||||
continue
|
||||
generic_evolution.append(
|
||||
[0, generic_status_id, evo.time, evo.time.date(), evo.time.hour])
|
||||
[0, generic_status_id, evo.time, evo.time.date(), evo.time.hour, evo.delay])
|
||||
last_status = generic_status_id
|
||||
generic_evolution_values.append(generic_evolution)
|
||||
evolution_values.append(evolution)
|
||||
|
@ -849,12 +851,12 @@ class WcsFormdefFeeder(object):
|
|||
generic_evolutions.append(tuple(row))
|
||||
if len(generic_evolutions) == 500:
|
||||
self.ex('INSERT INTO {generic_evolution_table} (%s) VALUES %s' % (
|
||||
', '.join(['formdata_id', 'generic_status_id', 'time', 'date', 'hour_id']),
|
||||
', '.join(['formdata_id', 'generic_status_id', 'time', 'date', 'hour_id', 'delay']),
|
||||
', '.join(['%s'] * len(generic_evolutions))), vars=generic_evolutions)
|
||||
generic_evolutions = []
|
||||
if generic_evolutions:
|
||||
self.ex('INSERT INTO {generic_evolution_table} (%s) VALUES %s' % (
|
||||
', '.join(['formdata_id', 'generic_status_id', 'time', 'date', 'hour_id']),
|
||||
', '.join(['formdata_id', 'generic_status_id', 'time', 'date', 'hour_id', 'delay']),
|
||||
', '.join(['%s'] * len(generic_evolutions))), vars=generic_evolutions)
|
||||
|
||||
# insert evolutions
|
||||
|
@ -865,12 +867,12 @@ class WcsFormdefFeeder(object):
|
|||
evolutions.append(tuple(row))
|
||||
if len(evolutions) == 500:
|
||||
self.ex('INSERT INTO "{evolution_table}" (%s) VALUES %s' % (
|
||||
', '.join(['formdata_id', 'status_id', 'time', 'date', 'hour_id']),
|
||||
', '.join(['%s'] * len(evolutions))), vars=evolutions)
|
||||
', '.join(['formdata_id', 'status_id', 'time', 'date', 'hour_id', 'delay']),
|
||||
', '.join(['%s'] * len(evolutions))), vars=evolutions)
|
||||
evolutions = []
|
||||
if evolutions:
|
||||
self.ex('INSERT INTO "{evolution_table}" (%s) VALUES %s' % (
|
||||
', '.join(['formdata_id', 'status_id', 'time', 'date', 'hour_id']),
|
||||
', '.join(['formdata_id', 'status_id', 'time', 'date', 'hour_id', 'delay']),
|
||||
', '.join(['%s'] * len(evolutions))), vars=evolutions)
|
||||
|
||||
def get_first_agent_in_evolution(self, formdata):
|
||||
|
|
|
@ -79,15 +79,23 @@ class Evolution(BaseObject):
|
|||
who = None
|
||||
status = None
|
||||
parts = None
|
||||
formdata = None
|
||||
|
||||
def __init__(self, wcs_api, **kwargs):
|
||||
def __init__(self, wcs_api, formdata, **kwargs):
|
||||
super(Evolution, self).__init__(wcs_api, **kwargs)
|
||||
self.formdata = formdata
|
||||
self.time = isodate.parse_datetime(self.time)
|
||||
if self.parts:
|
||||
self.parts = [BaseObject(wcs_api, **part) for part in self.parts]
|
||||
if self.who:
|
||||
self.who = EvolutionUser(wcs_api, **self.who)
|
||||
|
||||
@property
|
||||
def delay(self):
|
||||
'''Compute delay as the time when the last not endpoint status precedes an endpoint
|
||||
status.'''
|
||||
return self.time - self.formdata.receipt_time
|
||||
|
||||
|
||||
class FormData(BaseObject):
|
||||
geolocations = None
|
||||
|
@ -98,7 +106,7 @@ class FormData(BaseObject):
|
|||
self.receipt_time = isodate.parse_datetime(self.receipt_time)
|
||||
self.submission = BaseObject(wcs_api, **self.submission)
|
||||
self.workflow = FormDataWorkflow(wcs_api, **self.workflow)
|
||||
self.evolution = [Evolution(wcs_api, **evo) for evo in self.evolution or []]
|
||||
self.evolution = [Evolution(wcs_api, self, **evo) for evo in self.evolution or []]
|
||||
self.functions = {}
|
||||
self.concerned_roles = []
|
||||
self.action_roles = []
|
||||
|
|
Loading…
Reference in New Issue