commit 40a76cc7d6566626a871abf0934a379b3cad40bb Author: juga0 juga@riseup.net Date: Wed Aug 29 14:40:28 2018 +0000
Reorder methods in BWV3Header
1. magic methods 2. classmethods 3. staticmethods 4. properties 5. methods --- sbws/lib/v3bwfile.py | 116 +++++++++++++++++++++++++-------------------------- 1 file changed, 58 insertions(+), 58 deletions(-)
diff --git a/sbws/lib/v3bwfile.py b/sbws/lib/v3bwfile.py index ad3e2e2..d663445 100644 --- a/sbws/lib/v3bwfile.py +++ b/sbws/lib/v3bwfile.py @@ -109,53 +109,26 @@ class V3BWHeader(object): [setattr(self, k, v) for k, v in kwargs.items() if k in EXTRA_ARG_KEYVALUES]
- @property - def keyvalue_unordered_tuple_ls(self): - """Return list of KeyValue tuples that do not have specific order.""" - # sort the list to generate determinist headers - keyvalue_tuple_ls = sorted([(k, v) for k, v in self.__dict__.items() - if k in UNORDERED_KEYVALUES]) - return keyvalue_tuple_ls - - @property - def keyvalue_tuple_ls(self): - """Return list of all KeyValue tuples""" - return [('version', self.version)] + self.keyvalue_unordered_tuple_ls - - @property - def keyvalue_v110str_ls(self): - """Return KeyValue list of strings following spec v1.1.0.""" - keyvalues = [self.timestamp] + [KEYVALUE_SEP_V110.join([k, v]) - for k, v in self.keyvalue_tuple_ls] - return keyvalues - - @property - def strv110(self): - """Return header string following spec v1.1.0.""" - header_str = LINE_SEP.join(self.keyvalue_v110str_ls) + LINE_SEP + \ - LINE_TERMINATOR - return header_str - - @property - def keyvalue_v200_ls(self): - """Return KeyValue list of strings following spec v2.0.0.""" - keyvalue = [self.timestamp] + [KEYVALUE_SEP_V200.join([k, v]) - for k, v in self.keyvalue_tuple_ls] - return keyvalue - - @property - def strv200(self): - """Return header string following spec v2.0.0.""" - header_str = LINE_SEP.join(self.keyvalue_v200_ls) + LINE_SEP + \ - LINE_TERMINATOR - return header_str - def __str__(self): if self.version == '1.1.0': return self.strv110 return self.strv200
@classmethod + def from_results(cls, conf, results): + kwargs = dict() + latest_bandwidth = cls.latest_bandwidth_from_results(results) + earliest_bandwidth = cls.earliest_bandwidth_from_results(results) + generator_started = cls.generator_started_from_file(conf) + timestamp = str(latest_bandwidth) + kwargs['latest_bandwidth'] = unixts_to_isodt_str(latest_bandwidth) + kwargs['earliest_bandwidth'] = unixts_to_isodt_str(earliest_bandwidth) + if generator_started is not None: + kwargs['generator_started'] = generator_started + h = cls(timestamp, **kwargs) + return h + + @classmethod def from_lines_v110(cls, lines): """ :param list lines: list of lines to parse @@ -184,10 +157,6 @@ class V3BWHeader(object): assert isinstance(text, str) return self.from_lines_v110(text.split(LINE_SEP))
- @property - def num_lines(self): - return len(self.__str__().split(LINE_SEP)) - @staticmethod def generator_started_from_file(conf): ''' @@ -208,19 +177,50 @@ class V3BWHeader(object): def earliest_bandwidth_from_results(results): return round(min([r.time for fp in results for r in results[fp]]))
- @classmethod - def from_results(cls, conf, results): - kwargs = dict() - latest_bandwidth = cls.latest_bandwidth_from_results(results) - earliest_bandwidth = cls.earliest_bandwidth_from_results(results) - generator_started = cls.generator_started_from_file(conf) - timestamp = str(latest_bandwidth) - kwargs['latest_bandwidth'] = unixts_to_isodt_str(latest_bandwidth) - kwargs['earliest_bandwidth'] = unixts_to_isodt_str(earliest_bandwidth) - if generator_started is not None: - kwargs['generator_started'] = generator_started - h = cls(timestamp, **kwargs) - return h + @property + def keyvalue_unordered_tuple_ls(self): + """Return list of KeyValue tuples that do not have specific order.""" + # sort the list to generate determinist headers + keyvalue_tuple_ls = sorted([(k, v) for k, v in self.__dict__.items() + if k in UNORDERED_KEYVALUES]) + return keyvalue_tuple_ls + + @property + def keyvalue_tuple_ls(self): + """Return list of all KeyValue tuples""" + return [('version', self.version)] + self.keyvalue_unordered_tuple_ls + + @property + def keyvalue_v110str_ls(self): + """Return KeyValue list of strings following spec v1.1.0.""" + keyvalues = [self.timestamp] + [KEYVALUE_SEP_V110.join([k, v]) + for k, v in self.keyvalue_tuple_ls] + return keyvalues + + @property + def strv110(self): + """Return header string following spec v1.1.0.""" + header_str = LINE_SEP.join(self.keyvalue_v110str_ls) + LINE_SEP + \ + LINE_TERMINATOR + return header_str + + @property + def keyvalue_v200_ls(self): + """Return KeyValue list of strings following spec v2.0.0.""" + keyvalue = [self.timestamp] + [KEYVALUE_SEP_V200.join([k, v]) + for k, v in self.keyvalue_tuple_ls] + return keyvalue + + @property + def strv200(self): + """Return header string following spec v2.0.0.""" + header_str = LINE_SEP.join(self.keyvalue_v200_ls) + LINE_SEP + \ + LINE_TERMINATOR + return header_str + + @property + def num_lines(self): + return len(self.__str__().split(LINE_SEP))
class V3BWLine(object):