def createWaves(sked, rows, waves): for row in rows: i = int(row["wave_ID"]) wave_entry = waves[i] #if verbose: print row["schedule_ID"],row["wave_ID"],row["priority"] w = Wave(i) #Plane times midnight = datetime.combine(sked.day, time(0)) start_time = midnight + wave_entry["plane_start"] end_time = midnight + wave_entry["plane_end"] w.begin = start_time w.end = end_time w.times["Plane"].begin = start_time w.times["Plane"].end = end_time #Flyer times start_time = midnight + wave_entry["flyer_start"] end_time = midnight + wave_entry["flyer_end"] w.times["Flyer"].begin = start_time w.times["Flyer"].end = end_time w.schedule = sked w.priority = float(row["priority"]) if wave_entry["student_multiple"] != None: w.studentMultiple = float(wave_entry["student_multiple"]) sked.waves[i] = w sked.findExclusiveWaves()
def play(self, musicalNote): if musicalNote == None: self.mute() else: self.wave = Wave(self.system.getFrequency(musicalNote), self.samplingRate) self.samplesToMute = None
def createWaves(self): self.waves = {} _begin = datetime.combine(self.day, self.firstBrief) + self.briefLength for i in range(1, self.waveNumber + 1): _end = _begin + self.waveLength w = Wave(i) w.begin = _begin w.end = _end w.schedule = self w.times["Flyer"].begin = _begin - self.briefLength w.times["Flyer"].end = _end + self.briefLength w.times["Plane"].begin = _begin w.times["Plane"].end = _end self.waves[i] = w _begin = _end self.findExclusiveWaves()
def generate(self): #place dock and vessel randomly in the map self.dock = np.random.rand(2) * self.env_size init_pos = np.random.rand(3) * self.env_size init_pos[2] = 0 init_vel = np.array([0, 0, 0]) init_theta = np.random.rand(3) * 2 * np.pi init_theta[0:2] = 0 init_w = np.array([0, 0, 0]) init_t = 0 self.path = Path([init_pos[:2], self.dock]) #TODO add sea state to state? self.vessel = Boat(init_pos, init_vel, init_theta, init_w, init_t) #initialize waves self.wave = Wave(1, 1, 1, 0, 0) #initialize current #TODO determine current format self.current = np.array([0, 0, 0])
def create_waves(self, sked): for i in range(1, 6): w = Wave(i) #Plane times dawn = datetime.combine(sked.date, sked.dawn) start_time = dawn + timedelta(hours=(i-1)*2.5) end_time = dawn + timedelta(hours=i*2.5) w.begin = start_time w.end = end_time w.times["Plane"].begin = start_time w.times["Plane"].end = end_time #Flyer times start_time = start_time - timedelta(hours=1) end_time = start_time - timedelta(hours=1) w.times["Flyer"].begin = start_time w.times["Flyer"].end = end_time w.schedule = sked w.priority = 1.0 sked.waves[i]=w sked.findExclusiveWaves()
def __init__(self, beatsPerMinute, beatUnit, tuningSystem, note, samplingRate=44100): self.note = note self.volume = 1 # Full colume for starters self.samplingRate = samplingRate # How many samples will I have to play? self.totalSamples = int(beatUnit * samplingRate * 60 / (note.duration * beatsPerMinute)) if self.note.times != None: self.totalSamples /= self.note.times if note.dots: self.totalSamples = int(self.totalSamples * (2.0 - pow(2, -note.dots))) self.wave = Wave(tuningSystem.getFrequency(note), samplingRate) self.counter = 0 self.volumeRate = None self.tied = False
def main(): s = Sniv() s.begin = datetime(2015, 3, 28, 8) s.end = datetime(2015, 3, 28, 9, 30) w = Wave() w.begin = datetime(2015, 3, 28, 10) w.end = datetime(2015, 3, 28, 12, 30) w.times["Flyer"].begin = datetime(2015, 3, 28, 9) w.times["Flyer"].end = datetime(2015, 3, 28, 13, 30) w.times["Plane"].begin = datetime(2015, 3, 28, 10) w.times["Plane"].end = datetime(2015, 3, 28, 12, 30) r = Flyer(1) r.snivs[0] = s print "Flyer" print r.available(date(2015, 3, 28), w) print r._available[date(2015, 3, 28)][w] print "Plane" p = Plane(1) p.snivs[0] = s print p.available(date(2015, 3, 28), w) print p._available[date(2015, 3, 28)][w]
import pygame, os from Wave import Wave, Coord os.environ["SDL_VIDEO_WINDOW_POS"] = "15,30" pygame.display.init() size = Coord(1000, 600) screen = pygame.display.set_mode(size) wave = Wave(screen, size) running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False screen.fill((0, 0, 0)) wave.update() wave.draw() pygame.display.update()
PI = np.pi sliderDataList = [{'name': 'Left amplitude', 'min': 0, 'max': 8.0, 'init': 2, 'step': 0.01}, {'name': 'Right amplitude', 'min': 0, 'max': 8.0, 'init': 2, 'step': 0.01}, {'name': 'Left period', 'min': 0.01, 'max': 8 * PI, 'init': 2 * PI, 'step': 0.01}, {'name': 'Right period', 'min': 0.01, 'max': 8 * PI, 'init': 2 * PI, 'step': 0.01}, {'name': 'Wire tension', 'min': 0.01, 'max': 8.0, 'init': 1, 'step': 0.01}, {'name': 'Wire mass density', 'min': 0.01, 'max': 8.0, 'init': 1, 'step': 0.01}, {'name': 'Simulation speed', 'min': 0.001, 'max': 2.0, 'init': 0.1, 'step': 0.001}, {'name': 'Line thickness', 'min': 1, 'max': 10, 'init': 5, 'step': 0.1}] checkboxDataList = [{'name': 'Left wave', 'init': True}, {'name': 'Right wave', 'init': True}, {'name': 'Sum wave', 'init': True}] waveList = [Wave(amplitude=2, period=2*PI, direction=1), Wave(amplitude=2, period=2*PI, direction=-1), None] class WaveSuperposition(WaveGraphBase): def __init__(self, name='Wave superposition', granularity=2048, x_range=4 * PI, x_offset=0, y_range=6, y_offset=0, time_factor=0.1, line_thickness=5, waves=[], slider_data=[], checkbox_data=[]): super().__init__(name, granularity, x_range, x_offset, y_range, y_offset, time_factor, line_thickness, waves, slider_data, checkbox_data) def update(self, event=None): self.waves[0].amplitude = self.sliders[0].val self.waves[1].amplitude = self.sliders[1].val self.waves[0].period = self.sliders[2].val self.waves[1].period = self.sliders[3].val self.waves[0].tension = self.sliders[4].val self.waves[1].tension = self.sliders[4].val
from Wave import Wave song = Wave(523.25, 5, 0.8) song.play() song.record('cnote')
def main(): config = {} execfile(sys.argv[1], config) vt = TrainingSquadron(config) vtSqlScheduler.load(vt, config) # Load csv with open(sys.argv[2]) as csvfile: reader = csv.DictReader(csvfile) con = mysql.connector.connect(host=config['host'], port=config['port'], user=config['user'], passwd=config['password'], db=config['database']) cur = con.cursor(dictionary=True) # Create validation sortie s = Sortie(instructor=Instructor(instructor_ID=11)) s.schedule_ID = 113 s.takeoff = datetime.now() s.land = datetime.now() s.brief = datetime.now() s.wave = Wave(1) for crow in reader: progressing = set() print(crow['first_name'], crow['last_name']) # Look for student in user db, return student_ID cur.execute( "SELECT user_ID FROM user WHERE last_name = %(last_name)s " "AND (middle_name = %(middle_name)s OR middle_name IS NULL) " "AND first_name = %(first_name)s " "AND title = %(title)s " "LIMIT 1", crow) row = cur.fetchone() if row is None: # Create resource entries cur.execute( "INSERT INTO resource(`created_at`, `type`, `airfield_ID`) VALUES " "(NOW(),'user',4)") student_ID = cur.lastrowid else: student_ID = row['user_ID'] student = Student(student_ID=student_ID) # Enter user information cur.execute("SELECT count(1) FROM user WHERE user_ID = %(id)s;", {'id': student_ID}) row = cur.fetchone() if row['count(1)'] == 0: crow['id'] = student_ID cur.execute( "INSERT INTO user(user_ID, last_name, first_name, middle_name, title) VALUES (" "%(id)s, %(last_name)s, %(first_name)s, %(middle_name)s, %(title)s)", crow) # Enter student information cur.execute( "SELECT count(1) FROM student WHERE student_ID = %(id)s;", {'id': student_ID}) row = cur.fetchone() if row['count(1)'] == 0: cur.execute( "INSERT INTO student(student_ID, status, training_end_date) VALUES (" "%(id)s, 'active', %(end)s)", { 'id': student_ID, 'end': crow['training_end_date'] }) cur.execute( "INSERT INTO student_syllabus(student_ID, syllabus_ID) " "VALUES (%(id)s, %(syll)s)", { 'id': student_ID, 'syll': int(crow['syllabus_ID']) }) student_syllabus_ID = cur.lastrowid else: cur.execute( "SELECT student_syllabus_ID FROM student_syllabus WHERE student_ID = %(id)s LIMIT 1;", {'id': student_ID}) row = cur.fetchone() student_syllabus_ID = row['student_syllabus_ID'] student.student_syllabus_ID = student_syllabus_ID # Create class if not there cur.execute( "SELECT count(1), organization_ID FROM organization WHERE name = %(class_name)s LIMIT 1;", {'class_name': "Class " + crow['class']}) row = cur.fetchone() if row['count(1)'] == 0: cur.execute( "INSERT INTO resource(`created_at`, `type`, `airfield_ID`) VALUES " "(NOW(),'organization',4)") class_ID = cur.lastrowid cur.execute( """INSERT INTO organization(organization_ID, name, scheduling) VALUES (%(id)s, %(class_name)s, 0)""", { 'id': class_ID, 'class_name': "Class " + crow['class'] }) cur.execute( "INSERT INTO hierarchy(parent, child) VALUES (5, %(id)s)", {'id': class_ID}) else: class_ID = row['organization_ID'] # Associate student with VT-35 cur.execute( "SELECT count(1) FROM hierarchy WHERE child = %(id)s LIMIT 1;", {'id': student_ID}) row = cur.fetchone() if row['count(1)'] == 0: cur.execute( "INSERT INTO hierarchy(parent, child) VALUES (5, %(id)s)", {'id': student_ID}) # Insert resource_tags cur.execute( "SELECT count(1) FROM resource_tag WHERE resource_ID = %(id)s LIMIT 1;", {'id': student_ID}) row = cur.fetchone() if row['count(1)'] == 0: cur.execute( """INSERT INTO resource_tag(resource_ID, tag_ID) VALUES (%(id)s, 1), (%(id)s, 2), (%(id)s, 3), (%(id)s, 4), (%(id)s, 5), (%(id)s, 7), (%(id)s, 8), (%(id)s, 9), (%(id)s, 10)""", {'id': student_ID}) """# Pull progressing events cur.execute("SELECT * FROM student_sortie " "LEFT JOIN student ON student.student_ID = student_sortie.student_ID " "LEFT JOIN hierarchy ON student.student_ID = child " "LEFT JOIN student_syllabus " "ON student_sortie.student_syllabus_ID = student_syllabus.student_syllabus_ID " "LEFT JOIN sortie ON sortie.sortie_ID = student_sortie.sortie_ID " "LEFT JOIN schedule ON schedule.schedule_ID = student_sortie.schedule_ID " "WHERE student.student_ID = %(id)s " "AND (hierarchy.stop > NOW() OR hierarchy.stop IS NULL) " "AND student_syllabus.outcome IS NULL AND student_sortie.progressing_event = 1 " "AND schedule.published = TRUE", {'id': student_ID})""" # Create student sorties for each ancestor event event = vt.events[int(crow['latest_event_ID'])] ss = StudentSortie() ss.student = student ss.event = event s.studentSorties.append(ss) for a, syllabus in vt.syllabus[int( crow['syllabus_ID'])].ancestors(event): ss = StudentSortie() ss.student = student ss.event = a s.studentSorties.append(ss) print ss for i in range(1, 4): ss = StudentSortie() ss.student = Student(student_ID=student_ID) ss.event = vt.events[i] s.studentSorties.append(ss) print ss write(s, cur) con.commit() con.close()
def on_message(self,message): print(message) # print ("message received: {}").format(message) messageHeader = message[0] # print("message header: {}").format(messageHeader) if messageHeader == "a":#done white = Color() white.setColorRBGW(255,0,0,0) eventLoop.effects.append(Wave(leds, 71, Direction.BOTH_NO_CENTER, white)) if messageHeader == "s":#done white = Color() white.setColorRBGW(0,255,255,0) eventLoop.effects.append(Wave(leds, 71, Direction.BOTH_NO_CENTER, white)) if messageHeader == "d":#done white = Color() white.setColorRBGW(255,0,255,0) eventLoop.effects.append(Wave(leds, 71, Direction.BOTH_NO_CENTER, white)) if messageHeader == "f":#done white = Color() white.setColorRBGW(255,255,0,0) eventLoop.effects.append(Wave(leds, 71, Direction.BOTH_NO_CENTER, white)) if messageHeader == "j":#done white = Color() white.setColorRBGW(0,0,255,0) eventLoop.effects.append(Wave(leds, 71, Direction.BOTH_NO_CENTER, white)) if messageHeader == "k":#done white = Color() white.setColorRBGW(255,0,0,0) eventLoop.effects.append(Wave(leds, 71, Direction.BOTH_NO_CENTER, white)) if messageHeader == "l":#done # white = Color() # white.setColorRBGW(0,255,0,0) # eventLoop.effects.append(Wave(leds, 71, Direction.BOTH_NO_CENTER, white)) hardwareController.set_hue_rotation(0) if messageHeader == ";":#done # white = Color() # white.setColorRBGW(0,0,0,0) # eventLoop.effects.append(Wave(leds, 71, Direction.BOTH_NO_CENTER, white)) hardwareController.set_hue_rotation(180) # if messageHeader == "000":#done # static(message) # if messageHeader == "100":#Enable threading # pass # if messageHeader == "200":#Still searching for a library # pass # if messageHeader == "300":#Enable threading # pass # if messageHeader == "400":#Enable threading # pass # if messageHeader == "500":#Search for a good distribution of light colors # pass # if messageHeader == "600":#search for a good distibution of random in and out clouds. # pass if message == "NumberOfLights()":#done self.write_message(str(NUM_LEDS)) else: self.write_message(str("command not understood"))
def __init__(self, pcm, data): Thread.__init__(self) self.pcm = pcm self.data = data def run(self): self.pcm.write(self.data) if __name__ == "__main__": import math import sys argc = len(sys.argv) channel = None frequencies = list() if argc == 1: print "Have to provide frequencies to play during a second each" sys.exit(1) for i in range(1, argc): frequencies.append(float(sys.argv[i])) player = WavePlayer(11025) channel = Wave(frequencies[0], 11025) for i in frequencies: sys.stderr.write("Playing frequency " + str(i) + "\n") sys.stderr.flush() channel.setFrequency(i) for j in range(0, 11025): height = channel.getNextValue() player.play(height)
self.data = data def run(self): self.pcm.write(self.data) if __name__ == "__main__": import math import sys argc = len(sys.argv) leftChannel = None rightChannel = None if argc == 1: print "Have to provide either a single frequency to play or a frequency for each channel (left channel first)" sys.exit(1) elif argc == 2: # Provided a single frequency for both channels leftChannel = Wave(float(sys.argv[1]), 11025) else: leftChannel = Wave(float(sys.argv[1]), 11025) rightChannel = Wave(float(sys.argv[2]), 11025) player = WavePlayer(11025) while True: leftHeight = leftChannel.getNextValue() if rightChannel == None: rightHeight = leftHeight else: rightHeight = rightChannel.getNextValue() player.play(leftHeight, rightHeight)
from Wave import Wave #twi-nkle twinkle_song = Wave(523.25, 1, 0.8) twinkle_song = Wave(523.25, 1, 0.8) #twi-nkle twinkle_song = Wave(783.99, 1, 0.8) twinkle_song = Wave(783.99, 1, 0.8) #lit-tle twinkle_song = Wave(880.00, 1, 0.8) twinkle_song = Wave(880.00, 1, 0.8) #star twinkle_song = Wave(783.99, 1, 0.8) #how i twinkle_song = Wave(698.46, 1, 0.8) twinkle_song = Wave(698.46, 1, 0.8) #won-der twinkle_song = Wave(659.26, 1, 0.8) twinkle_song = Wave(659.26, 1, 0.8) #what you twinkle_song = Wave(587.33, 1, 0.8) twinkle_song = Wave(587.33, 1, 0.8) #are twinkle_song = Wave(523.25, 1, 0.8) twinkle_song.play() twinkle_song.record('twinkle')