]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/diskprediction_local: add to flake8
authorKefu Chai <kchai@redhat.com>
Fri, 19 Feb 2021 15:45:06 +0000 (23:45 +0800)
committerKefu Chai <kchai@redhat.com>
Sat, 20 Feb 2021 06:36:53 +0000 (14:36 +0800)
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/pybind/mgr/diskprediction_local/__init__.py
src/pybind/mgr/diskprediction_local/module.py
src/pybind/mgr/diskprediction_local/predictor.py
src/pybind/mgr/tox.ini

index 8f210ac9247ea49624b20582ca8206e56055fbcd..ee85dc9d376e61235d719cf25585769bd07299a6 100644 (file)
@@ -1 +1,2 @@
+# flake8: noqa
 from .module import Module
index 948c59bd7edf0a3090b61df6327e0143da80d89e..7c2bdbcef38ab1508b3382259e8ba48978207029 100644 (file)
@@ -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'])
index 548454145cea94c5b890db09c3c41279cecdd90d..fbea9dc94989ff5b9cd866b2eec653b127e3fbd8 100644 (file)
@@ -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)
index c554de29f89075626919bbbcaf6ef4b81b4bd794..6cba2b7510d8bec61ec48fa777f2d57c020cf96e 100644 (file)
@@ -118,6 +118,7 @@ modules =
     alerts
     balancer
     cephadm
+    diskprediction_local
     crash
     devicehealth
     hello