def test_creation_with_one_destination_from_one_lane(self): input_connections = connections.Connections() input_connections.add("source 1", "source lane 1", "destination 1") turn_definitions = TurnDefinitions() turn_definitions.add("source 1", "destination 1", 100.0) self.assertEqual(turn_definitions, from_connections(input_connections))
def test_creation_two_destinations_from_two_lanes_overlapping(self): input_connections = connections.Connections() input_connections.add("source 1", "source lane 1", "destination 1") input_connections.add("source 1", "source lane 2", "destination 2") input_connections.add("source 1", "source lane 2", "destination 1") turn_definitions = TurnDefinitions() turn_definitions.add("source 1", "destination 1", 100.0 / 2 / 2 + 100.0 / 2) turn_definitions.add("source 1", "destination 2", 100.0 / 2 / 2) self.assertEqual(turn_definitions, from_connections(input_connections))
class MainHandler(BaseHandler): # logging stuff.. enable_pretty_logging() logger = logging.getLogger("MainHandler") hdlr = logging.FileHandler("./mserver.log", "w+") formatter = logging.Formatter("%(asctime)s %(levelname)s %(message)s") hdlr.setFormatter(formatter) logger.addHandler(hdlr) logger.setLevel(logging.DEBUG) access_log = logging.getLogger("tornado.access") app_log = logging.getLogger("tornado.application") gen_log = logging.getLogger("tornado.general") access_log.addHandler(hdlr) app_log.addHandler(hdlr) gen_log.addHandler(hdlr) dbs = connections.Connections() async def post(self): ## get params, algorithm contains the name of the algorithm, params is a valid json file algorithm = self.get_argument("algorithm") print(algorithm) params = self.get_argument("params") #### new connection per request - required since connection objects are not thread safe at the time await self.dbs.initialize() db_objects = await self.dbs.acquire() try: result = await run_algorithm.run(algorithm, params, db_objects) self.write("{}".format(result)) except Exception as e: # raise tornado.web.HTTPError(status_code=500,log_message="...the log message??") self.logger.debug( "(MadisServer::post) QueryExecutionException: {}".format( str(e))) # print "QueryExecutionException ->{}".format(str(e)) await self.dbs.release(db_objects) self.write("Error: " + str(e)) self.finish() raise await self.dbs.release(db_objects) self.logger.debug("(MadisServer::post) str_result-> {}".format(result)) # self.write("{}".format(result)) self.finish()
def main(command=None): """ Main routine. Optionally accepts a <command> string as the first command to execute after connecting to the hosts. """ connection_info = lambda x: error(text=x) connection_error = lambda x: error(text=x, lvl=2) conns = connections.Connections(config.get('hosts'), info_output=connection_info, error_output=connection_error) connections.set(conns) if config.get('interactive') or not command: exitcode = dispatcher.run_interactive(command) else: exitcode = dispatcher.run(command) return exitcode
import uuid import _thread import tornado.httpserver import tornado.websocket import tornado.ioloop import tornado.web import asyncio import socket import json import connections import youtube_dl from tornado.platform.asyncio import AnyThreadEventLoopPolicy from mp3Juggler import mp3Juggler clients = connections.Connections() juggler = mp3Juggler(clients) __UPLOADS__ = "static/songs/" def skipper(): while True: if (input() == "s"): print("Skipping...") juggler.skip() class IndexHandler(tornado.web.RequestHandler): @tornado.web.asynchronous def get(request): request.render("index.html")
def test_creation_with_0_sources(self): self.assertEqual(TurnDefinitions(), from_connections(connections.Connections()))
dic_stations = {} #Row : Name, ID, LineID, String, LineName for row in csv_reader: element = station.station(row[0], row[2], row[4]) dic_stations[row[1]] = element #Establishing the connections between adresses with open('c.csv') as csv_file: csv_reader = csv.reader(csv_file, delimiter=',') nodes = [] dict_connections = {} #Row : ID1, ID2, Time for row in csv_reader: nodes.append(row[0]) connection = connections.Connections(row[1], row[2]) if row[0] in dict_connections.keys(): dict_connections[row[0]].append(connection) else: dict_connections[row[0]] = [connection] class Graph(object): def __init__(self): self.nodes = set() self.edges = defaultdict(list) self.distances = {} def add_node(self, value): self.nodes.add(value)
class MainHandler(BaseHandler): # logging stuff.. enable_pretty_logging() logger = logging.getLogger("MainHandler") hdlr = logging.FileHandler("./mserver.log", "w+") formatter = logging.Formatter("%(asctime)s %(levelname)s %(message)s") hdlr.setFormatter(formatter) logger.addHandler(hdlr) logger.setLevel(logging.DEBUG) access_log = logging.getLogger("tornado.access") app_log = logging.getLogger("tornado.application") gen_log = logging.getLogger("tornado.general") access_log.addHandler(hdlr) app_log.addHandler(hdlr) gen_log.addHandler(hdlr) dbs = connections.Connections() states = {} def get_package(self, algorithm): try: mpackage = "algorithms" importlib.import_module(mpackage) algo = importlib.import_module("." + algorithm, mpackage) if DEBUG: importlib.reload(algo) except ModuleNotFoundError: raise Exception( f"`{algorithm}` does not exist in the algorithms library") return algo async def post(self): ## get params, algorithm contains the name of the algorithm, params is a valid json file print(self.get_argument("params")) parameters = json.loads(self.get_argument("params")) algorithm = parameters["algorithm"] hash_value = parameters["hash"] step = parameters["step"] params = parameters["params"] static_schema = parameters["schema"] node_id = parameters["node_id"] if hash_value in self.states: db_objects = self.states[hash_value]['db_objects'] algorithm_instance = self.states[hash_value]['algorithm'] #### new connection per request - required since connection objects are not thread safe at the time else: await self.dbs.initialize() db_objects = await self.dbs.acquire() algorithm_instance = self.get_package(algorithm).Algorithm() self.states[hash_value] = {} self.states[hash_value]['db_objects'] = db_objects self.states[hash_value]['algorithm'] = algorithm_instance try: result = await run_algorithm.run(algorithm_instance, params, hash_value, step, static_schema, node_id, db_objects, self.states[hash_value]) self.write("{}".format(result)) except Exception as e: # raise tornado.web.HTTPError(status_code=500,log_message="...the log message??") self.logger.debug( "(MadisServer::post) QueryExecutionException: {}".format( str(e))) # print "QueryExecutionException ->{}".format(str(e)) if step == -1: self.states.pop(hash_value) await self.dbs.release(db_objects) self.write("Error: " + str(e)) self.finish() raise self.logger.debug("(MadisServer::post) str_result-> {}".format(result)) # self.write("{}".format(result)) self.finish() if step == -1: self.states.pop(hash_value) await self.dbs.release(db_objects)