Skip to content

Commit

Permalink
Merge pull request #266 from powerapi-ng/refactor/fix-pylint-protecte…
Browse files Browse the repository at this point in the history
…d-access

refactor: Fix pylint `protected-access` warnings
  • Loading branch information
gfieni authored Mar 6, 2024
2 parents b9563cc + af7f9b3 commit 88ffe08
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
1 change: 0 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ disable=raw-checker-failed,
dangerous-default-value,
invalid-overridden-method,
abstract-method,
protected-access,
broad-exception-caught

# Enable the message, report, category or checker with the given id(s). You can
Expand Down
13 changes: 7 additions & 6 deletions src/powerapi/report/power_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,11 @@ def to_virtiofs_db(report: PowerReport) -> Tuple[str, str]:
power = report.power
return filename, power

def _gen_tag(self, metadata_kept):
tags = {'sensor': self.sensor,
'target': self.target
}
def gen_tag(self, metadata_kept):
"""
Generate the tags list of the report.
"""
tags = {'sensor': self.sensor, 'target': self.target}

for metadata_name in metadata_kept:
if metadata_name not in self.metadata:
Expand All @@ -170,7 +171,7 @@ def to_influxdb(report: PowerReport, tags: List[str]) -> Dict:
"""
return {
'measurement': 'power_consumption',
'tags': report._gen_tag(tags),
'tags': report.gen_tag(tags),
'time': str(report.timestamp),
'fields': {
'power': report.power
Expand All @@ -183,7 +184,7 @@ def to_prometheus(report: PowerReport, tags: List[str]) -> Dict:
:return: a dictionary, that can be stored into a prometheus instance, from a given PowerReport
"""
return {
'tags': report._gen_tag(tags),
'tags': report.gen_tag(tags),
'time': int(report.timestamp.timestamp()),
'value': report.power
}
Expand Down
15 changes: 7 additions & 8 deletions src/powerapi/utils/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ def aux(node, depth):
aux(self, 1)

def retrieve_leaf_values(self, path):
"""retrieves all leafs value under the node designating by path
"""
Retrieves all leafs value under the node designating by path
:param path:
:type path: list
:rtype: list : list of leafs value
Expand All @@ -186,26 +186,25 @@ def aux(node, depth):
return []
# if the current node is a leaf return its value
if depth == (len(path) - 1):
return node._get_leafs()
return node.get_leafs()

# go down in all child nodes
return reduce(lambda acc, child: acc + aux(child, depth + 1), node.childs, [])
return aux(self, 0)

def _get_leafs(self):
def get_leafs(self):
"""
Retrives all leafs under this node
Retrieves all leafs under this node.
"""
if self.is_leaf:
return [self.val]
# concat all leafs value of the node's childs
return reduce(lambda acc, child: acc + child._get_leafs(), self.childs,
[])
return reduce(lambda acc, child: acc + child.get_leafs(), self.childs, [])

def __eq__(self, other):
if not isinstance(other, Node):
return False
if (self.label != other.label or self.val != other.val or self.is_leaf != other.is_leaf):
if self.label != other.label or self.val != other.val or self.is_leaf != other.is_leaf:
return False
sorted_child = deepcopy(self.childs)
sorted_child.sort(key=lambda node: node.label)
Expand Down

0 comments on commit 88ffe08

Please sign in to comment.