def runIoThroughNupic(inputData, model, gymName, plot):
 inputFile = open(inputData, 'rb')
 csvReader = csv.reader(inputFile)
 csvReader.next()
 csvReader.next()
 csvReader.next()
 shifter = InferenceShifter()
 if plot:
  output = nupic_anomaly_output.NuPICPlotOutput(gymName)
 else:
  output = nupic_anomaly_output.NuPICFileOutput(gymName)
 counter = 0
 for row in csvReader:
  counter += 1
  if ((counter % 100) == 0):
   print ('Read %i lines...' % counter)
  timestamp = datetime.datetime.strptime(row[0], DATE_FORMAT)
  consumption = float(row[1])
  result = model.run({'timestamp': timestamp, 'kw_energy_consumption': consumption})
  if plot:
   result = shifter.shift(result)
  prediction = result.inferences['multiStepBestPredictions'][1]
  anomalyScore = result.inferences['anomalyScore']
  output.write(timestamp, consumption, prediction, anomalyScore)
 inputFile.close()
 output.close()

def runIoThroughNupic ( inputData , model , gymName , plot ) : inputFile = open ( inputData , 'rb' ) csvReader = csv . reader ( inputFile ) csvReader . next ( ) csvReader . next ( ) csvReader . next ( ) shifter = InferenceShifter ( ) if plot : output = nupic_anomaly_output . NuPICPlotOutput ( gymName ) else : output = nupic_anomaly_output . NuPICFileOutput ( gymName ) counter = 0 for row in csvReader : counter += 1 if ( ( counter % 100 ) == 0 ) : print ( 'Read %i lines...' % counter ) timestamp = datetime . datetime . strptime ( row [ 0 ] , DATE_FORMAT ) consumption = float ( row [ 1 ] ) result = model . run ( { 'timestamp' : timestamp , 'kw_energy_consumption' : consumption } ) if plot : result = shifter . shift ( result ) prediction = result . inferences [ 'multiStepBestPredictions' ] [ 1 ] anomalyScore = result . inferences [ 'anomalyScore' ] output . write ( timestamp , consumption , prediction , anomalyScore ) inputFile . close ( ) output . close ( )
handles looping over the input data and passing each row into the given model object .