Skip to content

Commit

Permalink
Functions to calculate total wait, processing, and lead times in the …
Browse files Browse the repository at this point in the history
…pipeline
  • Loading branch information
sarah256 committed Jul 26, 2019
1 parent 5866134 commit 5744a60
Show file tree
Hide file tree
Showing 14 changed files with 922 additions and 97 deletions.
25 changes: 21 additions & 4 deletions estuary/api/v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
from flask import Blueprint, jsonify, request, current_app
from werkzeug.exceptions import NotFound

from estuary import version
from estuary import version, log
from estuary.models.base import EstuaryStructuredNode

from estuary.utils.general import str_to_bool, get_neo4j_node, inflate_node, login_required
from estuary.utils.recents import get_recent_nodes
from estuary.error import ValidationError
Expand Down Expand Up @@ -115,12 +114,21 @@ def _get_partial_story(results, reverse=False):

# Adding the artifact itself if it's story is not available
if not results:
base_instance = estuary.utils.story.BaseStoryManager()
wait_times, total_wait_time = base_instance.get_wait_times([item])
rv = {'data': [item.serialized_all], 'meta': {}}
rv['meta']['story_related_nodes_forward'] = [0]
rv['meta']['story_related_nodes_backward'] = [0]
rv['meta']['requested_node_index'] = 0
rv['meta']['story_type'] = story_manager.__class__.__name__[:-12].lower()
rv['meta']['wait_times'] = [0]
rv['meta']['wait_times'] = wait_times
rv['meta']['total_wait_time'] = total_wait_time
rv['meta']['total_processing_time'] = None
rv['meta']['total_lead_time'] = 0
try:
rv['meta']['total_processing_time'] = base_instance.get_total_processing_time([item])
except: # noqa E722
log.exception('Failed to compute total processing time.')
rv['data'][0]['resource_type'] = item.__label__
rv['data'][0]['display_name'] = item.display_name
rv['data'][0]['timeline_timestamp'] = item.timeline_timestamp
Expand Down Expand Up @@ -227,12 +235,21 @@ def _get_partial_stories(results, reverse=False):

# Adding the artifact itself if its story is not available
if not all_results:
base_instance = estuary.utils.story.BaseStoryManager()
wait_times, total_wait_time = base_instance.get_wait_times([item])
rv = {'data': [item.serialized_all], 'meta': {}}
rv['meta']['story_related_nodes_forward'] = [0]
rv['meta']['story_related_nodes_backward'] = [0]
rv['meta']['requested_node_index'] = 0
rv['meta']['story_type'] = story_manager.__class__.__name__[:-12].lower()
rv['meta']['wait_times'] = [0]
rv['meta']['wait_times'] = wait_times
rv['meta']['total_wait_time'] = total_wait_time
rv['meta']['total_processing_time'] = None
rv['meta']['total_lead_time'] = 0
try:
rv['meta']['total_processing_time'] = base_instance.get_total_processing_time([item])
except: # noqa E722
log.exception('Failed to compute total processing time.')
rv['data'][0]['resource_type'] = item.__label__
rv['data'][0]['display_name'] = item.display_name
rv['data'][0]['timeline_timestamp'] = item.timeline_timestamp
Expand Down
9 changes: 8 additions & 1 deletion estuary/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,15 @@ def display_name(self):

@property
def timeline_timestamp(self):
"""Get the DateTime property used for the Estuary timeline as a string."""
if self.timeline_datetime:
return self.timeline_datetime.strftime('%Y-%m-%dT%H:%M:%SZ')
return None

@property
def timeline_datetime(self):
"""Get the DateTime property used for the Estuary timeline."""
raise NotImplementedError('The timeline_timestamp method is not defined')
raise NotImplementedError('The timeline_datetime method is not defined')

@property
def serialized(self):
Expand Down
6 changes: 2 additions & 4 deletions estuary/models/bugzilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,9 @@ def display_name(self):
return 'RHBZ#{0}'.format(self.id_)

@property
def timeline_timestamp(self):
def timeline_datetime(self):
"""Get the DateTime property used for the Estuary timeline."""
if self.creation_time:
return self.creation_time.strftime('%Y-%m-%dT%H:%M:%SZ')
return None
return self.creation_time

@classmethod
def find_or_none(cls, identifier):
Expand Down
6 changes: 2 additions & 4 deletions estuary/models/distgit.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ def display_name(self):
return 'commit #{0}'.format(self.hash_[:7])

@property
def timeline_timestamp(self):
def timeline_datetime(self):
"""Get the DateTime property used for the Estuary timeline."""
if self.commit_date:
return self.commit_date.strftime('%Y-%m-%dT%H:%M:%SZ')
return None
return self.commit_date
21 changes: 17 additions & 4 deletions estuary/models/errata.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,24 @@ def display_name(self):
return self.advisory_name

@property
def timeline_timestamp(self):
def timeline_datetime(self):
"""Get the DateTime property used for the Estuary timeline."""
if self.created_at:
return self.created_at.strftime('%Y-%m-%dT%H:%M:%SZ')
return None
return self.created_at

@classmethod
def attached_build_time(self, advisory, build):
"""
Get the time that a build related to the advisory was attached.
:param node build: a Neo4j node representing an attached build
:return: the time the build was attached
:rtype: datetime object
"""
rel = advisory.attached_builds.relationship(build)
if rel:
return rel.time_attached
else:
return None

@classmethod
def find_or_none(cls, identifier):
Expand Down
6 changes: 2 additions & 4 deletions estuary/models/freshmaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,9 @@ def display_name(self):
return 'Freshmaker event {0}'.format(self.id_)

@property
def timeline_timestamp(self):
def timeline_datetime(self):
"""Get the DateTime property used for the Estuary timeline."""
if self.time_created:
return self.time_created.strftime('%Y-%m-%dT%H:%M:%SZ')
return None
return self.time_created


class FreshmakerBuild(EstuaryStructuredNode):
Expand Down
6 changes: 2 additions & 4 deletions estuary/models/koji.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@ def display_name(self):
return '{0}-{1}-{2}'.format(self.name, self.version, self.release)

@property
def timeline_timestamp(self):
def timeline_datetime(self):
"""Get the DateTime property used for the Estuary timeline."""
if self.creation_time:
return self.creation_time.strftime('%Y-%m-%dT%H:%M:%SZ')
return None
return self.creation_time

@classmethod
def find_or_none(cls, identifier):
Expand Down

0 comments on commit 5744a60

Please sign in to comment.