Skip to content

Commit

Permalink
flake8
Browse files Browse the repository at this point in the history
  • Loading branch information
Richardvdketterij committed Jan 16, 2024
1 parent b12bbda commit fe86d0f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@
import socket
import psutil

from rclpy.node import Node
from diagnostic_msgs.msg import DiagnosticStatus
from diagnostic_updater import DiagnosticTask, Updater
from rclpy.node import Node


class CpuTask(DiagnosticTask):
Expand All @@ -56,7 +56,8 @@ def _get_average_reading(self):
def avg(lst):
return float(sum(lst)) / len(lst) if lst else float('nan')

return [avg(cpu_percentages) for cpu_percentages in zip(*self._readings)]
return [avg(cpu_percentages)
for cpu_percentages in zip(*self._readings)]

def run(self, stat):
self._readings.append(psutil.cpu_percent(percpu=True))
Expand All @@ -75,7 +76,8 @@ def run(self, stat):
stat.summary(DiagnosticStatus.WARN,
"At least one CPU exceeds {:d} percent".format(self._warning_percentage))
else:
stat.summary(DiagnosticStatus.OK, "CPU Average {:.2f} percent".format(cpu_average))
stat.summary(DiagnosticStatus.OK,
"CPU Average {:.2f} percent".format(cpu_average))

return stat

Expand All @@ -91,7 +93,8 @@ def main(args=None):
node.declare_parameter('warning_percentage', 90)
node.declare_parameter('window', 1)

warning_percentage = node.get_parameter('warning_percentage').get_parameter_value().integer_value
warning_percentage = node.get_parameter(
'warning_percentage').get_parameter_value().integer_value
window = node.get_parameter('window').get_parameter_value().integer_value

# Create diagnostic updater with default updater rate of 1 hz
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,17 @@
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

import unittest
import time
import rclpy
import unittest

from rclpy.node import Node
from diagnostic_msgs.msg import DiagnosticStatus
from diagnostic_updater import DiagnosticStatusWrapper
from diagnostic_updater import DiagnosticArray, Updater
from diagnostic_updater import DiagnosticStatusWrapper

import rclpy
from rclpy.node import Node
from diagnostic_common_diagnostics.cpu_monitor import CpuTask
import time


class TestCPUMonitor(unittest.TestCase):
@classmethod
Expand Down Expand Up @@ -101,7 +102,8 @@ def test_updater(self):
updater.setHardwareID("test_id")
updater.add(CpuTask())

node.create_subscription(DiagnosticArray, '/diagnostics', self.diagnostics_callback, 10)
node.create_subscription(
DiagnosticArray, '/diagnostics', self.diagnostics_callback, 10)

start_time = time.time()
timeout = 5.0 # Timeout in seconds
Expand Down

0 comments on commit fe86d0f

Please sign in to comment.