def main(): logging.basicConfig(filename=LOG_FILE, level=logging.INFO, format='%(asctime)s %(message)s') logging.info("Bustimes starting") with open('config.yaml') as f: config = yaml.load(f, Loader=yaml.FullLoader) weather_api_key = config['weather']['api_key'] lat = config['weather']['latitude'] lng = config['weather']['longitude'] logging.info('Weather API: %s', weather_api_key) logging.info('Weather latitude: %s', lat) logging.info('Weather longitude: %s', lng) weather_service = weather.Weather(weather_api_key, lat, lng) bus_api_key = config['bus']['api_key'] bus_api_base_url = config['bus']['api_base_url'] bus_data_feed = config['bus']['data_feed'] logging.info('Bus API: %s', bus_api_key) logging.info("Bus API base URL: %s", bus_api_base_url) logging.info("Bus API data feed: %s", bus_data_feed) bus_service = bus.Bus(bus_api_key, bus_api_base_url, bus_data_feed) window = tk.Tk() app = BusTimes(window, bus_service, weather_service, config) window.mainloop() logging.info("Bustimes exiting")
def get_next_bus(handler_input): # Get the two next time of bus stop # Get the persistence attributes attr = handler_input.attributes_manager.persistent_attributes if not attr: attr['code'] = 0 attr['station'] = u'None' attr['way'] = u'None' handler_input.attributes_manager.session_attributes = attr handler_input.attributes_manager.save_persistent_attributes() if (attr['code'] != 0) & (attr['station'] != u'None') & (attr['way'] != u'None'): mybus = bus.Bus(attr['code']) mybus.setStation(attr['station']) mybus.setWay(attr['way']) speech_text = mybus.getSchedules() handler_input.response_builder.speak(speech_text).set_should_end_session(True) else: speech_text = "Aucune configuration ou configuration incomplete ." reprompt = "Pour débuter la configuration de smart bus dites: configurer le bus ... suivi du numéro de votre ligne" speech_text += reprompt handler_input.response_builder.speak(speech_text).ask(reprompt) return handler_input.response_builder.response
def __init__(self): self.bus = bus.Bus() self.memory = memory.Memory(self.bus) self.L2C0 = L2.L2(0, self.bus, self.memory) self.L2C1 = L2.L2(1, self.bus, self.memory) self.directoryController = directoryController.DirectoryController( self.L2C0, self.L2C1, self.memory, self.bus) self.C0 = chip.Chip(0, self.memory, self.bus, self.directoryController, self.L2C0) self.C1 = chip.Chip(1, self.memory, self.bus, self.directoryController, self.L2C1) self.window = Tk() self.tableL1P0C0 = Treeview(self.window, height=2) self.tableL1P1C0 = Treeview(self.window, height=2) self.tableL1P0C1 = Treeview(self.window, height=2) self.tableL1P1C1 = Treeview(self.window, height=2) self.tableL2C0 = Treeview(self.window, height=4) self.tableL2C1 = Treeview(self.window, height=4) self.tableMemory = Treeview(self.window, height=16) self.t1 = threading.Thread(target=self.C0.run) self.t2 = threading.Thread(target=self.C1.run) self.t3 = threading.Thread(target=self.directoryController.runL2toMem) self.t4 = threading.Thread(target=self.directoryController.runMemtoL2) self.t5 = threading.Thread(target=self.updateMemories)
def test_handler_raise_exception_in_execute_method(self): b = bus.Bus() b.register(object, RaiseExceptionHandler()) command = object() result = b.execute(command) self.assertFalse(result.ok)
def init_bus(self): for i in range(cf.N_RIDES): time = cf.HEADWAY * 60 * i self.active_buses.append( bus.Bus(self.next_bus_id, self.chkpts[1:], time, self.chkpts[0])) self.next_bus_id += 1 """
def test_empty_init(self): "Test the default Bus creation" # 1. Create default Bus object myobj = bus.Bus() # 2. Make sure it has the default values self.assertEqual(myobj.bid, 0) self.assertEqual(myobj.offset, 0)
def test_value_init(self): "Test the Bus object creation from text" # 1. Create Bus object from text myobj = bus.Bus(bid='7', offset=2) # 2. Make sure it has the expected values self.assertEqual(myobj.bid, 7) self.assertEqual(myobj.offset, 2)
def test_bus_can_register_handler(self): b = bus.Bus() command = object handler = object() b.register(command, handler) self.assertTrue(command in b.handlers) self.assertEqual(handler, b.handlers[command])
def test_execute_handle_method_from_handler(self): b = bus.Bus() handler = FakeHandler() b.register(object, handler) command = object() b.execute(command) self.assertTrue(handler.handle_called) self.assertEqual(command, handler.command)
def test_part_one(self): "Test part one examples of Bus object" # 1. Loop for all the examples for example in EXAMPLES: # 2. Create Bus object from values myobj = bus.Bus(bid=example['bid']) # 3. Check the part one result self.assertEqual(myobj.next_depart_after(example['at']), example['departs'])
def __init__(self, text=None, part2=False): # 1. Set the initial values self.part2 = part2 self.text = text self.earliest = 0 self.buses = [] # 2. Process text (if any) if text is not None and len(text) > 1: self.earliest = int(text[0]) for offset, bid in enumerate(text[1].split(',')): if bid != 'x': self.buses.append(bus.Bus(bid=bid, offset=offset))
def make_buses_appear(lanes, sources, time, delta_time): new_buses = [] for index, bus_sources in enumerate(sources['bus']): if bus_sources: for x in bus_sources: line = x['line'] source = x['source'] if source and source.chances_to_appear(delta_time): new_bus = bus_module.Bus(line, 0, 0) next_car = get_next_car(new_bus, lanes[index]) if not next_car or (rear(next_car, 0) > new_bus.position + DISTANCE_MARGIN): lanes[index].add_car(new_bus) new_buses.append(new_bus) source.reset() return new_buses
def configure_handlers(self): self.bus = bus.Bus() self.bus.register(commands.CreateRangeVoteCommand, handlers.CreateRangeVoteHandler(self.repository)) self.bus.register(commands.UpdateRangeVoteCommand, handlers.UpdateRangeVoteHandler(self.repository)) self.bus.register(commands.CreateVoteCommand, handlers.CreateVoteHandler(self.repository)) self.query_dispatcher = bus.QueryDispatcher() self.query_dispatcher.register( queries.GetRangeVoteQuery, handlers.GetRangeVoteHandler(self.repository)) self.query_dispatcher.register( queries.GetRangeVotesQuery, handlers.GetRangeVotesHandler(self.repository)) self.query_dispatcher.register( queries.GetRangeVoteResultsQuery, handlers.GetRangeVoteResultsHandler(self.repository))
def yindu(): content = [] router_name = ["143路", "莘南专线", "闵行41路", "庄莘线", "闵行30路"] direction = ['1', '1', '1', '0', '1'] stop_id = ['36', '25', '31', '40', '15'] bus = B.Bus() for i in range(len(router_name)): r_name = router_name[i] stop = stop_id[i] dire = direction[i] #info = bus.query_router(r_name,direction=dire) #print(info) r = bus.query_stop(r_name, dire, stop) if r["stop_interval"] == "" and r["time"] == "": content.append(r_name + "已停运\n\r") else: content.append(r_name + " 还有" + r["stop_interval"] + "站 " + str(round(int(r["time"]) / 60.0, 2)) + "分\n\r") return "".join(content)
def get_bus_stop(handler_input): # Get all bus stop of the line if handler_input.request_envelope.request.intent.slots["busnumber"].value: session_attr = handler_input.attributes_manager.session_attributes session_attr['code'] = handler_input.request_envelope.request.intent.slots["busnumber"].value mybus = bus.Bus(session_attr['code']) if mybus.query_code == 200: speech_text = mybus.getStations() reprompt = "Pour configurer la station, dites: configurer la station ... suivi du numéro de station ." speech_text += reprompt else: speech_text = "Numéro de bus inconnu ." reprompt = "Pour connaitre les numéros de stations, dites: quels sont les stations de la ligne ... suivi du numéro du bus" speech_text += reprompt else: speech_text = "Vous devez donner le numéro de ligne de bus ." reprompt += "Pour connaitre les numéros de stations, dites: quels sont les stations de la ligne ... suivi du numéro du bus" speech_text += reprompt handler_input.response_builder.speak(speech_text).ask(reprompt) handler_input.attributes_manager.persistent_attributes = session_attr handler_input.attributes_manager.save_persistent_attributes() return handler_input.response_builder.response
def __init__(self): self.rom = rom32k.ROM32K() self.memory = memory.Memory() self.bus = bus.Bus(self.rom, self.memory) self.cpu = cpu.CPU(self.bus)
import interpretor import sensor_commands import controller import bus from sensor_commands import producer as sensor_function from interpretor import consumer_producer as interpreter_function from controller import consumer_producer as controller_function import concurrent.futures from readerwriterlock import rwlock motor = motor_commands.MotorCommands() inter = interpretor.Interpretor() contr = controller.Controller() sens = sensor_commands.SensorCommands() sensor_values_bus = bus.Bus() interpreter_bus = bus.Bus() controller_bus = bus.Bus() sensor_delay = 1 interpreter_delay = 1 controller_delay = 1 with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor: eSensor = executor.submit(sensor_function, sensor_values_bus, sensor_delay) eInterpreter = executor.submit(interpreter_function, sensor_values_bus, interpreter_bus, interpreter_delay) eSensor.result() eInterpreter.result()
from flask import Flask import gateway import bus import dal import product if __name__ == "__main__": # Here's the bootstrapper, it starts the vector of microservices we'll need, along with their protocols enterpriseServiceBus = bus.Bus( 'amqp://*****:*****@rabbitmq-master.default.svc.cluster.local/%2f', 10) gatewayService = gateway.Gateway(enterpriseServiceBus) dalDbDriver = dal.DalHelper() productService = ProductService()
from OpenGL.GL import * from OpenGL.GLUT import * from OpenGL.GLU import * import threading as th import time from datetime import datetime import bus import sys import cartridge as cart import graphics as g nes = bus.Bus() cartridge = None mapAsm = [] show_canvas_opengl = False show_canvas_qt = True show_palettes = False rom = "nestest.nes" class CanvasOpenGL(): pixel_size = 2 sprite = nes.ppu.spr_screen key_value = 0x00
def setup_bus(): bus_url = os.environ.get('BUS_URL', 'amqp://*****:*****@localhost:5672') return bus.Bus(bus_url)
def setup_bus(): bus_url = os.environ.get('BUS_URL') if not bus_url: port = AssetLauncher.service_port(5672, 'rabbitmq') bus_url = 'amqp://*****:*****@localhost:{port}'.format(port=port) return bus.Bus(bus_url)
metavar='N', help='the number of trips that a bus does') parser.add_argument( '--inter-trip-pause', type=float, default=300.0, metavar='T', help= 'how much time the bus waits before starting a new trip or returns to the depot, units in s' ) parser.add_argument('--route-data', type=str, default=None, metavar='FILENAME', help='XML file with route information') return parser.parse_args() if __name__ == '__main__': args = process_arguments() if args.route_data is not None: route.read_routes_xml(args.route_data) a_bus = bus.Bus( # start_position=args.start_position, velocity=args.velocity, bus_stop_boarding_time=args.bus_stop_boarding_time, # data_rate=args.data_rate, number_trips=args.number_trips, inter_trip_pause=args.inter_trip_pause) a_bus.run()
def configure_smart_bus(handler_input): # Configure bus, station and direction # Get the persistence attributes attr = handler_input.attributes_manager.persistent_attributes if not attr: attr['code'] = 0 attr['station'] = u'None' attr['way'] = u'None' handler_input.attributes_manager.session_attributes = attr handler_input.attributes_manager.save_persistent_attributes() session_attr = handler_input.attributes_manager.session_attributes what = handler_input.request_envelope.request.intent.slots["what"].value if what == 'bus': if handler_input.request_envelope.request.intent.slots["whatnumber"].value: session_attr['code'] = handler_input.request_envelope.request.intent.slots["whatnumber"].value session_attr['station'] = u'None' session_attr['way'] = u'None' mybus = bus.Bus(session_attr['code']) if mybus.query_code == 200: speech_text = "Vous venez de configurer la ligne de bus numéro {0} .".format(session_attr['code']) reprompt = "Pour configurer la station, dites: configurer la station ... suivi du numéro de station ." reprompt += "Pour connaitre les numéros de stations, dites: quels sont les stations de la ligne ... suivi du numéro du bus" speech_text += reprompt else: speech_text = "Numéro de bus inconnu ." reprompt = "Pour débuter la configuration de smart bus dites: configurer le bus ... suivi du numéro de votre ligne" speech_text += reprompt else: speech_text = "Vous devez donner le numéro de ligne de bus ." reprompt = "Pour débuter la configuration de smart bus dites: configurer le bus ... suivi du numéro de votre ligne" speech_text += reprompt elif what == 'station': if handler_input.request_envelope.request.intent.slots["whatnumber"].value: if session_attr['code'] != 0: mybus = bus.Bus(session_attr['code']) stationNumber = int(handler_input.request_envelope.request.intent.slots["whatnumber"].value) # check station number if (stationNumber > 0) & (stationNumber <= len(mybus.stations)): stationName = mybus.stations[stationNumber-1] session_attr['station'] = stationName speech_text = "Vous venez de configurer la station {0} .".format(stationName) reprompt = "Pour configurer la direction, dites: configurer la direction ... suivi de aller ou retour" speech_text += reprompt else: speech_text = "Le numéro de station doit être compris entre 1 et {0} .".format(len(mybus.stations)) reprompt = "Pour configurer la station, dites: configurer la station ... suivi du numéro de station ." speech_text += reprompt else: speech_text = "Le numéro de ligne de bus n'a pas été configuré ." reprompt = "Pour débuter la configuration de smart bus dites: configurer le bus ... suivi du numéro de votre ligne" speech_text += reprompt else: speech_text = "Vous devez donner le numéro de station ." reprompt = "Pour configurer la station, dites: configurer la station ... suivi du numéro de station ." speech_text += reprompt elif what == 'direction': if handler_input.request_envelope.request.intent.slots["whatstring"].value: if (session_attr['code'] != 0) & (session_attr['station'] != u'None'): direction = handler_input.request_envelope.request.intent.slots["whatstring"].value if direction == 'aller': session_attr['way'] = 'A' speech_text = "Vous venez de configurer la direction {0} .".format(direction) speech_text += "Configuration terminer. Pour connaitre l'heure du prochain bus, dites: quand passe mon bus ." reprompt = "Pour connaitre l heure de passage de votre prochain bus, dites : quand passe mon bus ?" elif direction == 'retour': session_attr['way'] = 'R' speech_text = "Vous venez de configurer la direction {0} .".format(direction) speech_text += "Configuration terminer. Pour connaitre l'heure du prochain bus, dites: quand passe mon bus ." reprompt = "Pour connaitre l heure de passage de votre prochain bus, dites : quand passe mon bus ?" else: print 'Direction inconnue: {0}'.format(direction) speech_text = "Direction {0} inconnue .".format(direction) reprompt = "Pour configurer la direction, dites: configurer la direction ... suivi de: aller ou retour" speech_text += reprompt elif session_attr['code'] == 0: speech_text = "Le numéro de ligne de bus n'a pas ete configurer ." reprompt = "Pour débuter la configuration de smart bus dites: configurer le bus ... suivi du numéro de votre ligne" speech_text += reprompt else: speech_text = "Le numéro de station n'a pas ete configurer ." reprompt = "Pour configurer la station, dites: configurer la station ... suivi du numéro de station ." speech_text += reprompt else: speech_text = "Vous devez donner la direction ." reprompt = "Pour configurer la direction, dites: configurer la direction ... suivi de: aller ou retour" speech_text += reprompt else: print 'Type de configuration inconnue.' speech_text = "Type de configuration inconnue ." reprompt = "Pour débuter la configuration de smart bus dites: configurer le bus ... suivi du numéro de votre ligne ." reprompt += "Pour configurer la station, dites: configurer la station ... suivi du numéro de station ." reprompt += "Pour configurer la direction, dites: configurer la direction ... suivi de: aller ou retour" speech_text += reprompt handler_input.response_builder.speak(speech_text).ask(reprompt) handler_input.attributes_manager.persistent_attributes = session_attr handler_input.attributes_manager.save_persistent_attributes() return handler_input.response_builder.response
def test_raise_error_if_no_handlers_availables(self): b = bus.Bus() with self.assertRaises(Exception): b.execute(object())
"""importation des codes pour les differents capteurs"""" import sys import os sys.path.append(os.getcwd()) import temperature import bus import lumiere """declaration des pins pour la temperature""" t = temperature.Temperature(pin_int="17", pin_ext="18", pin_rad="2") b = bus.Bus() """declaration des pins pour la lumiere""" l = lumiere.Lumiere(pin_mouv="7", pin_rel="3", niveau=1000) t.start() b.start() l.start() t.join() b.join() l.join()
def check_add_bus(self): if self.t < 0 or self.next_bus_id >= cf.N_RIDES: return if self.t % (cf.HEADWAY * 60) == 0: self.active_buses.append(bus.Bus(self.next_bus_id, self.chkpts[1:], self.t, self.chkpts[0])) self.next_bus_id = self.next_bus_id + 1
def new_bus(self): return bus.Bus(self, 0, random.randint(0, bus.Bus.max_people))