def runCPU():
 model = ModelFactory.create(model_params.MODEL_PARAMS)
 model.enableInference({'predictedField': 'cpu'})
 shifter = InferenceShifter()
 actHistory = deque(([0.0] * WINDOW), maxlen=60)
 predHistory = deque(([0.0] * WINDOW), maxlen=60)
 (actline,) = plt.plot(range(WINDOW), actHistory)
 (predline,) = plt.plot(range(WINDOW), predHistory)
 actline.axes.set_ylim(0, 100)
 predline.axes.set_ylim(0, 100)
 while True:
  s = time.time()
  cpu = psutil.cpu_percent()
  modelInput = {'cpu': cpu}
  result = shifter.shift(model.run(modelInput))
  inference = result.inferences['multiStepBestPredictions'][5]
  if (inference is not None):
   actHistory.append(result.rawInput['cpu'])
   predHistory.append(inference)
  actline.set_ydata(actHistory)
  predline.set_ydata(predHistory)
  plt.draw()
  plt.legend(('actual', 'predicted'))
  try:
   plt.pause(SECONDS_PER_STEP)
  except:
   pass

def runCPU ( ) : model = ModelFactory . create ( model_params . MODEL_PARAMS ) model . enableInference ( { 'predictedField' : 'cpu' } ) shifter = InferenceShifter ( ) actHistory = deque ( ( [ 0.0 ] * WINDOW ) , maxlen = 60 ) predHistory = deque ( ( [ 0.0 ] * WINDOW ) , maxlen = 60 ) ( actline , ) = plt . plot ( range ( WINDOW ) , actHistory ) ( predline , ) = plt . plot ( range ( WINDOW ) , predHistory ) actline . axes . set_ylim ( 0 , 100 ) predline . axes . set_ylim ( 0 , 100 ) while True : s = time . time ( ) cpu = psutil . cpu_percent ( ) modelInput = { 'cpu' : cpu } result = shifter . shift ( model . run ( modelInput ) ) inference = result . inferences [ 'multiStepBestPredictions' ] [ 5 ] if ( inference is not None ) : actHistory . append ( result . rawInput [ 'cpu' ] ) predHistory . append ( inference ) actline . set_ydata ( actHistory ) predline . set_ydata ( predHistory ) plt . draw ( ) plt . legend ( ( 'actual' , 'predicted' ) ) try : plt . pause ( SECONDS_PER_STEP ) except : pass
poll cpu usage .