1# http://pyrocko.org - GPLv3
2#
3# The Pyrocko Developers, 21st Century
4# ---|P------/S----------~Lg----------
6import math
8from pyrocko import util
11g_tmin, g_tmax = util.get_working_system_time_range()[:2]
14def time_or_none_to_str(x, format):
15 if x is None:
16 return '...'
17 else:
18 return util.time_to_str(x, format=format)
21def squirrel_content(cls):
23 def str_codes(self):
24 return '.'.join(self.codes)
26 cls.str_codes = property(str_codes)
28 def str_time_span(self):
29 tmin, tmax = self.time_span
30 deltat = getattr(self, 'deltat', 0)
31 if deltat > 0:
32 fmt = min(9, max(0, -int(math.floor(math.log10(self.deltat)))))
33 else:
34 fmt = 6
36 if tmin == tmax:
37 return '%s' % time_or_none_to_str(tmin, fmt)
38 else:
39 return '%s - %s' % (
40 time_or_none_to_str(tmin, fmt), time_or_none_to_str(tmax, fmt))
42 cls.str_time_span = property(str_time_span)
44 def summary(self):
45 return '%s %-16s %s' % (
46 self.__class__.__name__, self.str_codes, self.str_time_span)
48 if not hasattr(cls, 'summary'):
49 cls.summary = property(summary)
51 def __lt__(self, other):
52 return self.__key__() < other.__key__()
54 cls.__lt__ = __lt__
56 def __key__(self):
57 return self.codes, self.time_span_g_clipped
59 cls.__key__ = __key__
61 @property
62 def time_span_g_clipped(self):
63 tmin, tmax = self.time_span
64 return (
65 tmin if tmin is not None else g_tmin,
66 tmax if tmax is not None else g_tmax)
68 cls.time_span_g_clipped = property(time_span_g_clipped)
70 return cls