<commit_before>from liblo import ServerThread, ServerError, make_method

import sys

import time


class MuseServer(ServerThread):

    # listen for messages on port 5001

    def __init__(self):

        ServerThread.__init__(self, 5001)

    # receive accelrometer data
    @make_method('/muse/acc', 'fff')
    def acc_callback(self, path, args):

        acc_x, acc_y, acc_z = args

        print ("%s %f %f %f" % (path, acc_x, acc_y, acc_z))

    # receive EEG data
    @make_method('/muse/eeg', 'ffff')
    def eeg_callback(self, path, args):

        l_ear, l_forehead, r_forehead, r_ear = args

        print ("%s %f %f %f %f" % (path, l_ear, l_forehead, r_forehead, r_ear))

    # handle unexpected messages
    @make_method(None, None)
    def fallback(self, path, args, types, src):
        pass
        # print ("Unknown message \
        # \n\t Source: '%s' \
        # \n\t Address: '%s' \
        # \n\t Types: '%s ' \
        # \n\t Payload: '%s'" \
        # % (src.url, path, types, args))

try:
    server = MuseServer()

except ServerError as err:

    print(str(err))

    sys.exit()

server.start()


if __name__ == "__main__":

    while 1:
        time.sleep(1)<commit_msg>Extracting BPM from head movement<commit_after>from liblo import ServerThread, ServerError, make_method

import sys
import time

import threading as th
from copy import deepcopy

import numpy as np
from numpy.fft import fft

acc_lock = th.Lock()
acc_list = []


class MuseServer(ServerThread):

    # listen for messages on port 5001

    def __init__(self):

        ServerThread.__init__(self, 5001)

    # receive accelrometer data
    @make_method('/muse/acc', 'fff')
    def acc_callback(self, path, args):
        global acc_list

        acc_lock.acquire()
        acc_list.append(args)
        acc_lock.release()

        acc_x, acc_y, acc_z = args

        #print ("%s %f %f %f" % (path, acc_x, acc_y, acc_z))

    # # receive blink data
    # @make_method('/muse/elements/blink', 'i')
    # def blink_callback(self, path, args):

    #     blink, = args

    #     print ("%s %i" % (path, blink))

    # # receive blink data
    # @make_method('/muse/elements/jaw_clench', 'i')
    # def jaw_callback(self, path, args):

    #     jaw, = args

    #     print ("%s %i" % (path, jaw))

    # handle unexpected messages
    @make_method(None, None)
    def fallback(self, path, args, types, src):
        pass
        # print ("Unknown message \
        # \n\t Source: '%s' \
        # \n\t Address: '%s' \
        # \n\t Types: '%s ' \
        # \n\t Payload: '%s'" \
        # % (src.url, path, types, args))

try:
    server = MuseServer()

except ServerError as err:

    print(str(err))

    sys.exit()

server.start()


if __name__ == "__main__":
    t = 5

    while 1:
        acc_lock.acquire()
        tmp = list(zip(*acc_list))
        acc_list = []
        acc_lock.release()

        if tmp:
            size = len(tmp[0])
            fs = [i / t for i in range(size // 2)]
            tmp = [np.array(x) - sum(x) / len(x) for x in tmp]
            acc_fft = [fft(x)[: size // 2] for x in tmp]
            imax = [sorted(enumerate(x), key=lambda k: abs(k[1]))[-1] for x in acc_fft]
            print(fs[imax[0][0]], fs[imax[0][0]] * 60)

        time.sleep(t)
{'fraction_non_alphanumeric': 0.14316239316239315, 'fraction_numerical': 0.009462759462759462, 'mean_word_length': 2.2445544554455448, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4952735', 'n_tokens_mistral': 1199, 'n_tokens_neox': 1142, 'n_words': 313}