1# http://pyrocko.org - GPLv3
2#
3# The Pyrocko Developers, 21st Century
4# ---|P------/S----------~Lg----------
6import math
8from pyrocko.guts import Object
9from pyrocko import util
12g_tmin, g_tmax = util.get_working_system_time_range()[:2]
15def time_or_none_to_str(x, format):
16 if x is None:
17 return '...'
18 else:
19 return util.time_to_str(x, format=format)
22class Content(Object):
23 '''
24 Base class for Pyrocko content objects.
25 '''
27 @property
28 def str_codes(self):
29 return '.'.join(self.codes)
31 @property
32 def str_time_span(self):
33 tmin, tmax = self.time_span
34 deltat = getattr(self, 'deltat', 0)
35 if deltat > 0:
36 fmt = min(9, max(0, -int(math.floor(math.log10(self.deltat)))))
37 else:
38 fmt = 6
40 if tmin == tmax:
41 return '%s' % time_or_none_to_str(tmin, fmt)
42 else:
43 return '%s - %s' % (
44 time_or_none_to_str(tmin, fmt), time_or_none_to_str(tmax, fmt))
46 @property
47 def summary(self):
48 return '%s %-16s %s' % (
49 self.__class__.__name__, self.str_codes, self.str_time_span)
51 def __lt__(self, other):
52 return self.__key__() < other.__key__()
54 def __key__(self):
55 return self.codes, self.time_span_g_clipped
57 @property
58 def time_span_g_clipped(self):
59 tmin, tmax = self.time_span
60 return (
61 tmin if tmin is not None else g_tmin,
62 tmax if tmax is not None else g_tmax)