class Deaerator: st_i = Stream() st_o = Stream() st_o.quality = 0 def __init__(self, pressure): self.pressure = pressure
def main(): if len(sys.argv) != 2: eprint("Error:", "Missing source file name!", sep=" ") exit(1) stream = Stream(sys.argv[1]) stream.parse_file()
def main(): def max_of_std(lst, state): a = np.array(lst) state = max(a.std(), state) return (state, state) print "example_1" print "example function from list to value: mean_and_sigma() " window_size = 10 step_size = 10 print "window_size = ", window_size print "step_size = ", step_size print "" x = Stream('x') # x is the in_stream. # sum() is the function on the window z = stream_func(x, f_type='window', f=max_of_std, num_outputs=1, state=0.0, window_size=window_size, step_size=step_size) z.set_name('z') x.extend([random.random() for i in range(30)]) x.print_recent() z.print_recent()
def run_templater(inputFile, outputDir, tmpF): templateFile = open(tmpF).read() env = jinja2.Environment() env.globals.update(sorted=sorted, to_snake=to_snake_case) template = env.from_string(templateFile) s = Stream(inputFile, 'Letter') # Dirty counter for well-formedness wf = 0 bf = 0 for key, item in s.stream(): templatedText = template.render(item) f = open(outputDir+key+".xml", 'w') f.write(templatedText) f.close() # A dirty checker for wellformedness try: ET.fromstring(templatedText) wf += 1 except Exception as e: print(key, " is BAD:: ", e) bf += 1 print('GOOD: ', wf) print('BAD: ', bf)
def __init__(self, A=545, w=5.76, v_min=1.1, v_max=2.9): self.n = self.n + 1 self.A = A self.w = w self.v_min = v_min self.v_max = v_max self.rho = 0.94 # Reflectance of the collector self.shading = 1 # Shading factor of the collector self.tau = 0.95 # Transmissivity of trough receiver self.alpha = 0.96 # Absorptivity of the absorber selective # coating of trough collector self.Fe = 0.97 # Soiling factor of the trough collector self.d_i = 0.066 # Inner diameter of the absorber, m self.d_o = 0.07 # Outer diameter of the absorber, m self.phi = np.deg2rad(70) # Incidence angle, rad self.f = 0 # Focal length, m self.len = 0 # Length of the collector, m self.tc_type = None # type of the collector self.gamma = 0.93 # Intercept factor of the collector self.n_in_a_row = 0 self.st_i = Stream() self.st_i.fluid = Const.FLUID[3] self.st_o = Stream() self.st_o.fluid = Const.FLUID[3] self.amb = Ambient() self.v = 0 # Actual average oil speed in the trough collector
def main(): def copy(list_of_in_lists, state): return ([in_list.list[in_list.start:in_list.stop] for in_list in list_of_in_lists], state, [in_list.stop for in_list in list_of_in_lists]) input_stream_0 = Stream('input_stream_0', num_in_memory=32) input_stream_1 = Stream('input_stream_1', num_in_memory=32 ) output_stream_0 = Stream('output_stream_0', num_in_memory=32) output_stream_1 = Stream('output_stream_1', num_in_memory=32) A = Agent(in_streams=[input_stream_0, input_stream_1 ], out_streams=[output_stream_0, output_stream_1], transition=copy, name='A') input_stream_0.extend(range(10)) assert(output_stream_0.stop == 10) assert(output_stream_1.stop == 0) assert(output_stream_0.recent[:10] == range(10)) assert(input_stream_0.start == {A:10}) assert(input_stream_1.start == {A:0}) input_stream_1.extend(range(10, 25, 1)) assert(output_stream_0.stop == 10) assert(output_stream_1.stop == 15) assert(output_stream_0.recent[:10] == range(10)) assert(output_stream_1.recent[:15] == range(10, 25, 1)) assert(input_stream_0.start == {A:10}) assert(input_stream_1.start == {A:15})
def getValuesFromFile(self): stream = Stream(self.filePath, self.column, sheet="ID") for k, v in stream.stream(): #print(k) if k != 'None' and v["DATE"] < self.date: yield str(k) + '.0'
def main(): def mean_of_window(stream): def mean(lst, state): sum_window, next_value_dropped = state if sum_window is None: sum_window = sum(lst) else: sum_window = sum_window + lst[-1] - next_value_dropped mean = sum_window/len(lst) next_value_dropped = lst[0] state = (sum_window, next_value_dropped) return (mean, state) return stream_func( inputs=stream, f_type='window', f=mean, num_outputs=1, state=(None, None), window_size=2, step_size=2) def max_of_std(lst, state): a = np.array(lst).std() if a > state: state = a return (a, state) else: return (_no_value, state) x = Stream('x') # x is the input stream. g = partial(stream_func, f_type='window', f=max_of_std, num_outputs=1, state=0.0, window_size=10, step_size=10) y = g(x) z = g(y) means = mean_of_window(x) y.set_name('y') z.set_name('z') means.set_name('means') x.extend([random.random() for i in range(30)]) x.print_recent() y.print_recent() z.print_recent() means.print_recent()
def create_stream(self, position): stream = Stream(color=randint(0, 3)) self.streams.append(stream) self.add_widget(stream) self.bind(on_ignore_touch=stream.on_ignore_touch) self.bind(on_acknowledge_touch=stream.on_acknowledge_touch) self.bind(on_mouse_state_changed=stream.on_mouse_state_changed) stream.head_position = (position[0], position[1]) stream.active = True stream.ignore_touch = False
def test(): x = Stream('x') y,z = exp_smooth_max_and_std_of_windows_in_stream(x) y.set_name('y') z.set_name('z') check(y, [1.6000000000000001, 4.3200000000000003]) check(z, [0.65319726474218087, 0.78383671769061702]) x.extend([1, 2, 3, 4, 5]) x.print_recent() y.print_recent() z.print_recent() print x.extend([6, 12, 13, 14, 15]) x.print_recent() y.print_recent() z.print_recent() print check_empty()
def test(): x = Stream('x') y,z = max_min_of_windows_in_stream(x) y.set_name('y') z.set_name('z') check(y, [5]) check(z, [3]) x.extend([3,5]) x.print_recent() y.print_recent() z.print_recent() print x.extend([11,15]) x.print_recent() y.print_recent() z.print_recent() print check_empty()
def main(): # Functions: list -> list def square(lst): return [v*v for v in lst] def double(lst): return [2*v for v in lst] def even(lst): return [v for v in lst if not v%2] # Functions: stream -> stream. # Each element of the output stream is f() applied to the corresponding # element of the input stream. stream_square = partial(stream_func, f_type='list', f=square, num_outputs=1) stream_double = partial(stream_func, f_type='list', f=double, num_outputs=1) stream_even = partial(stream_func, f_type='list', f=even, num_outputs=1) # Create stream x, and give it name 'x'. x = Stream('input') # u is the stream returned by stream_square(x) and # v is the stream returned by stream_double(x) # w is the stream returned by stream_square(v) and # so w could have been defined as: # stream_square(stream_double(x)) # a is the stream containing only even values of x u = stream_square(x) v = stream_double(x) w = stream_square(v) a = stream_even(x) # Give names to streams u, v, and w. This is helpful in reading output. u.set_name('square of input') v.set_name('double of input') w.set_name('square of double of input') a.set_name('even values in input') print print 'add [3, 5] to the tail of the input stream' # Add values to the tail of stream x. x.extend([3, 5]) # Print the N most recent values of streams x, u, v, w. x.print_recent() u.print_recent() v.print_recent() w.print_recent() a.print_recent() print print 'add [2, 6] to the tail of the input stream' # Add more values to the tail of stream x. x.extend([2, 6]) # Print the N most recent values of streams x, u, v, w. x.print_recent() u.print_recent() v.print_recent() w.print_recent() a.print_recent()
def main(): # Functions: list -> list of lists def even_odd(list_of_integers): evens_list = [n for n in list_of_integers if not n%2] odds_list = [n for n in list_of_integers if n%2] return (evens_list, odds_list) # Functions: stream -> stream. # The n-th element of the output stream is f() applied to the n-th # elements of each of the input streams. # Function mean is defined above, and functions sum and max are the # standard Python functions. stream_even_odd = partial(stream_func, f_type='list', f=even_odd, num_outputs=2) # Create stream x, and give it name 'x'. x = Stream('input_0') # u is the stream returned by stream_sum([x,y]) and # v is the stream returned by stream_max([x,y]) # w is the stream returned by stream_mean([x,y]). # u[i] = sum(x[i],y[i]) # v[i] = max(x[i],y[i]) # w[i] = mean(x[i],y[i]) evens, odds = stream_even_odd(x) # Give names to streams u, v, and w. This is helpful in reading output. evens.set_name('even numbers in x') odds.set_name('odd numbers in x') print print 'Adding [3, 5, 8] to input stream' # Add values to the tail of stream x. x.extend([3, 5, 8]) # Print recent values of the streams print 'recent values of input streams' x.print_recent() print 'recent values of output streams' evens.print_recent() odds.print_recent() print print 'Adding [4, 6, 2, 1] to the input stream' # Add more values to the tail of stream x. x.extend([4, 6, 2, 1]) # Print recent values of the streams print 'recent values of input streams' x.print_recent() print 'recent values of output streams' evens.print_recent() odds.print_recent()
class Filter: def __init__(self, inputFilePath, outputFilePath): self.inclusionList = [] self.exclusionList = [] self.stream = Stream(inputFilePath, 'Letter') self.new_shelve_file = outputFilePath def inclusionListAdd(self, filterList): self.inclusionList += filterList() def exclusionListAdd(self, filterList): self.exclusionList += filterList() def filter(self): print(len(self.inclusionList)) with ShelveManager(self.new_shelve_file) as new_shelf: for index, fields in self.stream.stream(): #print(str(index)+'.0', str(index)+'.0' in self.inclusionList) if str(index) + '.0' in self.inclusionList and str( index) + '.0' not in self.exclusionList: print('Filtering letter, included ,', index) new_shelf[index] = self._get_fields(fields) else: print('Filtering letter, removed ,', index) @editLogger('Filtered from Completed List', 'PythonScript') def _get_fields(self, fields): return fields
class Filter: def __init__(self, inputFilePath, outputFilePath): self.inclusionList = [] self.exclusionList = [] self.stream = Stream(inputFilePath, 'Letter') self.new_shelve_file = outputFilePath def inclusionListAdd(self, filterList): self.inclusionList += filterList() def exclusionListAdd(self, filterList): self.exclusionList += filterList() def filter(self): with ShelveManager(self.new_shelve_file) as new_shelf: for index, fields in self.stream.stream(): #print(str(index)) if str(index)+'.0' in self.inclusionList and str(index)+'.0' not in self.exclusionList: new_shelf[index] = self._get_fields(fields) @editLogger('Filtered from Completed List', 'PythonScript') def _get_fields(self, fields): return fields
def start(self, users): #users is a list of dictionary type objects # dict type objects from getConfig() print "Starting..." #start Twitter stream streamThreads = [] streamBuffers = [] for user in users: sr = Stream(user['con_key'], user['con_secret'], user['key'], user['secret'], user['name']) #insert user list into db list = sr.getUserList(self.parseLists(user['lists'])) self.sql.insert_into_userList(list, user['db']) track = [] for keyword in user['track'].split(','): track.append(keyword) #get buffer and run stream buff = sr.getTweetsBuffer() # if list is not None or track is not None: # stream = sr.run(list, track) # else: # stream = sr.run(None) stream = sr.run(list, track) #add new buff and stream to list streamBuffers.append({'buff':buff, 'db':user['db']}) streamThreads.append(stream) print "Started user: "******"Started user: "******"Exiting..." os._exit(0)
def main(): b, a = butter_bandpass(lowcut=0.1, highcut=5.0, fs=50, order=5) y = np.zeros(len(a)-1) state = (b, a, y) filename = '20110111000000.2D.OBS34.SXZ.npy' data_array = np.load(filename) print 'len(data_array)', len(data_array) data_array = data_array[:1000000] x = Stream('x') print 'a', a print 'b', b y = stream_func(x, f_type='window', f=linear_filter, num_outputs=1, state=state, window_size=len(b), step_size=1) x.extend(data_array) y.set_name('y') plt.plot(y.recent[5000:y.stop]) plt.show() plt.close()
def get(self): current_time = datetime.datetime.now() all_streams = Stream.query() for stream in all_streams: for date in stream.view_queue: minback = current_time - datetime.timedelta(hours=1) if date < minback: stream.view_queue.remove(date) stream.views = stream.views - 1 stream.put()
def __init__(self,config): self.config = config # Commands self.execute['list'] = self.list # list supported commands self.execute['status'] = self.get_status # send status self.execute['restart_machine'] = self.restart # restart machine self.execute['poweroff_machine'] = self.poweroff # self.execute['update'] = self.update # download files from github if( config.enable('CAMERA') ) : self.execute['photo'] = self.photo # take a photo self.execute['tweet'] = self.tweet # take a photo, send a tweet if( config.enable('SOUND') ) : self.execute['beep'] = self.beep # play beep.wav if( config.enable('RELAY') ) : self.execute['relay'] = self.relay # trigger RelayEn if(config.enable('MOTION') and config.enable('CAMERA')) : self.execute['start_tweet'] = self.start_motion_tweet # tweet triggered by MotionEn self.execute['stop_tweet'] = self.stop_motion_tweet self.execute['start_alarm'] = self.start_motion_alarm # alarm triggered by MotionEn self.execute['stop_alarm'] = self.stop_motion_alarm if( config.enable('SERVO') ): self.execute['pos_ventana'] = self.pos_ventana self.execute['pos_adentro'] = self.pos_adentro logging.info('Supported commads:') for k in self.execute: logging.info('\t%s'%k) # Common resources self.sem = threading.BoundedSemaphore(value=1) if( Config.IS_RPI and config.enable('CAMERA') ): self.Camera = picamera.PiCamera() self.Stream = Stream(self.Camera,self.config) self.Stream.run() else: self.Camera = None self.Stream = None if( config.enable('DISPLAY') ) : self.Display = Display( pin_rs=7, pin_e=8, pins_db=[25,24,23,18] ) else: self.Display = None
def test(): # Create stream x, and give it name 'x'. x = Stream('input_0') # u is the stream returned by stream_sum([x,y]) and # v is the stream returned by stream_max([x,y]) # w is the stream returned by stream_mean([x,y]). # u[i] = sum(x[i],y[i]) # v[i] = max(x[i],y[i]) # w[i] = mean(x[i],y[i]) evens, odds = stream_even_odd(x) # Give names to streams u, v, and w. This is helpful in reading output. evens.set_name('even numbers in x') odds.set_name('odd numbers in x') check(evens, [8, 4, 6, 2]) check(odds, [3,5]) print print 'Adding [3, 5, 8], [1, 7, 2], [2, 3] to 3 input streams' # Add values to the tail of stream x. x.extend([3, 5, 8]) # Print recent values of the streams print 'recent values of input streams' x.print_recent() print 'recent values of output streams' evens.print_recent() odds.print_recent() print print 'Adding [4, 6, 2], [2, 3, 8], [5, 3, 0, -1] to 3 input streams' # Add more values to the tail of stream x. x.extend([4, 6, 2]) # Print recent values of the streams print 'recent values of input streams' x.print_recent() print 'recent values of output streams' evens.print_recent() odds.print_recent() check_empty()
def test(): # Create stream x, and give it name 'x'. x = Stream('input_0') id_0_average, id_1_average = stream_split_by_sensor_id(x) # Give names to streams u, v, and w. This is helpful in reading output. id_0_average.set_name('average of id_0 sensors in x') id_1_average.set_name('average of id_1 sensors in x') check(id_0_average, [2.0, 3.0, 5.0, 4.0, 4.0]) check(id_1_average, [5.0, 3.0, 3.0, 4.0, 5.0, 6.0]) print print 'Adding ([(0,2), (0,4), (1,5), (1,1), (0,9)]' print 'to the input stream.' # Add values to the tail of stream x. x.extend([(0,2), (0,4), (1,5), (1,1), (0,9)]) # Print recent values of the streams print print 'recent values of input streams' x.print_recent() print print 'recent values of output streams' id_0_average.print_recent() id_1_average.print_recent() print print print 'Adding ([(1,3), (1,7), (0,1), (1,9), (1,11), (0,4)])' print 'to the input stream.' # Add values to the tail of stream x. x.extend([(1,3), (1,7), (0,1), (1,9), (1,11), (0,4)]) # Print recent values of the streams print 'recent values of input streams' print x.print_recent() print 'recent values of output streams' print id_0_average.print_recent() id_1_average.print_recent() check_empty()
def main(): x = Stream('x') fs=250 b, a = butter_bandpass( lowcut=4, highcut=10, fs=fs, order=5) # Create sine wave with frequency of 8 num_cycles = 4 hertz_1 = 8 hertz_2 = 16 time = 0.25 wavelength = 0.1 t = np.linspace(0, 20, 5000) z_1 = np.sin(2*np.pi*hertz_1*t) z_2 = 0.5*np.sin(2*np.pi*hertz_2*t) z_3 = z_1+z_2 #print 't_1', t_1 #print 'z', z #x.extend(z) plt.plot(z_1[4000:]) #plt.title('input') plt.show() plt.close() plt.plot(z_2[4000:]) #plt.title('input') plt.show() plt.close() plt.plot(z_3[4000:]) #plt.title('input') plt.show() plt.close() y = filter(b, a, input_stream=x) x.extend(z_3) plt.plot(y.recent[4000:y.stop]) plt.title('output') plt.show() plt.close()
def main(): def single_stream_of_random_numbers(trigger_stream): def ran(): return random.random() return stream_func( inputs=None, f_type='element', f=ran, num_outputs=1, call_streams=[trigger_stream]) def stream_of_normal_and_pareto(clock_stream, b): from scipy.stats import norm, pareto def normal_and_pareto(): return [norm.rvs(size=1)[0], pareto.rvs(b, size=1)[0]] return stream_func( inputs=None, f_type='element', f=normal_and_pareto, num_outputs=2, call_streams=[clock_stream] ) trigger = Stream('trigger') r = single_stream_of_random_numbers( trigger_stream=trigger) u, v = stream_of_normal_and_pareto( clock_stream=trigger, b=2.62171653214) r.set_name('random') u.set_name('normal') v.set_name('pareto') trigger.extend(['tick', 'tick']) trigger.print_recent() r.print_recent() u.print_recent() v.print_recent()
def get(self): #Get the list of streams images = {'stream_names': [], 'image_urls': []} streams = Stream.query().order(-Stream.date_last_added) for stream in streams: images['stream_names'].append(stream.name) images['image_urls'].append(stream.cover_image) image_json = json.dumps(images,indent=4, separators=(',', ': ')) self.response.write(image_json)
def get(self): #Get the list of streams images = {'stream_names': [], 'image_urls': []} streams = Stream.query().order(-Stream.date_last_added) for stream in streams: images['stream_names'].append(stream.name) images['image_urls'].append(stream.cover_image) image_json = json.dumps(images, indent=4, separators=(',', ': ')) self.response.write(image_json)
def test(): in_1 = Stream(name='in_1') out_1 = Stream(name='out_1') out_2 = Stream(name= 'out_2') check(out_1, [4, 8]) check(out_2, [3, 5]) stream_agent( inputs=in_1, outputs=[out_1, out_2], f_type='element', f=number_even_odd) in_1.extend([3, 4, 5, 8]) out_1.print_recent() out_2.print_recent() check_empty()
def start(self, users): print "Starting..." #start Twitter stream streamThreads = [] streamBuffers = [] for user in users: sr = Stream(user['con_key'], user['con_secret'], user['key'], user['secret'], user['name']) #insert user list into db list = sr.getUserList(self.parseLists(user['lists'])) self.sql.insert_into_userList(list, user['db']) #get buffer and run stream buff = sr.getTweetsBuffer() if list is not None: stream = sr.run(list) else: stream = sr.run(None) #add new buff and stream to list streamBuffers.append({'buff':buff, 'db':user['db']}) streamThreads.append(stream) print "Started user: "******"Started user: "******"Exiting..." os._exit(0)
def get(self): self.cache('manage') JINJA_ENVIRONMENT = jinja2.Environment( loader=jinja2.FileSystemLoader('templates'), extensions=['jinja2.ext.autoescape'], autoescape=True) user = users.get_current_user() user_id = user.user_id() user_email = user.email() #Get the list of streams my_streams = Stream.query(Stream.owner_id == user_id) subscribed_streams = Stream.query(Stream.subscribed_users.IN([user_email])) template_values = { 'my_streams':my_streams, 'subscribed_streams':subscribed_streams } template = JINJA_ENVIRONMENT.get_template('ManagementPage.html') self.response.write(template.render(template_values))
def test(): # Create stream x and give it names 'x'. x = Stream('input') # v is the stream returned by stream_cumulative(x) and # w is the stream returned by stream_cumulative(v). v = stream_cumulative(x) w = stream_cumulative(v) # avg is the stream returned by stream_average(x) avg = stream_average(x) # Give names to streams. This is helpful in reading output. v.set_name('cumulative sum of input') w.set_name('cumulative sum of cumulative sum of input') avg.set_name('average of input') check(v, [3, 8, 18, 20, 25, 36]) check(w, [3, 11, 29, 49, 74, 110]) check(avg, [3.0, 4.0, 6.0, 5.0, 5.0, 6.0]) print print 'add values [3, 5, 10] to the tail of the input stream.' # Add values to the tail of stream x. x.extend([3, 5, 10]) # Print the N most recent values of streams x, v, w. x.print_recent() v.print_recent() w.print_recent() avg.print_recent() print print 'add values [2, 5, 11] to the tail of the input stream.' # Add more values to the tail of stream x. x.extend([2, 5, 11]) # Print the N most recent values of streams x, v, w. x.print_recent() v.print_recent() w.print_recent() avg.print_recent() check_empty()
def add_stream(self, component, section, status, enrols, times): # Create stream object stream = Stream(component=component, section=section, status=status, enrols=enrols, times=times) # Include the stream iff all it's attributes are valid if stream.included: self.streams.append(stream) return stream
def get(self): self.cache('manage') JINJA_ENVIRONMENT = jinja2.Environment( loader=jinja2.FileSystemLoader('templates'), extensions=['jinja2.ext.autoescape'], autoescape=True) user = users.get_current_user() user_id = user.user_id() user_email = user.email() #Get the list of streams my_streams = Stream.query(Stream.owner_id == user_id) subscribed_streams = Stream.query( Stream.subscribed_users.IN([user_email])) template_values = { 'my_streams': my_streams, 'subscribed_streams': subscribed_streams } template = JINJA_ENVIRONMENT.get_template('ManagementPage.html') self.response.write(template.render(template_values))
def get(self): user_email = cgi.escape(self.request.get('user_email')) #Get the list of streams subscribed_streams = Stream.query(Stream.subscribed_users.IN([user_email])) images = {'stream_names': [], 'image_urls': [],} for stream in subscribed_streams: images['stream_names'].append(stream.name) images['image_urls'].append(stream.cover_image) image_json = json.dumps(images,indent=4, separators=(',', ': ')) self.response.write(image_json)
def run(self): """ Runs the framework and returns a `Stream` of outputs. Returns ------- y_predict : `Stream` A `Stream` containing outputs as returned by `predict_func`. """ self._initialize() self._init_streams() self.model_stream = Stream('model') self.all_stream = Stream('all') # Continual learning if isinstance(self.data_train, Stream): self.stream_filter(self.data_train) self.stream_train(inputs=self.x_train) if self.all_func is not None: self.stream_all(inputs=self.data_train) # Batch learning with numpy array elif isinstance(self.data_train, np.ndarray): x = self.data_train[:, 0:self.num_features] y = self.data_train[:, self.num_features:] self.model = self.train_func(x, y, None, None) self.trained = True # Batch learning else: self.model = self.train_func(self.data_train, None, None, None) self.trained = True y_predict = self.stream_predict(self.data_out) return y_predict
def main(): # EXAMPLE FUNCTIONS ON WINDOWS # Functions have a single input: a list # which is the list of values in a window. # Functions return a scalar value, _no_value # or a list, _multivalue(). min_window_size = 2 max_window_size = 11 step_size = 2 input_stream = Stream('in') # output_stream = Stream('out') current_window_size = 0 steady_state = False reset = False state = [current_window_size, steady_state, reset] def f(lst, state): print lst return (lst, state) f_stream = partial(dynamic_window_func, f = f, state = state, min_window_size = min_window_size, max_window_size = max_window_size, step_size = step_size) output_stream = f_stream(inputs = input_stream) # output_stream = dynamic_window_func( # f, input_stream, state, # min_window_size, max_window_size, step_size) for i in range(1, 15): print "Adding ", i input_stream.extend([i]) if i == 10: state[2] = True # output_stream.print_recent() print "\n"
def main(): print "example_1" print x = Stream('x') y = stream_func(x, f_type='window', f=ksigma, num_outputs=1, window_size=WINDOW_SIZE, step_size=STEP_SIZE) y.set_name('y') x.extend(range(20)) x.print_recent() y.print_recent() print x.extend(range(20, 0, -1)) x.print_recent() y.print_recent() print
def test(): # Create stream x, and give it name 'input'. x = Stream('input') y = g(x) y.set_name('output') check(y, [3, 1, 2, 5, 2, 4, 7]) # Add values 3, 2, 5 to the tail of stream x. x.extend([3, 2, 5]) x.print_recent() y.print_recent() # Add values 4, 7 to the tail of stream x. x.extend([4, 7]) x.print_recent() y.print_recent() check_empty()
def main(): lst = [ (0, [3, 4, 1]), (1, [4, 3, 2]), (2, [2, 2, 3]), (3, [1, 2, 1]), (4, [0, 0, 2]), (5, [1, 0, 1]), (6, [0, 1, 1]), (7, [2, 0, 1]), (8, [1.5, 2, 1]), (9, [2, 1.5, 3]), (10, [3, 4, 1]), (11, [4, 3, 0]), ] x = Stream("x") h, v = pick_h_and_v_in_stream(x) h_quenched = quench_stream(h) v_quenched = quench_stream(v) h.set_name("h") v.set_name("v") h_quenched.set_name("h quenched") v_quenched.set_name("v quenched") x.extend(lst) x.print_recent() print h.print_recent() print v.print_recent() print h_quenched.print_recent() print v_quenched.print_recent()
def __init__(self, server_ip, server_port, user_interface=None, is_root=False, root_address=None): """ The Peer object constructor. Code design suggestions: 1. Initialise a Stream object for our Peer. 2. Initialise a PacketFactory object. 3. Initialise our UserInterface for interaction with user commandline. 4. Initialise a Thread for handling reunion daemon. Warnings: 1. For root Peer, we need a NetworkGraph object. 2. In root Peer, start reunion daemon as soon as possible. 3. In client Peer, we need to connect to the root of the network, Don't forget to set this connection as a register_connection. :param server_ip: Server IP address for this Peer that should be pass to Stream. :param server_port: Server Port address for this Peer that should be pass to Stream. :param is_root: Specify that is this Peer root or not. :param root_address: Root IP/Port address if we are a client. :type server_ip: str :type server_port: int :type is_root: bool :type root_address: tuple """ self.server_address = (server_ip, server_port) self.stream = Stream(server_ip, server_port) self.packet_factory = PacketFactory() self.user_interface = user_interface
def main(): def max_and_min(lst): return (max(lst), min(lst)) x = Stream('x') y,z = stream_func(x, f_type='window', f=max_and_min, num_outputs=2, window_size=2, step_size=2) y.set_name('y') z.set_name('z') x.extend([3,5]) x.print_recent() y.print_recent() z.print_recent() print x.extend([11,15]) x.print_recent() y.print_recent() z.print_recent() print
def get(self): user_email = cgi.escape(self.request.get('user_email')) #Get the list of streams subscribed_streams = Stream.query( Stream.subscribed_users.IN([user_email])) images = { 'stream_names': [], 'image_urls': [], } for stream in subscribed_streams: images['stream_names'].append(stream.name) images['image_urls'].append(stream.cover_image) image_json = json.dumps(images, indent=4, separators=(',', ': ')) self.response.write(image_json)
def calc_st2_o(self): st2_o = Stream() st2_o.fluid = self.st2_i.fluid st2_o.flow_rate = self.st2_i.flow_rate st2_o.pressure = self.st2_i.pressure - self.pressure_drop( self.st2_i, self.st2_pip) h = self.st2_i.h - (self.st1_i.h - self.st1_o.h) * self.st1_i.flow_rate[0] \ / st2_o.flow_rate[0] / self.eta h_l = PropsSI('H', 'P', st2_o.pressure, 'Q', 0, st2_o.fluid) h_g = PropsSI('H', 'P', st2_o.pressure, 'Q', 1, st2_o.fluid) if h_l <= h <= h_g: st2_o.x = PropsSI('Q', 'P', st2_o.pressure, 'H', h, st2_o.fluid) else: st2_o.temperature = PropsSI('T', 'P', st2_o.pressure, 'H', h, st2_o.fluid) self.st2_o = st2_o
def calc_st2_i(self): st2_i = Stream() st2_i.fluid = self.st2_o.fluid st2_i.flow_rate = self.st2_o.flow_rate st2_i.pressure = self.st2_o.pressure + self.pressure_drop( self.st2_o, self.st2_pip) h = self.st2_o.h + (self.st1_i.h - self.st1_o.h) * self.st1_i.flow_rate[0] \ / self.st2_o.flow_rate[0] * self.eta h_l = PropsSI('H', 'P', st2_i.pressure, 'Q', 0, st2_i.fluid) h_g = PropsSI('H', 'P', st2_i.pressure, 'Q', 1, st2_i.fluid) if h_l <= h <= h_g: st2_i.x = PropsSI('Q', 'P', st2_i.pressure, 'H', h, st2_i.fluid) else: st2_i.T = PropsSI('T', 'P', st2_i.pressure, 'H', h, self.st2_i.fluid) self.st2_i = st2_i
def get(self): # self.setup('trending') self.cache('trending') JINJA_ENVIRONMENT = jinja2.Environment( loader=jinja2.FileSystemLoader('templates'), extensions=['jinja2.ext.autoescape'], autoescape=True) #Get the list of streams streams = Stream.query().order(-Stream.views) template_values = { 'streams':streams } template = JINJA_ENVIRONMENT.get_template('TrendingStreamsPage.html') self.response.write(template.render(template_values))
def __init__(self): self.stream_parent_conn, self.stream_child_conn = mp.Pipe() model_path = '../data/faster_rcnn_inception_v2_coco_2018_01_28/frozen_inference_graph.pb' self.odapi = DetectorAPI(path_to_ckpt=model_path) self.cal = Calibration() self.comm = Comm() self.stream = Stream(self.stream_child_conn) self.str = mp.Process(target=self.stream.run, args=()) self.eat = None self.socket_update = None self.frame_lock = mp.RLock() self.coords_lock = mp.RLock() self.coords = []
def get(self): self.cache('view') JINJA_ENVIRONMENT = jinja2.Environment( loader=jinja2.FileSystemLoader('templates'), extensions=['jinja2.ext.autoescape'], autoescape=True) user = users.get_current_user() user_id = user.user_id() #Get the list of streams my_streams = Stream.query(Stream.owner_id == user_id).order(Stream.timestamp) template_values = { 'my_streams':my_streams, } template = JINJA_ENVIRONMENT.get_template('ViewAllStreamsPage.html') self.response.write(template.render(template_values))
class Processor: def __init__(self): # f, outputFilePath): self.stream = Stream(self.inputFilePath, self.dict_key) self.new_shelf_file = self.outputFilePath def process(self): with ShelveManager(self.new_shelf_file) as new_shelf: for index, fields in self.stream.stream(): if index in new_shelf: #print('index in new shelf') ### Some sort of check whether self.resolve.. returns anything, otherwise don't set the index? new_shelf[index] = self.resolve(new_shelf[index], fields) else: #print('index not in new shelf') new_shelf[index] = self.transform(fields)
def get_st2(self, st1, pressure2): st2 = Stream() st2.fluid = st1.fluid st2.flow_rate = st1.flow_rate st2.pressure = pressure2 s_ideal = st1.s h2_ideal = PropsSI('H', 'S', s_ideal, 'P', st2.pressure, st2.fluid) eta = self.calculate_eta(st1.pressure, st2.pressure) h2 = st1.h - eta * (st1.h - h2_ideal) # Check whether it is saturated h2_l = PropsSI('H', 'P', st2.pressure, 'Q', 0, st2.fluid) h2_g = PropsSI('H', 'P', st2.pressure, 'Q', 1, st2.fluid) if h2_l <= h2 <= h2_g: st2.quality = PropsSI('Q', 'P', st2.pressure, 'H', h2, st2.fluid) else: st2.temperature = PropsSI('T', 'P', st2.pressure, 'H', h2, st2.fluid) return st2
def get(self): message = mail.EmailMessage() user = users.get_current_user() message.sender = user.email() message.subject = "Trending" message.to = user.email() #Get the list of streams streams = Stream.query().order(-Stream.views) i = 0 top = [] for stream in streams: if i == 3: break top.append(stream.name) i = i + 1 if len(top) == 3: message.body = "'Top 3 Trending Streams: %s %s %s'" % ( top[0], top[1], top[2]) else: message.body = "'There are not 3 streams in the datastore'" message.send()
def get(self): JINJA_ENVIRONMENT = jinja2.Environment( loader=jinja2.FileSystemLoader('templates'), extensions=['jinja2.ext.autoescape'], autoescape=True) user = users.get_current_user() login_url = users.create_login_url('/management') if user: self.redirect('/management') #Get the list of streams streams = Stream.query() template_values = { 'login_url': login_url, } template = JINJA_ENVIRONMENT.get_template('MainPage.html') self.response.write(template.render(template_values))
def make_timer_streams_for_network(agent_dict): """ Returns ------- agent_timer_dict, a dict where key: agent_name value: a stream (note a stream and not a name) This stream is a call stream of the agent with the specified name (the key). Usually, timing messages are sent on this stream. The agent takes a step when it receives a message on this stream. """ agent_timer_dict = dict() for agent_name, agent in agent_dict.items(): timer_stream = Stream(agent_name + ':timer') if agent.call_streams is None: agent.call_streams = [timer_stream] agent_timer_dict[agent_name] = timer_stream return agent_timer_dict
def inlezen_file(checkpublic, file): f = open(file, "r") if f.mode == "r": acl_interface = "" for line in f: # Haal alle dubbele spaties weg uit de regel. line = re.sub('\s+',' ',line) # lees regel in en split op spatie. lineArray = line.split(" ") # Voeg waardes toe aan variabele voor verdere referentie in de code source_interface = lineArray[9].split("/")[0] src_ip_split = lineArray[9].split("/")[1] src_ip = src_ip_split.split("(")[0] src_port = src_ip_split.split("(")[1].replace(")"," ").rstrip() acl_interface = lineArray[6] protocol = lineArray[8].strip().lower() dst_ip_split = lineArray[11].split("/")[1] dst_ip = dst_ip_split.split("(")[0] dst_port = dst_ip_split.split("(")[1].replace(")", " ").rstrip() dst_interface = lineArray[11].split("/")[0] # Haal vanuit de syslog over welke interface ACL het gaat. Dit wordt in de klasse opgeslagen en later gebruikt om ASA CLI uit te printen Stream.interface = acl_interface # controleer of stream ping verkeer is if protocol == "icmp": src_port = "0" dst_port = "0" # controleer of het destination ip-adres publiek of private is. Indien publieke filtering aanstaat wordt het destination adres aangepast naar "any" if checkpublic is True: ip = IP(dst_ip) type_ip = ip.iptype() if type_ip == "PUBLIC": dst_ip = "any" Stream(src_ip,dst_ip,dst_port,protocol)
def cache(self, currentTab): JINJA_ENVIRONMENT = jinja2.Environment( loader=jinja2.FileSystemLoader('templates'), extensions=['jinja2.ext.autoescape'], autoescape=True) user = users.get_current_user() user_id = user.user_id() logout_url = users.create_logout_url('/') #welcome to Connexus userInfo = {'user': user, 'logout_url': logout_url} template = JINJA_ENVIRONMENT.get_template('Welcome.html') self.response.write(template.render(userInfo)) #Get the list of streams streams = Stream.query() taglist = [] streamNames = [] for stream in streams: streamNames.append(str(stream.name)) for tag in stream.tags: if tag not in taglist: streamNames.append(tag) taglist.append(tag) template_values = {'streams': streams} template = JINJA_ENVIRONMENT.get_template('Search.html') self.response.write(template.render(streams=json.dumps(streamNames))) #test search header searchHead = JINJA_ENVIRONMENT.get_template('Header.html') self.response.write(searchHead.render(current=currentTab))
def __init__(self, config, timestamp, q=None, watchdogQueue=None, marsOnlineQueue=None, ipAddress=None): #assign queues self._watchdogQueue = watchdogQueue self._marsOnlineQueue = marsOnlineQueue #Init devices self._devices = self.initDevices(config) #Prepare stream self._devices['Stream'] = Stream(config, timestamp, ipAddress) logger.info("Connecting Jetson") self._jetson = Jetson(self._devices, config, timestamp, q) time.sleep(.5) logger.info("All devices connected") logger.info("System initialized.") if q is None: try: answer = raw_input("Would you like to start? Y/n: ") except KeyboardInterrupt: self._jetson.exit() return if answer.lower() == 'n' or answer.lower() == 'no': self._jetson.exit() else: self._jetson.start() else: self._jetson.start()
def _getBuiltInDefaultValue(self, instance): import pyre.parsing.locators locator = pyre.parsing.locators.default() import sys if hasattr(sys.stdout, 'isatty') and sys.stdout.isatty(): from os import environ term = environ.get('TERM', 'console') component = instance.retrieveComponent(term, factory=self.family, vault=self.vault) if component is None: from Console import Console component = Console() else: component.aliases.append(self.name) locator = pyre.parsing.locators.chain(component.getLocator(), locator) else: from Stream import Stream component = Stream(sys.stdout, "stdout") return component, locator
def start(self, users): print "Starting..." #start Twitter stream streamThreads = [] streamBuffers = [] for user in users: sr = Stream(user['con_key'], user['con_secret'], user['key'], user['secret'], user['name']) #insert user list into db list = sr.getUserList(self.parseLists(user['lists'])) self.sql.insert_into_userList(list, user['db']) #get buffer and run stream buff = sr.getTweetsBuffer() if list is not None: stream = sr.run(list) else: stream = sr.run(None) #add new buff and stream to list streamBuffers.append({'buff': buff, 'db': user['db']}) streamThreads.append(stream) print "Started user: "******"Started user: "******"Exiting..." os._exit(0)
def make_process( input_stream_names, output_stream_names, func, input_queue, output_queues_list): """ Makes a process that gets messages on its single input queue, processes the messages and puts messages on its output queues. An output queue of this process is an input queue of another process. Parameters ---------- input_stream_names : list of str List of names of input streams output_stream_names : list of str List of names of output streams func : function The parameters of func are input_streams, output_streams where input_streams is a list of streams whose names are in input_stream_names and where output_streams is a list of streams whose names are in output_stream_names. func gets messages on its input streams and puts messages on its output streams. input_queue: multiprocessing.Queue Each process has a single input queue along which it receives messages. output_queues_list : list of list of multiprocessing.Queue output_queues_list[j] is the list of queues to which messages that appear on the stream with name output_stream_names[j] should be sent. Returns ------- None Attributes ---------- input_streams : list of Stream input_stream[j] is the Stream with name input_stream_name[j]. output_streams : list of Stream output_stream[j] is the Stream with name output_stream_name[j]. map_name_to_input_stream : dict key : str name of an input stream value : Stream The stream with the specified name. Notes ----- make_process carries out the following steps: (1) Sets up data structures for the next two steps. (2) Calls func which creates the network of agents that process messages on its input streams and puts messages on its output streams. (3) Makes the output and input managers. """ # Create input_streams, output_streams and # map_name_to_input_stream input_streams = [Stream(name) for name in input_stream_names] output_streams = [Stream(name) for name in output_stream_names] map_name_to_input_stream = dict() for stream in input_streams: map_name_to_input_stream[stream.name] = stream # Call the function that creates a network of agents that # map input streams to output streams. func(input_streams, output_streams) new_output_queues_list = list() for output_queues in output_queues_list: new_output_queues = list() for output_queue in output_queues: if isinstance(output_queue, tuple): SERVER, PORT, DESTINATION = output_queue new_output_queue = RemoteQueue(SERVER, PORT, DESTINATION) new_output_queues.append(new_output_queue) else: new_output_queues.append(output_queue) new_output_queues_list.append(new_output_queues) make_output_manager(output_streams, new_output_queues_list) if isinstance(input_queue, tuple): SERVER, PORT, DESTINATION = input_queue input_queue = RemoteQueue(SERVER, PORT, DESTINATION) make_input_manager(input_queue, input_streams, map_name_to_input_stream)