def _AveragePerCommitExecutionTime(try_job_data, display_data): if (hasattr(try_job_data, 'number_of_commits_analyzed') and try_job_data.number_of_commits_analyzed and try_job_data.end_time and try_job_data.start_time): display_data['execution_time_per_commit'] = time_util.FormatTimedelta( (try_job_data.end_time - try_job_data.start_time) / try_job_data.number_of_commits_analyzed) else: display_data['execution_time_per_commit'] = 'N/A'
def testFormatTimedelta(self): self.assertIsNone(time_util.FormatTimedelta(None)) self.assertEqual(time_util.FormatTimedelta(timedelta(0, 0)), '00:00:00') self.assertEqual(time_util.FormatTimedelta(timedelta(0, 1)), '00:00:01') self.assertEqual(time_util.FormatTimedelta(timedelta(0, 60)), '00:01:00') self.assertEqual(time_util.FormatTimedelta(timedelta(0, 3600)), '01:00:00') self.assertEqual(time_util.FormatTimedelta(timedelta(0, 0, 1)), '00:00:00')
def testFormatTimedelta(self): self.assertIsNone(time_util.FormatTimedelta(None)) self.assertEqual(time_util.FormatTimedelta(timedelta(0, 0)), '00:00:00') self.assertEqual(time_util.FormatTimedelta(timedelta(0, 1)), '00:00:01') self.assertEqual(time_util.FormatTimedelta(timedelta(0, 60)), '00:01:00') self.assertEqual(time_util.FormatTimedelta(timedelta(0, 3600)), '01:00:00') self.assertEqual(time_util.FormatTimedelta(timedelta(0, 0, 1)), '00:00:00') self.assertEqual( time_util.FormatTimedelta(datetime(2018, 1, 2, 1) - datetime(2018, 1, 1, 1), with_days=True), '1 day, 00:00:00') self.assertEqual( time_util.FormatTimedelta(datetime(2018, 1, 3, 1) - datetime(2018, 1, 1), with_days=True), '2 days, 01:00:00')
def GenerateFlakesData(flakes, include_closed_bug=False): """Processes flakes data to make them ready to be displayed on pages. Args: flakes ([Flake]): A list of Flake objects. include_closed_bug (bool): True to include info about closed bugs. Otherwise False. Returns: [dict]: A list of dicts containing each flake's data. """ flakes_data = [] for flake in flakes: flake_dict = flake.to_dict() # Tries to use merge_destination first, then falls back to the bug that # directly associates to the flake. flake_issue = GetFlakeIssue(flake) if (flake_issue and (include_closed_bug or (flake_issue.status and flake_issue.status in OPEN_STATUSES))): # pragma: no branch. # Only show open bugs on dashboard. # Unless told otherwise. flake_dict['flake_issue'] = flake_issue.to_dict() flake_dict['flake_issue'][ 'issue_link'] = FlakeIssue.GetLinkForIssue( flake_issue.monorail_project, flake_issue.issue_id) flake_dict['flake_issue'][ 'last_updated_time_in_monorail'] = _GetLastUpdatedTimeDelta( flake_issue) flake_dict['flake_urlsafe_key'] = flake.key.urlsafe() flake_dict['time_delta'] = time_util.FormatTimedelta( time_util.GetUTCNow() - flake.last_occurred_time, with_days=True) if flake.last_occurred_time else None flake_dict['flake_counts_last_week'] = _GetFlakeCountsList( flake.flake_counts_last_week) flakes_data.append(flake_dict) return flakes_data
def _GetLastUpdatedTimeDelta(flake_issue): """Uses the latest update time we can get as last_updated_time_in_monorail.""" last_updated_time = flake_issue.last_updated_time_in_monorail or None return (time_util.FormatTimedelta( time_util.GetUTCNow() - last_updated_time, with_days=True) if last_updated_time else None)
def _FormatDuration(start_time, end_time): if not start_time or not end_time: return NOT_AVAILABLE return time_util.FormatTimedelta(end_time - start_time)