Coverage for /home/ubuntu/Documents/Research/mut_p6/sacred/sacred/observers/base.py: 42%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1#!/usr/bin/env python
2# coding=utf-8
4__all__ = ("RunObserver", "td_format")
7class RunObserver:
8 """Defines the interface for all run observers."""
10 priority = 0
12 def queued_event(
13 self, ex_info, command, host_info, queue_time, config, meta_info, _id
14 ):
15 pass
17 def started_event(
18 self, ex_info, command, host_info, start_time, config, meta_info, _id
19 ):
20 pass
22 def heartbeat_event(self, info, captured_out, beat_time, result):
23 pass
25 def completed_event(self, stop_time, result):
26 pass
28 def interrupted_event(self, interrupt_time, status):
29 pass
31 def failed_event(self, fail_time, fail_trace):
32 pass
34 def resource_event(self, filename):
35 pass
37 def artifact_event(self, name, filename, metadata=None, content_type=None):
38 pass
40 def log_metrics(self, metrics_by_name, info):
41 pass
43 def join(self):
44 pass
47# http://stackoverflow.com/questions/538666/python-format-timedelta-to-string
48def td_format(td_object):
49 seconds = int(td_object.total_seconds())
50 if seconds == 0:
51 return "less than a second"
53 periods = [
54 ("year", 60 * 60 * 24 * 365),
55 ("month", 60 * 60 * 24 * 30),
56 ("day", 60 * 60 * 24),
57 ("hour", 60 * 60),
58 ("minute", 60),
59 ("second", 1),
60 ]
62 strings = []
63 for period_name, period_seconds in periods:
64 if seconds >= period_seconds:
65 period_value, seconds = divmod(seconds, period_seconds)
66 if period_value == 1:
67 strings.append("%s %s" % (period_value, period_name))
68 else:
69 strings.append("%s %ss" % (period_value, period_name))
71 return ", ".join(strings)