Esempio n. 1
0
 def load(self, nspikes=100, nsamples=20, nclusters=5, nchannels=32):
     
     self.holder = DataHolder()
     
     self.holder.waveforms = rdn.randn(nspikes, nsamples, nchannels)
     self.holder.waveforms_info = Info(nsamples=nsamples)
     
     fetdim = 3
     # TODO
     # self.holder.features = rdn.randn(nspikes, nchannels, fetdim)
     self.holder.features = rdn.randn(nspikes, nchannels * fetdim + 1)
     
     self.holder.masks = rdn.rand(nspikes, nchannels)
     self.holder.masks[self.holder.masks < .25] = 0
     
     self.holder.clusters = rdn.randint(low=0, high=nclusters, size=nspikes)
     self.holder.clusters_info = Info(
         colors=np.array(colors.generate_colors(nclusters),
                                 dtype=np.float32))
                                 
     self.holder.probe = Info(positions=np.loadtxt("data/buzsaki32.txt"))
     
     # cross correlograms
     nsamples_correlograms = 20
     self.holder.correlograms = rdn.rand(nclusters * (nclusters + 1) / 2,
         nsamples_correlograms)
     self.holder.correlograms_info = Info(nsamples=nsamples_correlograms)
     
     self.holder.correlationmatrix = rdn.rand(nclusters, nclusters) ** 10
     
     
     return self.holder
Esempio n. 2
0
def track_move(move_serial, move_num, team, num_teams, dead_move, force_color,
               music_speed, show_team_colors, invincibility):
    #proc = psutil.Process(os.getpid())
    #proc.nice(3)
    #explosion = Audio('audio/Joust/sounds/Explosion34.wav')
    #explosion.start_effect()
    start = False
    no_rumble = time.time() + 1
    move_last_value = None
    move = common.get_move(move_serial, move_num)
    team_colors = colors.generate_colors(num_teams)
    vibrate = False
    vibration_time = time.time() + 1
    flash_lights = True
    flash_lights_timer = 0
    start_inv = False
    change_arr = [0, 0, 0]

    #keep on looping while move is not dead
    while True:
        if show_team_colors.value == 1:
            if team.value != -1:
                move.set_leds(*team_colors[team.value])
            else:
                move.set_leds(100, 100, 100)
            move.update_leds()
        elif sum(force_color) != 0:
            no_rumble_time = time.time() + 5
            time.sleep(0.01)
            move.set_leds(*force_color)
            if sum(force_color) == 30:
                move.set_leds(0, 0, 0)
            move.set_rumble(0)
            move.update_leds()
            no_rumble = time.time() + 0.5
        elif dead_move.value == 1 and team.value != -1:
            if move.poll():
                ax, ay, az = move.get_accelerometer_frame(
                    psmove.Frame_SecondHalf)
                #total = sum([ax, ay, az])
                total = sqrt(sum([ax**2, ay**2, az**2]))
                if move_last_value is not None:
                    change_real = abs(move_last_value - total)
                    change_arr[0] = change_arr[1]
                    change_arr[1] = change_arr[2]
                    change_arr[2] = change_real
                    change = (change_arr[0] + change_arr[1] +
                              change_arr[2]) / 3
                    speed_percent = (music_speed.value - SLOW_MUSIC_SPEED) / (
                        FAST_MUSIC_SPEED - SLOW_MUSIC_SPEED)
                    warning = common.lerp(SLOW_WARNING, FAST_WARNING,
                                          speed_percent)
                    threshold = common.lerp(SLOW_MAX, FAST_MAX, speed_percent)
                    if not start_inv and invincibility.value == 1:
                        start_inv = True
                        vibrate = True
                        vibration_time = time.time() + 3

                    if vibrate:
                        flash_lights_timer += 1
                        if flash_lights_timer > 7:
                            flash_lights_timer = 0
                            flash_lights = not flash_lights
                        if flash_lights:
                            move.set_leds(100, 100, 100)
                        else:
                            if team.value != -1:
                                move.set_leds(*team_colors[team.value])
                            else:
                                move.set_leds(100, 100, 100)
                        if time.time() < vibration_time - 0.22:
                            move.set_rumble(110)
                        else:
                            move.set_rumble(0)
                        if time.time() > vibration_time:
                            vibrate = False
                            start_inv = False
                            invincibility.value = 0
                    else:
                        if team.value != -1:
                            move.set_leds(*team_colors[team.value])
                        else:
                            move.set_leds(100, 100, 100)

                    if invincibility.value == 0:
                        if change > threshold:
                            if time.time() > no_rumble:
                                move.set_leds(0, 0, 0)
                                move.set_rumble(90)
                                dead_move.value = 0

                        elif change > warning and not vibrate:
                            if time.time() > no_rumble:
                                vibrate = True
                                vibration_time = time.time() + 0.5
                                move.set_leds(20, 50, 100)

                move_last_value = total
            move.update_leds()
        else:
            if dead_move.value < 1:
                move.set_leds(0, 0, 0)
            elif team.value == -1:
                move.set_leds(100, 100, 100)
            move.update_leds()

            time.sleep(0.5)
            move.set_rumble(0)
Esempio n. 3
0
def track_move(move_serial, move_num, team, num_teams, dead_move, force_color,
               music_speed, commander_intro, move_opts, power, overdrive):
    #proc = psutil.Process(os.getpid())
    #proc.nice(3)

    start = False
    no_rumble = time.time() + 1
    move_last_value = None
    move = common.get_move(move_serial, move_num)
    team_colors = colors.generate_colors(num_teams)
    #keep on looping while move is not dead
    ready = False
    move.set_leds(0, 0, 0)
    move.update_leds()
    time.sleep(1)
    vibrate = False
    vibration_time = time.time() + 1
    flash_lights = True
    flash_lights_timer = 0
    change_arr = [0, 0, 0]

    death_time = 8
    time_of_death = time.time()

    while commander_intro.value == 1:
        if move.poll():
            button = common.Button(move.get_buttons())
            if button == common.Button.MIDDLE and move_opts[
                    Opts.holding.value] == Holding.not_holding.value:

                move_opts[Opts.selection.value] = Selections.a_button.value
                move_opts[Opts.holding.value] = Holding.holding.value
            elif button == common.Button.TRIANGLE and move_opts[
                    Opts.holding.value] == Holding.not_holding.value:

                move_opts[Opts.selection.value] = Selections.triangle.value
                move_opts[Opts.holding.value] = Holding.holding.value

            elif move_opts[
                    Opts.is_commander.value] == Bool.no.value and move_opts[
                        Opts.holding.value] == Holding.holding.value:
                move.set_leds(200, 200, 200)

            elif move_opts[
                    Opts.is_commander.value] == Bool.yes.value and move_opts[
                        Opts.holding.value] == Holding.holding.value:
                move.set_leds(*Current_commander_colors[team])
            else:
                move.set_leds(*Commander_colors[team])
        move.update_leds()

    move_opts[Opts.holding.value] = Holding.not_holding.value
    move_opts[Opts.selection.value] = Selections.nothing.value

    while True:
        if sum(force_color) != 0:
            no_rumble_time = time.time() + 5
            time.sleep(0.01)
            move.set_leds(*force_color)
            move.update_leds()
            move.set_rumble(0)
            no_rumble = time.time() + 0.5
        #if we are not dead
        elif dead_move.value == 1:
            if move.poll():
                ax, ay, az = move.get_accelerometer_frame(
                    psmove.Frame_SecondHalf)
                #total = sum([ax, ay, az])
                total = sqrt(sum([ax**2, ay**2, az**2]))
                if move_last_value is not None:
                    change_real = abs(move_last_value - total)
                    change_arr[0] = change_arr[1]
                    change_arr[1] = change_arr[2]
                    change_arr[2] = change_real
                    change = (change_arr[0] + change_arr[1] +
                              change_arr[2]) / 3

                    if move_opts[Opts.is_commander.value] == Bool.no.value:
                        if overdrive.value == 0:
                            warning = SLOW_WARNING
                            threshold = SLOW_MAX
                        else:
                            warning = FAST_WARNING
                            threshold = FAST_MAX
                    else:
                        #if affected by overdrive, this could make the power better
                        warning = SLOW_WARNING
                        threshold = SLOW_MAX

                    if change > threshold:
                        if time.time() > no_rumble:
                            move.set_leds(0, 0, 0)
                            move.set_rumble(90)
                            dead_move.value = 0
                            time_of_death = time.time()

                    elif change > warning and not vibrate:
                        if time.time() > no_rumble:
                            move.set_leds(20, 50, 100)
                            vibrate = True
                            vibration_time = time.time() + 0.5

                    else:
                        if move_opts[Opts.is_commander.value] == Bool.no.value:
                            if overdrive.value == 0:
                                move.set_leds(*Commander_colors[team])
                            else:
                                move.set_leds(*Overdrive_colors[team])
                        else:
                            move.set_leds(*calculate_flash_time(
                                Current_commander_colors[team][0],
                                Current_commander_colors[team][1],
                                Current_commander_colors[team][2],
                                power.value))
                        move.set_rumble(0)

                    if move_opts[Opts.is_commander.value] == Bool.yes.value:
                        if (move.get_buttons() == 0
                                and move.get_trigger() < 10):
                            move_opts[
                                Opts.holding.value] = Holding.not_holding.value

                        button = move.get_buttons()
                        #print str(power.value)
                        if power.value >= 1.0:
                            #press trigger for overdrive
                            if (move_opts[Opts.holding.value]
                                    == Holding.not_holding.value
                                    and move.get_trigger() > 100):
                                move_opts[Opts.selection.
                                          value] = Selections.trigger.value
                                move_opts[
                                    Opts.holding.value] = Holding.holding.value

                move_last_value = total
                if vibrate:
                    flash_lights_timer += 1
                    if flash_lights_timer > 7:
                        flash_lights_timer = 0
                        flash_lights = not flash_lights
                    if flash_lights:
                        move.set_leds(100, 100, 100)
                    if time.time() < vibration_time - 0.22:
                        move.set_rumble(110)
                    else:
                        move.set_rumble(0)
                    if time.time() > vibration_time:
                        vibrate = False
            move.update_leds()
        #if we are dead
        elif dead_move.value <= 0:
            if time.time() - time_of_death >= death_time:
                dead_move.value = 3
        elif dead_move.value == 3:
            move_last_value = None
            dead_move.value = 1
            no_rumble = time.time() + 2
            if death_time < 25:
                death_time += 2
Esempio n. 4
0
def track_move(move, team, dead_move, force_color, music_speed,
               commander_intro, move_opts, commander_powers,
               commander_overdrive, restart, menu, controller_sensitivity):
    if team == Team.alpha.value:
        overdrive = commander_overdrive[0]
        power = commander_powers[0]
    else:
        overdrive = commander_overdrive[1]
        power = commander_powers[1]

    start = False
    no_rumble = time.time() + 1
    move_last_value = None
    team_colors = colors.generate_colors(2)
    #keep on looping while move is not dead
    ready = False
    move.set_leds(0, 0, 0)
    move.update_leds()
    time.sleep(1)
    vibrate = False
    vibration_time = time.time() + 1
    flash_lights = True
    flash_lights_timer = 0
    change = 0
    #change_arr = [0,0,0]

    SLOW_MAX = controller_sensitivity[0]
    SLOW_WARNING = controller_sensitivity[1]
    FAST_MAX = controller_sensitivity[2]
    FAST_WARNING = controller_sensitivity[3]

    death_time = 8
    time_of_death = time.time()

    while commander_intro.value == 1:
        if move.poll():
            button = common.Button(move.get_buttons())
            if button == common.Button.MIDDLE and move_opts[
                    Opts.holding.value] == Holding.not_holding.value:

                move_opts[Opts.selection.value] = Selections.a_button.value
                move_opts[Opts.holding.value] = Holding.holding.value
            elif button == common.Button.TRIANGLE and move_opts[
                    Opts.holding.value] == Holding.not_holding.value:

                move_opts[Opts.selection.value] = Selections.triangle.value
                move_opts[Opts.holding.value] = Holding.holding.value

            elif move_opts[
                    Opts.is_commander.value] == Bool.no.value and move_opts[
                        Opts.holding.value] == Holding.holding.value:
                move.set_leds(200, 200, 200)

            elif move_opts[
                    Opts.is_commander.value] == Bool.yes.value and move_opts[
                        Opts.holding.value] == Holding.holding.value:
                move.set_leds(*Current_commander_colors[team])
            else:
                move.set_leds(*Commander_colors[team])
        move.update_leds()

    move_opts[Opts.holding.value] = Holding.not_holding.value
    move_opts[Opts.selection.value] = Selections.nothing.value

    while True:
        if (restart.value == 1 or menu.value == 1):
            return
        if sum(force_color) != 0:
            no_rumble_time = time.time() + 5
            time.sleep(0.01)
            move.set_leds(*force_color)
            move.update_leds()
            move.set_rumble(0)
            no_rumble = time.time() + 0.5
        #if we are not dead
        elif dead_move.value == 1:
            if move.poll():
                ax, ay, az = move.get_accelerometer_frame(
                    psmove.Frame_SecondHalf)
                total = sqrt(sum([ax**2, ay**2, az**2]))
                change = (change * 4 + total) / 5

                if move_opts[Opts.is_commander.value] == Bool.no.value:
                    if overdrive.value == 0:
                        warning = SLOW_WARNING
                        threshold = SLOW_MAX
                    else:
                        warning = FAST_WARNING
                        threshold = FAST_MAX
                else:
                    #if affected by overdrive, this could make the power better
                    warning = SLOW_WARNING
                    threshold = SLOW_MAX

                if change > threshold:
                    if time.time() > no_rumble:
                        move.set_leds(0, 0, 0)
                        move.set_rumble(90)
                        dead_move.value = 0
                        time_of_death = time.time()

                elif change > warning and not vibrate:
                    if time.time() > no_rumble:
                        move.set_leds(20, 50, 100)
                        vibrate = True
                        vibration_time = time.time() + 0.5

                else:
                    if move_opts[Opts.is_commander.value] == Bool.no.value:
                        if overdrive.value == 0:
                            move.set_leds(*Commander_colors[team])
                        else:
                            move.set_leds(*Overdrive_colors[team])
                    else:
                        move.set_leds(*calculate_flash_time(
                            Current_commander_colors[team][0],
                            Current_commander_colors[team][1],
                            Current_commander_colors[team][2], power.value))
                    move.set_rumble(0)

                if move_opts[Opts.is_commander.value] == Bool.yes.value:
                    if (move.get_buttons() == 0 and move.get_trigger() < 10):
                        move_opts[
                            Opts.holding.value] = Holding.not_holding.value

                    button = move.get_buttons()
                    #print str(power.value)
                    if power.value >= 1.0:
                        #press trigger for overdrive
                        if (move_opts[Opts.holding.value]
                                == Holding.not_holding.value
                                and move.get_trigger() > 100):
                            move_opts[Opts.selection.
                                      value] = Selections.trigger.value
                            move_opts[
                                Opts.holding.value] = Holding.holding.value

                #move_last_value = total
                if vibrate:
                    flash_lights_timer += 1
                    if flash_lights_timer > 7:
                        flash_lights_timer = 0
                        flash_lights = not flash_lights
                    if flash_lights:
                        move.set_leds(100, 100, 100)
                    if time.time() < vibration_time - 0.22:
                        move.set_rumble(110)
                    else:
                        move.set_rumble(0)
                    if time.time() > vibration_time:
                        vibrate = False
            move.update_leds()
        #if we are dead
        elif dead_move.value <= 0:
            if time.time() - time_of_death >= death_time:
                dead_move.value = 3
        elif dead_move.value == 3:
            move_last_value = None
            dead_move.value = 1
            no_rumble = time.time() + 2
            if death_time < 25:
                death_time += 2
Esempio n. 5
0
def track_move(move, team, num_teams, dead_move, force_color, music_speed, show_team_colors, invincibility, menu, restart, controller_sensitivity):
    start = False
    no_rumble = time.time() + 1
    move_last_value = None
    team_colors = colors.generate_colors(num_teams)
    vibrate = False
    vibration_time = time.time() + 1
    flash_lights = True
    flash_lights_timer = 0
    start_inv = False
    change_arr = [0,0,0]
    change = 0
    
    SLOW_MAX = controller_sensitivity[0]
    SLOW_WARNING = controller_sensitivity[1]
    FAST_MAX = controller_sensitivity[2]
    FAST_WARNING = controller_sensitivity[3]

    #keep on looping while move is not dead
    while True:
        if(menu.value == 1 or restart.value == 1):
            return
        if show_team_colors.value == 1:
            if team.value != -1:
                move.set_leds(*team_colors[team.value])
            else:
                move.set_leds(100,100,100)
            move.update_leds()
        elif sum(force_color) != 0:
            no_rumble_time = time.time() + 5
            time.sleep(0.01)
            move.set_leds(*force_color)
            if sum(force_color) == 30:
                move.set_leds(0, 0, 0)
            move.set_rumble(0)
            move.update_leds()
            no_rumble = time.time() + 0.5
        elif dead_move.value == 1 and team.value != -1:   
            if move.poll():
                ax, ay, az = move.get_accelerometer_frame(psmove.Frame_SecondHalf)
                total = sqrt(sum([ax**2, ay**2, az**2]))
                change = (change * 4 + total)/5

                speed_percent = (music_speed.value - SLOW_MUSIC_SPEED)/(FAST_MUSIC_SPEED - SLOW_MUSIC_SPEED)
                warning = common.lerp(SLOW_WARNING, FAST_WARNING, speed_percent)
                threshold = common.lerp(SLOW_MAX, FAST_MAX, speed_percent)
                if not start_inv and invincibility.value == 1:
                    start_inv = True
                    vibrate = True
                    vibration_time = time.time() + 3
                    

                if vibrate:
                    flash_lights_timer += 1
                    if flash_lights_timer > 7:
                        flash_lights_timer = 0
                        flash_lights = not flash_lights
                    if flash_lights:
                        move.set_leds(100,100,100)
                    else:
                        if team.value != -1:
                            move.set_leds(*team_colors[team.value])
                        else:
                            move.set_leds(100,100,100)
                    if time.time() < vibration_time - 0.22:
                        move.set_rumble(110)
                    else:
                        move.set_rumble(0)
                    if time.time() > vibration_time:
                        vibrate = False
                        start_inv = False
                        invincibility.value = 0
                else:
                    if team.value != -1:
                        move.set_leds(*team_colors[team.value])
                    else:
                        move.set_leds(100,100,100)
                        
                if invincibility.value == 0:
                    if change > threshold:
                        if time.time() > no_rumble:
                            move.set_leds(0,0,0)
                            move.set_rumble(90)
                            dead_move.value = 0

                    elif change > warning and not vibrate:
                        if time.time() > no_rumble:
                            vibrate = True
                            vibration_time = time.time() + 0.5
                            move.set_leds(20,50,100)

            move.update_leds()
        else:
            if dead_move.value < 1:
                move.set_leds(0,0,0)
            elif team.value == -1:
                move.set_leds(100,100,100)
            move.update_leds()
                
            time.sleep(0.5)
            move.set_rumble(0)
Esempio n. 6
0
def get_colors():
    post_body = json.loads(request.data)
    image = post_body.get('image')
    colors = vis.generate_colors(image)
    return json.dumps({'success': True, 'data': colors}), 200