예제 #1
0
def classify(classiFile):
    global previousFile
    if (previousFile == "none"):
        previousFile = classiFile
        FolderWatch.FolderWatch(CLASSIFY_FOLDER, classify)
    else:

        #print("classifying: " + previousFile)

        dataFile = pd.read_csv(previousFile, header=0)

        try:
            print("trying...")
            dataFile = analyzer.normalize(dataFile)
            dataFile = analyzer.autoCorrelate(dataFile)
            #is already being autocorrelated by getBPM
            autoanalyzer = DataAnalyzer.AutoAnalyzer(dataFile)
            output = autoanalyzer.getLastPeakTime()
            detectedBPM = output['bpm']
            time = output['time']

            row = []
            for secondData in training_data:
                row.append(analyzer.DTWSimilarity(dataFile, secondData))

            print("Classify: \t", str(model.predict([row])), ", BPM: ",
                  str(detectedBPM), ", time: ", str(time))
        except:
            print('raising exception')
            pass

        os.remove(previousFile)
        previousFile = classiFile
        FolderWatch.FolderWatch(CLASSIFY_FOLDER, classify)
예제 #2
0
def classify(classiFile):
  global previousFile
  if (previousFile == "none"):
    previousFile = classiFile
    FolderWatch.FolderWatch(CLASSIFY_FOLDER, classify)
  else:
    
    #print("classifying: " + previousFile)
    try:
      dataFile = pd.read_csv(previousFile, header=0)
    except:
      print("[EXCEPTION] cant read previous file")
      pass

    try:
      print("Classificating...")
      dataFile = analyzer.normalize(dataFile)
      dataFile = analyzer.autoCorrelate(dataFile)
      #is already being autocorrelated by getBPM
      autoanalyzer = DataAnalyzer.AutoAnalyzer(dataFile)
      output = autoanalyzer.getLastPeakTime() #calculates where the first occuring peak is in the file
      detectedBPM = output['bpm']
      time = output['time']
      peakIndex = output['index'] #index number of the peak in the file
      endPeakIndex = output['endPeriodIndex']

      periodData = autoanalyzer.getPeriodsFromDataIndex(1, peakIndex)['data'] #get one period of data starting from peak index.

      row = []
      for secondData in training_data: # calculate the DTW Similarity between the sample and all items in the training dataset.
        row.append(analyzer.DTWSimilarity(periodData, secondData)) 

      gesture = model.predict([row])[0] #predict the gesture with KNN using the calculated distance matrix

      # if BPM is larger than 200, you know for sure it isn't a movement. Temporary 'knutseloplossing'
      if detectedBPM > 200:
        gesture = "rest"

      print("Classify: \t", str(gesture), ", BPM: ", str(detectedBPM), ", time: ", str(time))  
      socket.sendClassify(str(gesture), detectedBPM, time) #send back the classified gesture through the socket.
      dataFile[peakIndex:endPeakIndex].to_csv(CLASSIFY_SAVE_FOLDER + str(gesture) + "-" + str(detectedBPM) + "-" + str(time) + ".csv")

    except:
      print('[EXCEPTION] during classification')
      pass

    try:
      os.remove(previousFile)
    except:
      print("[EXCEPTION] cant delete previous file")
      pass
    previousFile = classiFile
    FolderWatch.FolderWatch(CLASSIFY_FOLDER, classify)
예제 #3
0
def classify(classiFile):
    global previousFile
    if (previousFile == "none"):
        previousFile = classiFile
        FolderWatch.FolderWatch(CLASSIFY_FOLDER, classify)
    else:

        #print("classifying: " + previousFile)
        try:
            dataFile = pd.read_csv(previousFile, header=0)
        except:
            print("[EXCEPTION] cant read previous file")
            pass

        try:
            print("Classificating...")
            dataFile = analyzer.normalize(dataFile)
            dataFile = analyzer.autoCorrelate(dataFile)
            #is already being autocorrelated by getBPM
            autoanalyzer = DataAnalyzer.AutoAnalyzer(dataFile)
            output = autoanalyzer.getLastPeakTime()
            detectedBPM = output['bpm']
            time = output['time']

            periodData = autoanalyzer.getPeriods(1, startIndexPeriod=1)['data']

            row = []
            for secondData in training_data:
                row.append(analyzer.DTWSimilarity(periodData, secondData))

            gesture = model.predict([row])[0]

            #knutseloplossing
            if detectedBPM > 200:
                gesture = "rest"

            print("Classify: \t", str(gesture), ", BPM: ", str(detectedBPM),
                  ", time: ", str(time))

            socket.sendClassify(str(gesture), detectedBPM, time)
            print("tried to send...")

        except:
            print('[EXCEPTION] during classification')
            pass

        try:
            os.remove(previousFile)
        except:
            print("[EXCEPTION] cant delete previous file")
            pass
        previousFile = classiFile
        FolderWatch.FolderWatch(CLASSIFY_FOLDER, classify)
예제 #4
0
def classify(classiFile):
    global previousFile
    if (previousFile == "none"):
        previousFile = classiFile
        FolderWatch.FolderWatch(CLASSIFY_FOLDER, classify)
    else:
        print("classifying: " + previousFile)

        dataFile = pd.read_csv(previousFile, header=0)
        data = [dataFile['accX'], dataFile['accY'], dataFile['accZ']]
        data = normalize(np.ravel(data))
        print("Guess: " + str(clf1.predict(data)))

        os.remove(previousFile)
        previousFile = classiFile
        FolderWatch.FolderWatch(CLASSIFY_FOLDER, classify)
예제 #5
0
      row = []
      for secondData in training_data: # calculate the DTW Similarity between the sample and all items in the training dataset.
        row.append(analyzer.DTWSimilarity(periodData, secondData)) 

      gesture = model.predict([row])[0] #predict the gesture with KNN using the calculated distance matrix

      # if BPM is larger than 200, you know for sure it isn't a movement. Temporary 'knutseloplossing'
      if detectedBPM > 200:
        gesture = "rest"

      print("Classify: \t", str(gesture), ", BPM: ", str(detectedBPM), ", time: ", str(time))  
      socket.sendClassify(str(gesture), detectedBPM, time) #send back the classified gesture through the socket.
      dataFile[peakIndex:endPeakIndex].to_csv(CLASSIFY_SAVE_FOLDER + str(gesture) + "-" + str(detectedBPM) + "-" + str(time) + ".csv")

    except:
      print('[EXCEPTION] during classification')
      pass

    try:
      os.remove(previousFile)
    except:
      print("[EXCEPTION] cant delete previous file")
      pass
    previousFile = classiFile
    FolderWatch.FolderWatch(CLASSIFY_FOLDER, classify)


#sort of while loop; when done classifying, watch the folder again!
FolderWatch.FolderWatch(CLASSIFY_FOLDER, classify)