Пример #1
0
def ttv():
    """Processes and executes command paramters"""

    # Set up logging
    logging.basicConfig(filename='log.log', level=logging.INFO)

    # Load request keys
    keys = json.load(open('./keys.json'))

    # Set up Helix api
    api = Helix(user_name=keys['username'],
                client_id=keys['client_id'],
                access_token=keys['access_token'])

    # Param info (temp)
    """
    Required Parameters:
        list - Lists active streamers ranked (aplhabetically? by num viewers?), then lists non active streamers
        open [name] - Opens streamer in browser, active or not
        follow - Follow a streamer
        check - check if a specific streamer is live
    """

    # Process params
    command_length = len(sys.argv)
    command_tag = str(sys.argv[1])
    if command_length < 2:
        print("No paramters given. Showing usage")
        sys.exit(1)

    elif command_tag == "list":
        if command_length > 2:
            print("Incorrect usage of list. Showing usage")
            sys.exit(1)
        else:
            print(api.get_streams())
            sys.exit(0)

    elif command_tag == "open":
        if command_length != 3:
            print("Incorrect usage of open. Showing usage")
            sys.exit(1)
        else:
            api.open_stream(str(sys.argv[2]))
            sys.exit(0)
    elif command_tag == "check":
        if command_length != 3:
            print("Incorrect usage of check. Showing usage")
            sys.exit(1)
        else:
            status = api.check_stream(str(sys.argv[2]))
            print(status)
            sys.exit(0)
    else:
        print("Parameter not recognized")
        sys.exit(1)
Пример #2
0
    def build_scene(self):
        self.camera = Camera((0.0, -8.0, 1.0), (0,0,1.0))
        self.score = Score(0)
        self.streak = Streak(0)
        self.atcg_display = ATCGDisplay()
        self.endzone = EndZone((-1.4,0,-1.3), 2.8, 0.18)
        self.attaboy = MsgQueue()
        self.mutation = Mutation(0)
        if self.win_conditions.has_key('time'):
            self.timer = Timer(self.win_conditions['time'])	
        else:
            self.timer = None
#        speed_dif = self.level * 0.07 * (self.diff*0.8)
#        spawn_dif = self.level * 0.07 + (self.diff*0.03)

## lower down        
#        self.helix = Helix(speed = 0.7 + speed_dif, spawn_rate=0.7-spawn_dif,
#            starthgt=7, endhgt=-5, spins=2.5, pair_generator=self.pair_generator)
        if self.level >= 4:
            starthgt = 7
            endhgt = -2.5
            spins = 2.5
        else:
            starthgt = 5
            endhgt = -2.5
            spins = 1.5  

        l, d = self.level, self.diff 
        speed_dif = 0.8 + (l * 0.04 * (d*0.6))
        spawn_dif = 0.5 - (l * 0.07 * (d*0.09))

        self.helix = Helix(speed = speed_dif, spawn_rate=spawn_dif,
            starthgt=starthgt, endhgt=endhgt, spins=spins, pair_generator=self.pair_generator)
        self.helix.register_callbacks(self.enter_callback, self.exit_callback)
#        for n in range(100):
#            self.helix.update(0.1)

        
        self.attaboy.add_centered_fade("level %d\n%s\n%s" % (self.level,
            diff[self.diff], messages.EASY_LEVELS[self.level]), 0.2, 0.1)
Пример #3
0
import numpy as np
import numpy.linalg as LA
from scipy.special import erf, erfc
import nlopt
from helix import Helix
from config import *

# setup the data
N = 11
Y = Helix(radius=2, slope=1, num_points=N).coords.T
p = 3
q = 2

# initialize a set of means and standard deviations for the latent variables
latent_means = [np.random.randn(q, 1) for _ in range(N)]
latent_variances = [np.random.randn(q)**2 for _ in range(N)]
latent_Sigmas = [np.diag(var) for var in latent_variances]

ss = [-mi[-1]*si[-1] for mi, si in zip(latent_means, latent_variances)]

# set starting values for sigma2, mu, B_1, B_2, g_1, and g_2
mu = np.mean(Y, axis=1).reshape(1, -1) # the optimal value for mu is the empirical mean of the data
sigma2 = np.random.rand()       # set to random positive number
B1 = np.random.randn(p, q)
B2 = np.random.randn(p, q)

g1 = 1.
g2 = 1.

# I want the observations to be 1xp arrays for later computations
Y = [yi.reshape(1, -1) for yi in Y.T]
Пример #4
0
import time
import serial
from helix import Helix
import json
import requests
import sys

serialcomm = serial.Serial('COM5', 115200)
serialcomm.timeout = 1

keys = json.load(open('./keys.json'))

api = Helix(
        user_name = keys['username'],
        client_id = keys['client_id'],
        access_token = keys['access_token'])

while True:

    # Get list of followed streamers
    url = 'https://api.twitch.tv/helix/users/follows?from_id=' #TODO Change to get id dynamically
    # sys.exit(1)
    r = requests.get(url, headers=api.headers)
    followed = []
    for streamer in r.json()['data']:
        followed.append(streamer['to_name'])


    url2 = 'https://api.twitch.tv/helix/streams?user_login='
    for streamer in followed:
        r2 = requests.get(url=url2 + streamer, headers=api.headers)
Пример #5
0
class GameState (State):
    def __init__(self, window, level, diff, pair_generator, win_conditions, *args, **kwargs):
        print "++++ new game state"
        self.level = level
        self.diff = diff
        self.pair_generator = pair_generator
        self.win_conditions = win_conditions
        State.__init__(self, window, "game", *args, **kwargs)
        self.build_scene()
        self.current_rung = None
        self.longest_streak = 0
        self.time = 0
        self.mutation_counter = 0
        
    def build_scene(self):
        self.camera = Camera((0.0, -8.0, 1.0), (0,0,1.0))
        self.score = Score(0)
        self.streak = Streak(0)
        self.atcg_display = ATCGDisplay()
        self.endzone = EndZone((-1.4,0,-1.3), 2.8, 0.18)
        self.attaboy = MsgQueue()
        self.mutation = Mutation(0)
        if self.win_conditions.has_key('time'):
            self.timer = Timer(self.win_conditions['time'])	
        else:
            self.timer = None
#        speed_dif = self.level * 0.07 * (self.diff*0.8)
#        spawn_dif = self.level * 0.07 + (self.diff*0.03)

## lower down        
#        self.helix = Helix(speed = 0.7 + speed_dif, spawn_rate=0.7-spawn_dif,
#            starthgt=7, endhgt=-5, spins=2.5, pair_generator=self.pair_generator)
        if self.level >= 4:
            starthgt = 7
            endhgt = -2.5
            spins = 2.5
        else:
            starthgt = 5
            endhgt = -2.5
            spins = 1.5  

        l, d = self.level, self.diff 
        speed_dif = 0.8 + (l * 0.04 * (d*0.6))
        spawn_dif = 0.5 - (l * 0.07 * (d*0.09))

        self.helix = Helix(speed = speed_dif, spawn_rate=spawn_dif,
            starthgt=starthgt, endhgt=endhgt, spins=spins, pair_generator=self.pair_generator)
        self.helix.register_callbacks(self.enter_callback, self.exit_callback)
#        for n in range(100):
#            self.helix.update(0.1)

        
        self.attaboy.add_centered_fade("level %d\n%s\n%s" % (self.level,
            diff[self.diff], messages.EASY_LEVELS[self.level]), 0.2, 0.1)

    def enter_callback(self, r):
        self.current_rung = r

    def exit_callback(self, r):
        if r.get_pair_data()[0] == None or r.get_pair_data()[1] == None:
            self.bad_move()
        self.current_rung = None
        

    def destroy_scene(self):
        pass

    def on_draw(self):
        set3D(self.window)
        self.window.clear()
        glLoadIdentity()
        self.camera.focus()
        batch.get_batch().draw()
        set2D(self.window)
        return pyglet.event.EVENT_HANDLED

    def bad_move(self):
        audio.play_sound('lose_streak')
        r = self.current_rung
        if r:
            r.miss()
        self.camera.shake(1,2, 1)
        self.attaboy.add_centered_fade(messages.random_bad_move(), 0.25, 1, ([0.7,0.7,0.7,1.0], [0.1,0.1,0.1,1.0]))
        self.streak.reset()
        l, d = self.level, self.diff 
        self.helix.mutate(0.2 + (l * 0.04))
        self.mutation_counter += 5 * (self.level*0.5)
        if self.mutation_counter > 100:
            self.lose()
        self.mutation.set_mutation(self.mutation_counter)

    def good_move(self):
        audio.play_sound('hit')
        r = self.current_rung
        if r:
            r.hit()
        if self.mutation_counter > 1:
            self.mutation_counter -= 1
            self.mutation.set_mutation(self.mutation_counter)
        s = self.streak.inc()
        p = s*0.5*100
        self.attaboy.add_score_fade(p)
        self.score.inc_score(p)

    def on_key_press(self, k, args):
## =A++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++===
        if k == key.A:
            self.atcg_display.A.on()
            if check_hit('A', self.current_rung):
                self.good_move()
            else:
                self.bad_move()
## =S++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++===                
        elif k == key.S:
            self.atcg_display.T.on()
            if check_hit('T', self.current_rung):
                self.good_move()
            else:
                self.bad_move()
## =D++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=== 
        elif k == key.D:
            self.atcg_display.C.on()
            if check_hit('C', self.current_rung):
                self.good_move()
            else:
                self.bad_move()
## =F++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++===             
        elif k == key.F:
            self.atcg_display.G.on()
            if check_hit('G', self.current_rung):
                self.good_move()
            else:
                self.bad_move()
## ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=

        elif k == key.LEFT:
            pass
        elif k == key.RIGHT:
            pass
        elif k == key.ESCAPE:
            self.pause()
            return pyglet.event.EVENT_HANDLED
        elif k == key.F11:
            if self.window.fullscreen:
                self.window.set_fullscreen(False)
            else:
                self.window.set_fullscreen(True)
        return pyglet.event.EVENT_HANDLED


    def on_key_release(self, k, args):
        if k == key.A:
            self.atcg_display.A.off()
        elif k == key.S:
            self.atcg_display.T.off()
        elif k == key.D:
            self.atcg_display.C.off()
        elif k == key.F:
            self.atcg_display.G.off()
        return pyglet.event.EVENT_HANDLED

    def on_mouse_scroll(self, x, y, scroll_x, scroll_y):
        pass

    def lose(self):
        self.window.pop_state()
        self.window.replace_state(transitions.ScriptedTransition, script=script.lose, script_name="lose")

    def win(self):
        self.window.replace_state(transitions.ScriptedTransition, script=script.win, script_name="win")
        
    def on_lose_focus(self):
        pyglet.clock.unschedule(self.on_update)
        return pyglet.event.EVENT_HANDLED

    def on_gain_focus(self):
        self.helix.unobscure()
        self.helix.update(0.1)
        pyglet.clock.schedule_interval(self.on_update, 1.0/60.0)
        return pyglet.event.EVENT_HANDLED

    def check_win_conditions(self):
        if self.win_conditions.has_key('score'):
            if self.score.points > self.win_conditions['score']:
                self.win()
        elif self.win_conditions.has_key('streak'):
            if self.streak.streak >= self.win_conditions['streak']:
                self.win()
        elif self.win_conditions.has_key('time'):
            if self.timer.time < 0:
                self.win()
    
    def on_update(self, dt):
        self.camera.update(dt)
        self.attaboy.update(dt)
        self.atcg_display.update(dt)
        self.check_win_conditions()
        self.helix.update(dt)
        if self.win_conditions.has_key('time'):
            self.timer.update_time(dt)


    def pause(self):
        self.helix.obscure()
        self.helix.update(0.1)
        self.window.push_state(transitions.Pause, "game")
Пример #6
0
 def build_scene(self):
     self.attaboy = MsgQueue()
     self.menu = MainMenu()
     self.camera = Camera((3.8, -18.0, 1.0), (3.8,0,1.0))
     self.camera.subtle_motion = True
     self.helix = Helix(starthgt=5, endhgt=-2, spawn_rate=0.5)
Пример #7
0
class MainMenuState (State):
    def __init__(self, window, *args, **kwargs):
        print "++++ new pause state"
        State.__init__(self, window, "main_menu", *args, **kwargs)
        self.build_scene()
        
    def build_scene(self):
        self.attaboy = MsgQueue()
        self.menu = MainMenu()
        self.camera = Camera((3.8, -18.0, 1.0), (3.8,0,1.0))
        self.camera.subtle_motion = True
        self.helix = Helix(starthgt=5, endhgt=-2, spawn_rate=0.5)
#        for x in range(200):
#            self.helix.anima(0.1)

    def destroy_scene(self):
        pass

    def on_draw(self):
        set3D(self.window)
        self.window.clear()
        glLoadIdentity()
        self.camera.focus()
        self.batch.draw()
        set2D(self.window)
        return pyglet.event.EVENT_HANDLED

    def on_key_press(self, k, args):
        if not self.menu.on_key_press(k, args):
            return pyglet.event.EVENT_HANDLED
        if k == key.ENTER:
            if self.menu.choice == 1:
                audio.play_music_fade('chill')
                self.window.push_state(transitions.FadeOut, old_state="main_menu",
                next_state=transitions.ScriptedTransition, duration=0.453,
                next_state_args={ 'script': script.easy_levels, 'script_name': "easy"})
            elif self.menu.choice == 2:
                audio.play_music_fade('easy')
                self.window.push_state(transitions.FadeOut, old_state="main_menu",
                next_state=transitions.ScriptedTransition, duration=0.45,
                next_state_args={ 'script': script.tutorial, 'script_name': "tutorial"})
            elif self.menu.choice == 3:
                if self.window.fullscreen:
                    self.window.set_fullscreen(False)
                else:
                    self.window.set_fullscreen(True)
            elif self.menu.choice == 4:
                audio.play_music_fade('fast_groove')
                self.window.push_state(transitions.FadeOut, old_state="main_menu",
                next_state=transitions.ScriptedTransition, duration=0.45,
                next_state_args={ 'script': script.about, 'script_name': "about"})
            elif self.menu.choice == 5:
                self.window.pop_state()
                self.window.close()
            #self.window.push_state(LevelIntroState, next_state=GameState, level=1)
        elif k == key.F11:
            if self.window.fullscreen:
                self.window.set_fullscreen(False)
            else:
                self.window.set_fullscreen(True)
        elif k == key.ESCAPE:
            self.window.pop_state()
            self.window.close()
        else:
            pass
        return pyglet.event.EVENT_HANDLED
        
    def on_gain_focus(self):
        pyglet.clock.schedule_interval(self.on_update, 1.0/60.0)
        return pyglet.event.EVENT_HANDLED

    def on_lose_focus(self):
        pyglet.clock.unschedule(self.on_update)
        return pyglet.event.EVENT_HANDLED
        
    def on_update(self, dt):
        self.helix.update(dt)
        self.menu.update(dt)
        self.camera.update(dt)
        self.attaboy.update(dt)