From 43a79aff9c8aec27ac6922c8f531ce931a998782 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Fri, 19 Feb 2021 23:45:06 +0800 Subject: [PATCH] mgr/diskprediction_local: add to flake8 Signed-off-by: Kefu Chai --- .../mgr/diskprediction_local/__init__.py | 1 + src/pybind/mgr/diskprediction_local/module.py | 7 +++---- .../mgr/diskprediction_local/predictor.py | 18 ++++++++---------- src/pybind/mgr/tox.ini | 1 + 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/pybind/mgr/diskprediction_local/__init__.py b/src/pybind/mgr/diskprediction_local/__init__.py index 8f210ac9247..ee85dc9d376 100644 --- a/src/pybind/mgr/diskprediction_local/__init__.py +++ b/src/pybind/mgr/diskprediction_local/__init__.py @@ -1 +1,2 @@ +# flake8: noqa from .module import Module diff --git a/src/pybind/mgr/diskprediction_local/module.py b/src/pybind/mgr/diskprediction_local/module.py index 948c59bd7ed..7c2bdbcef38 100644 --- a/src/pybind/mgr/diskprediction_local/module.py +++ b/src/pybind/mgr/diskprediction_local/module.py @@ -3,7 +3,6 @@ diskprediction with local predictor """ import json import datetime -import _strptime from threading import Event import time @@ -15,11 +14,11 @@ from mgr_module import MgrModule, CommandResult # from .predictor import get_diskfailurepredictor_path # # in a command thread. See https://tracker.ceph.com/issues/42764 -import scipy +import scipy # noqa: ignore=F401 TIME_FORMAT = '%Y%m%d-%H%M%S' -TIME_DAYS = 24*60*60 +TIME_DAYS = 24 * 60 * 60 TIME_WEEK = TIME_DAYS * 7 @@ -194,7 +193,7 @@ class Module(MgrModule): # get normalized smart values if attr.get('value') is not None: dev_smart['smart_%s_normalized' % attr.get('id')] = \ - attr.get('value') + attr.get('value') # add power on hours manually if not available in smart attributes if s_val.get('power_on_time', {}).get('hours') is not None: dev_smart['smart_9_raw'] = int(s_val['power_on_time']['hours']) diff --git a/src/pybind/mgr/diskprediction_local/predictor.py b/src/pybind/mgr/diskprediction_local/predictor.py index 548454145ce..fbea9dc9498 100644 --- a/src/pybind/mgr/diskprediction_local/predictor.py +++ b/src/pybind/mgr/diskprediction_local/predictor.py @@ -27,7 +27,6 @@ import pickle import logging import numpy as np -from scipy import stats def get_diskfailurepredictor_path(): @@ -113,7 +112,7 @@ class RHDiskFailurePredictor(object): # get the attributes that were used to train model for current manufacturer try: model_smart_attr = self.model_context[manufacturer] - except KeyError as e: + except KeyError: RHDiskFailurePredictor.LOGGER.debug( "No context (SMART attributes on which model has been trained) found for manufacturer: {}".format( manufacturer @@ -127,7 +126,7 @@ class RHDiskFailurePredictor(object): struc_dtypes = [(attr, np.float64) for attr in model_smart_attr] values = [tuple(day[attr] for attr in model_smart_attr) for day in disk_days] disk_days_sa = np.array(values, dtype=struc_dtypes) - except KeyError as e: + except KeyError: RHDiskFailurePredictor.LOGGER.debug( "Mismatch in SMART attributes used to train model and SMART attributes available" ) @@ -136,7 +135,7 @@ class RHDiskFailurePredictor(object): # view structured array as 2d array for applying rolling window transforms # do not include capacity_bytes in this. only use smart_attrs disk_days_attrs = disk_days_sa[[attr for attr in model_smart_attr if 'smart_' in attr]]\ - .view(np.float64).reshape(disk_days_sa.shape + (-1,)) + .view(np.float64).reshape(disk_days_sa.shape + (-1,)) # featurize n (6 to 12) days data - mean,std,coefficient of variation # current model is trained on 6 days of data because that is what will be @@ -146,20 +145,19 @@ class RHDiskFailurePredictor(object): roll_window_size = 6 # rolling means generator - gen = (disk_days_attrs[i: i + roll_window_size, ...].mean(axis=0) \ - for i in range(0, disk_days_attrs.shape[0] - roll_window_size + 1)) + gen = (disk_days_attrs[i: i + roll_window_size, ...].mean(axis=0) + for i in range(0, disk_days_attrs.shape[0] - roll_window_size + 1)) means = np.vstack(gen) # rolling stds generator - gen = (disk_days_attrs[i: i + roll_window_size, ...].std(axis=0, ddof=1) \ - for i in range(0, disk_days_attrs.shape[0] - roll_window_size + 1)) + gen = (disk_days_attrs[i: i + roll_window_size, ...].std(axis=0, ddof=1) + for i in range(0, disk_days_attrs.shape[0] - roll_window_size + 1)) stds = np.vstack(gen) # coefficient of variation cvs = stds / means cvs[np.isnan(cvs)] = 0 - featurized = np.hstack(( - means, + featurized = np.hstack((means, stds, cvs, disk_days_sa['user_capacity'][: disk_days_attrs.shape[0] - roll_window_size + 1].reshape(-1, 1) diff --git a/src/pybind/mgr/tox.ini b/src/pybind/mgr/tox.ini index c554de29f89..6cba2b7510d 100644 --- a/src/pybind/mgr/tox.ini +++ b/src/pybind/mgr/tox.ini @@ -118,6 +118,7 @@ modules = alerts balancer cephadm + diskprediction_local crash devicehealth hello -- 2.47.3