From 04413d20fb6cb5f0ff21fb36607fc5621bb9ae14 Mon Sep 17 00:00:00 2001 From: ivelin Date: Wed, 10 Feb 2021 06:05:31 +0000 Subject: [PATCH] chore: fix linter warnings --- .theia/settings.json | 5 ++- src/ambianic/pipeline/ai/fall_detect.py | 42 +++++++++++++++---------- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/.theia/settings.json b/.theia/settings.json index be05b336..fcd0d775 100644 --- a/.theia/settings.json +++ b/.theia/settings.json @@ -5,5 +5,8 @@ "python.testing.unittestEnabled": false, "python.testing.nosetestsEnabled": false, "python.testing.pytestEnabled": true, - "editor.autoSave": "on" + "editor.autoSave": "on", + "python.linting.enabled": true, + "python.linting.pylintEnabled": false, + "python.linting.pylamaEnabled": true } \ No newline at end of file diff --git a/src/ambianic/pipeline/ai/fall_detect.py b/src/ambianic/pipeline/ai/fall_detect.py index 7acf4b07..70083eb2 100755 --- a/src/ambianic/pipeline/ai/fall_detect.py +++ b/src/ambianic/pipeline/ai/fall_detect.py @@ -1,7 +1,6 @@ """Fall detection pipe element.""" from ambianic.pipeline.ai.tf_detect import TFDetectionModel from ambianic.pipeline.ai.pose_engine import PoseEngine -from ambianic.util import stacktrace import logging import math import time @@ -9,6 +8,7 @@ log = logging.getLogger(__name__) + class FallDetector(TFDetectionModel): """Detects falls comparing two images spaced about 1-2 seconds apart.""" @@ -28,7 +28,9 @@ def __init__(self, 'ai_models/posenet_mobilenet_v1_075_721_1281_quant_decoder_edgetpu.tflite' } """ - super().__init__(model=model, confidence_threshold=confidence_threshold, **kwargs) + super().__init__(model=model, + confidence_threshold=confidence_threshold, + **kwargs) # previous pose detection information for frame at time t-1 and t-2 \ # to compare pose changes against @@ -60,11 +62,14 @@ def __init__(self, log.debug(f"Initializing FallDetector with conficence threshold: {self.confidence_threshold}") # Require a minimum amount of time between two video frames in seconds. - # Otherwise on high performing hard, the poses could be too close to each other and have negligible difference + # Otherwise on high performing hard, the poses could be too close to + # each other and have negligible difference # for fall detection purpose. self.min_time_between_frames = 1 - # Require the time distance between two video frames not to exceed a certain limit in seconds. - # Otherwise there could be data noise which could lead false positive detections. + # Require the time distance between two video frames not to exceed + # a certain limit in seconds. + # Otherwise there could be data noise which could lead + # false positive detections. self.max_time_between_frames = 10 # keypoint lookup constants @@ -73,7 +78,8 @@ def __init__(self, self.RIGHT_SHOULDER = 'right shoulder' self.RIGHT_HIP = 'right hip' - self.fall_detect_corr = [self.LEFT_SHOULDER, self.LEFT_HIP, self.RIGHT_SHOULDER, self.RIGHT_HIP] + self.fall_detect_corr = [self.LEFT_SHOULDER, self.LEFT_HIP, + self.RIGHT_SHOULDER, self.RIGHT_HIP] def process_sample(self, **sample): """Detect objects in sample image.""" @@ -98,14 +104,14 @@ def process_sample(self, **sample): yield processed_sample except Exception as e: log.exception('Error "%s" while processing sample. ' - 'Dropping sample: %s', + 'Dropping sample: %s', str(e), str(sample) ) def calculate_angle(self, p): ''' - Calculate angle b/w two lines such as + Calculate angle b/w two lines such as left shoulder-hip with prev frame's left shoulder-hip or right shoulder-hip with prev frame's right shoulder-hip or shoulder-hip line with vertical axis @@ -113,25 +119,29 @@ def calculate_angle(self, p): x1, y1 = p[0][0] x2, y2 = p[0][1] - + x3, y3 = p[1][0] x4, y4 = p[1][1] theta1 = math.degrees(math.atan2(y2-y1, x1-x2)) theta2 = math.degrees(math.atan2(y4-y3, x3-x4)) - + angle = abs(theta1-theta2) return angle - def is_body_line_motion_downward(self, left_angle_with_yaxis, - rigth_angle_with_yaxis, inx): + def is_body_line_motion_downward(self, left_angle_with_yaxis, + rigth_angle_with_yaxis, inx): test = False - l_angle = left_angle_with_yaxis and self._prev_data[inx][self.LEFT_ANGLE_WITH_YAXIS] \ - and left_angle_with_yaxis > self._prev_data[inx][self.LEFT_ANGLE_WITH_YAXIS] - r_angle = rigth_angle_with_yaxis and self._prev_data[inx][self.RIGHT_ANGLE_WITH_YAXIS] \ - and rigth_angle_with_yaxis > self._prev_data[inx][self.RIGHT_ANGLE_WITH_YAXIS] + l_angle = left_angle_with_yaxis and \ + self._prev_data[inx][self.LEFT_ANGLE_WITH_YAXIS] \ + and left_angle_with_yaxis > \ + self._prev_data[inx][self.LEFT_ANGLE_WITH_YAXIS] + r_angle = rigth_angle_with_yaxis and \ + self._prev_data[inx][self.RIGHT_ANGLE_WITH_YAXIS] \ + and rigth_angle_with_yaxis > \ + self._prev_data[inx][self.RIGHT_ANGLE_WITH_YAXIS] if l_angle or r_angle: test = True