Beispiel #1
0
    def callback(self, recognizer, audio):
        log("callback calisti.")

        dispatcher = Dispatcher(self.toText(audio))
        if dispatcher.dispatch() == "close":
            try:
                self.stop_listening()
            except StandardError as se:
                log("callback error: {0}".format(se))
Beispiel #2
0
 def __init__(self):
     super(AgentClient, self).__init__()
     self.config = AgentClientConfig()
     self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     self.ip_addr = self.config.server_ip
     self.port = self.config.server_port
     self.receiver = MessageReceiver(self.sock)
     self.handler = ScanMessageHandler()
     self.connection = ClientConnection(self, self.sock, self.ip_addr)
     self.checker = HeartBeatChecker(self.connection,
                                     self.config.heartbeat_interval)
     self.epoll = select.epoll()
     self.dispatch_queue = Queue.Queue()
     self.dispatcher = Dispatcher(self.dispatch_queue)
Beispiel #3
0
    def flow(self):
        yield self.env.timeout(0)
        dp.WID(self.Controller, self, self.Controller.AGV_disRuleW,
               self.Controller.routRule, self.Controller.Parameter)
        self.out_req = self.Controller.stations[0].out_buffer.request()
        while self.current_seq < 11:
            yield self.Queue
            self.current_seq += 1
            self.Queue = self.env.event()
            yield self.env.timeout(0)
            station = self.Controller.stations[self.seq[self.current_seq]]
            self.position = station
            req = station.resource.request()

            station.in_queue.append(self)
            station.in_num += 1

            yield req
            station.processing = self
            pt = self.PT[self.current_seq]
            station.in_queue.remove(self)
            station.in_num -= 1
            yield self.env.timeout(pt)
            station.processing = 0

            self.out_req = station.out_buffer.request()
            yield self.out_req

            station.out_queue.append(self)
            station.out_num += 1
            station.resource.release(req)
            if self.current_seq != 11:
                self.Controller.jobs.append(self)
                self.Controller.job_num += 1
                dp.WID(self.Controller, self, self.Controller.AGV_disRuleW,
                       self.Controller.routRule, self.Controller.Parameter)

        self.Tardiness = max(0, self.env.now - self.DueDate)
        self.Tardiness = round(float(self.Tardiness))
        self.FlowTime = self.env.now - self.FlowTime

        self.Controller.Tardiness.append(self.Tardiness)
        #self.Controller.MeanTardiness = np.mean(self.Controller.Tardiness)
        self.Controller.FlowTime.append(self.FlowTime)
        self.Controller.Throughput += 1
        self.Controller.sysJob.remove(self)

        self.Controller.status.tardiness.append(self.Tardiness)
        self.Controller.status.throughput += 1
Beispiel #4
0
 def testBuildGenerators1d(self):
     self.params["dimensions"] = [self.dim]
     for i in self.imps:
         if i in ("poissondisk", "spiral", "radial"):
             continue
         self.params["coordinateGenerator"] = i
         _ = disp.getObject(self.params)
Beispiel #5
0
 def testRunSelectors3d(self):
     params = {'dimensions': [self.dim, self.dim, self.dim], 'specialHaltonPoints': 2000}
     for i in self.imps:
         params['forcedSelector'] = i
         g = disp.getObject(params)
         points = g()
         [(p[0] + 1 + p[1] + p[2]) for p in points]
Beispiel #6
0
 def testBuildGenerators2d(self):
     self.params["dimensions"] = [self.dim, self.dim]
     for i in self.imps:
         if i == "poissongap":
             continue
         self.params["coordinateGenerator"] = i
         _ = disp.getObject(self.params)
Beispiel #7
0
 def testRunSelectors1d(self):
     params = {'dimensions': [self.dim], 'specialHaltonPoints': 20}
     for i in self.imps:
         params['forcedSelector'] = i
         g = disp.getObject(params)
         points = g()
         [(p[0] + 1) for p in points]
Beispiel #8
0
 def testBuildGenerators1d(self):
     self.params['dimensions'] = [self.dim]
     for i in self.imps:
         if i in ('poissondisk', 'spiral', 'radial'):
             continue
         self.params['coordinateGenerator'] = i
         _ = disp.getObject(self.params)
Beispiel #9
0
def doWinter():
    messagebox.showinfo("Warning!", "Changing Season to Winter")

    gui2.label_29['text'] = "Winter"
    houses.house1.charge = 100
    houses.house2.charge = 100
    houses.house3.charge = 50
    houses.house4.charge = 10
    open('sampleData.txt', 'w').close()
    open('sampleData2.txt', 'w').close()
    open('sampleData3.txt', 'w').close()
    open('sampleData4.txt', 'w').close()
    gui2.a.cla()
    gui2.b.cla()
    gui2.c.cla()
    gui2.d.cla()
    season =3
    dispatcher1 = Dispatcher.Dispatcher()
    dispatcher1.event_list = []
    dispatcher1.current_time = 0

    dispatcher1.add_events_from_lists(houses.house1.list_events)
    dispatcher1.add_events_from_lists(houses.house2.list_events)
    dispatcher1.add_events_from_lists(houses.house3.list_events)
    dispatcher1.add_events_from_lists(houses.house4.list_events)

    dispatcher1.run_dispatcher(houses.list_house,season)
Beispiel #10
0
 def testBuildGenerators2d(self):
     self.params['dimensions'] = [self.dim, self.dim]
     for i in self.imps:
         if i == 'poissongap':
             continue
         self.params['coordinateGenerator'] = i
         _ = disp.getObject(self.params)
Beispiel #11
0
 def testRunGenerators3d(self):
     myDim = {'range': [1, 25]}
     self.params['dimensions'] = [myDim, myDim, myDim]
     for i in ['hypertable', 'halton']:
         self.params['coordinateGenerator'] = i
         g = disp.getObject(self.params)
         points = g()
         [(p[0] + 1 + p[1] + p[2]) for p in points]
Beispiel #12
0
 def testRunGenerators3d(self):
     myDim = {"range": [1, 25]}
     self.params["dimensions"] = [myDim, myDim, myDim]
     for i in ["hypertable", "halton"]:
         self.params["coordinateGenerator"] = i
         g = disp.getObject(self.params)
         points = g()
         [(p[0] + 1 + p[1] + p[2]) for p in points]
Beispiel #13
0
 def testRunMappers1D(self):
     for mapper in self.mappers1d:
         self.params['quadratureMapper'] = mapper
         myMapper = disp.getObject(self.params)
         qPointList = myMapper(self.points1d)
         points = qPointList.getPoints()
         qPointList.getMultiPhasePoints()
         qPointList.newInstance(points[1:14])
Beispiel #14
0
 def testRunSelectors1D(self):
     for selector in self.Selectors1d:
         self.params['pointSelector'] = selector
         myselector = disp.getObject(self.params)
         qPointList = myselector(self.points1d, 0)
         points = qPointList.getPoints()
         qPointList.getMultiPhasePoints()
         qPointList.newInstance(points[1:14])
Beispiel #15
0
 def testBuildSelectors3d(self):
     params = {
         'dimensions': [self.dim, self.dim, self.dim],
         'specialHaltonPoints': 2000
     }
     for i in self.imps:
         params['forcedSelector'] = i
         _ = disp.getObject(params)
Beispiel #16
0
 def testRunMappers3D(self):
     self.params['dimensions'] = [self.dim, self.dim, self.dim]
     for mapper in self.mappers3d:
         self.params['quadratureMapper'] = mapper
         myMapper = disp.getObject(self.params)
         qPointList = myMapper(self.points3d)
         points = qPointList.getPoints()
         qPointList.getMultiPhasePoints()
         qPointList.newInstance(points[1:14])
Beispiel #17
0
    def __init__(self,
                 max_jobs_per_query=100,
                 max_running_jobs=100,
                 interval_empty_queries=5):
        self._max_jobs_per_query = max_jobs_per_query
        self._max_running_jobs = max_running_jobs
        self._interval_empty_queries = interval_empty_queries

        self.dispatcher = Dispatcher.Dispatcher()
Beispiel #18
0
 def testRunGenerators2d(self):
     self.params["dimensions"] = [self.dim, self.dim]
     for i in self.imps:
         if i == "poissongap":
             continue
         self.params["coordinateGenerator"] = i
         g = disp.getObject(self.params)
         points = g()
         [(p[0] + 1 + p[1]) for p in points]
Beispiel #19
0
 def testRunGenerators2d(self):
     self.params['dimensions'] = [self.dim, self.dim]
     for i in self.imps:
         if i == 'poissongap':
             continue
         self.params['coordinateGenerator'] = i
         g = disp.getObject(self.params)
         points = g()
         [(p[0] + 1 + p[1]) for p in points]
Beispiel #20
0
 def testRunGenerators1d(self):
     self.params["dimensions"] = [self.dim]
     for i in self.imps:
         if i in ("poissondisk", "spiral", "radial"):
             continue
         self.params["coordinateGenerator"] = i
         g = disp.getObject(self.params)
         points = g()
         [(p[0] + 1) for p in points]
Beispiel #21
0
 def testRunSelectors3D(self):
     self.params['dimensions'] = [self.dim, self.dim, self.dim]
     for selector in self.Selectors3d:
         self.params['pointSelector'] = selector
         myselector = disp.getObject(self.params)
         qPointList = myselector(self.points3d, 0)
         points = qPointList.getPoints()
         qPointList.getMultiPhasePoints()
         qPointList.newInstance(points[1:14])
Beispiel #22
0
 def testRunGenerators1d(self):
     self.params['dimensions'] = [self.dim]
     for i in self.imps:
         if i in ('poissondisk', 'spiral', 'radial'):
             continue
         self.params['coordinateGenerator'] = i
         g = disp.getObject(self.params)
         points = g()
         [(p[0] + 1) for p in points]
Beispiel #23
0
    def __init__(self):
	super(AgentClient, self).__init__()
        self.config = AgentClientConfig()
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.ip_addr = self.config.server_ip
        self.port = self.config.server_port
        self.receiver = MessageReceiver(self.sock)
        self.handler = ScanMessageHandler()
        self.connection = ClientConnection(self, self.sock, self.ip_addr)
        self.checker = HeartBeatChecker(self.connection, self.config.heartbeat_interval)
        self.epoll = select.epoll()
        self.dispatch_queue = Queue.Queue()
        self.dispatcher = Dispatcher(self.dispatch_queue)
Beispiel #24
0
    def connect(self):
        self.listenThread = ListenThread(self.socket, self)

        try:
            self.socket.connect((self.host, self.port))
        except Exception as e:
            print "error connecting, aborting", e.args
            return

        self.connected = True

        self.listenThread.start()

        self.socket.send("NICK %s\r\n" % self.nick)
        self.socket.send("USER flossbot %s Bototo :Floss-PA Bot\r\n" % self.host)

        self.dispatcher = Dispatcher(self)

        listener = Listener(IRC_MSG, self.dispatcher.recvIRCMsg)
        getEventManager().addListener(listener)

        listener2 = Listener(IRC_SEND, self.send)
        getEventManager().addListener(listener2)
Beispiel #25
0
    def __init__(self, config=ServerConfig()):
        threading.Thread.__init__(self)
        self.config = config
        self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        server_addr = (self.config.bind_addr, self.config.bind_port)
        self.socket.bind(server_addr)
        self.queue = Queue.Queue()
        self.dispatcher = Dispatcher(self.queue)
        self.epoll = select.epoll()
        self.connections = {}
	self.machines = {}
	self.listeners = []
        self.clientConnections = []
        self.connectionMonitor = ConnectionMonitor(self.config.interval, self, self.clientConnections)
Beispiel #26
0
    def run(self, args):
        initData = Ice.InitializationData()
        initData.properties = self.createTestProperties(args)

        #
        # Limit the send buffer size, this test relies on the socket
        # send() blocking after sending a given amount of data.
        #
        initData.properties.setProperty("Ice.TCP.SndSize", "50000")
        d = Dispatcher.Dispatcher()
        initData.dispatcher = d.dispatch

        with self.initialize(initData=initData) as communicator:
            AllTests.allTests(self, communicator)

        Dispatcher.Dispatcher.terminate()
Beispiel #27
0
def _runRep(status):
    # Setup and start the simulation
    env = simpy.Environment()

    #make emergency responder resources
    #ems = Dispatcher.SimpleDispatcher(env, makeResponders(env, STATION, NUM_AMB, status), status)
    ems = Dispatcher.SimpleDispatcher(
        env, makeResponders(env, STATION, NUM_AMB, status), status)
    calls = IncidentGenerator.IncidentGenerator(env, ems, TBA, SIM_DURATION,
                                                END_BUFFER, HOSPITAL, status)

    horizBar = "----------------------------------------------------------------------"
    if (status):
        print(horizBar)

    #run simulation
    #env.run(until=SIM_DURATION)
    env.run()

    #print incident summary table
    if (status):
        print(horizBar)

    #analysis
    columns = ["D1", "D2", "D3", "D4"]

    analysis = Analyzer.Analyzer(["D1", "D2", "D3", "D4"])

    tempDict = dict()

    for inc in calls.incidentList:
        if (status):
            print(inc.toString())
        incTimes = inc.getTimesList()
        analysis.addData(incTimes.difList)
        tempDict.update({
            len(tempDict):
            {col: incTimes.difList[i]
             for i, col in enumerate(columns)}
        })

    analysis.run(status)

    return ([i.mea for i in analysis.stats])
Beispiel #28
0
    def _processResults(
            self,
            journalName,
            resultsE,  # ElementTree of results
            results,  # raw return from eutils search
    ):
        """ Process the results of the search.
	    For each article in the results, 
		parse the XML and pull out relevant bits.
		Skip the article if it not of the right type.
		Write out the requested files (xml, text, pdf)
	"""
        self.dispatcher = Dispatcher.Dispatcher(maxProcesses=5)
        self.cmdIndexes = []
        self.cmds = []
        self.articles = []

        for i, artE in enumerate(resultsE.findall('article')):

            # fill an article record with the fields we care about
            art = PMCarticle()
            art.journal = journalName
            art.type = artE.attrib['article-type']

            artMetaE = artE.find("front/article-meta")

            art.pmcid = artMetaE.find("article-id/[@pub-id-type='pmc']").text
            art.pmid = artMetaE.find("article-id/[@pub-id-type='pmid']")
            if art.pmid == None:
                #print "Cannot find PMID for PMC %s, skipping" % str(art.pmcid)
                self.curReporter.gotNoPmid(art)
                continue
            art.pmid = artMetaE.find("article-id/[@pub-id-type='pmid']").text

            if not self._wantArticle(art): continue

            # write files
            if self.getPdf: self._queuePdfFile(art, artE)
            if self.getXml: self._writeXmlFile(art, artE)
            if self.getText: self._writeTextFile(art, artE)
        # To use dispatcher, would need to save PDF requests and submit them
        #  to a batch PDF method
        self._runPdfQueue()
        return
Beispiel #29
0
    def run(self, args):

        initData = Ice.InitializationData()
        initData.properties = self.createTestProperties(args)

        #
        # This test kills connections, so we don't want warnings.
        #
        initData.properties.setProperty("Ice.Warn.Connections", "0")

        #
        # Limit the recv buffer size, this test relies on the socket
        # send() blocking after sending a given amount of data.
        #
        initData.properties.setProperty("Ice.TCP.RcvSize", "50000")

        d = Dispatcher.Dispatcher()
        initData.dispatcher = d.dispatch

        with self.initialize(initData=initData) as communicator:
            communicator.getProperties().setProperty("TestAdapter.Endpoints",
                                                     self.getTestEndpoint())
            communicator.getProperties().setProperty(
                "ControllerAdapter.Endpoints", self.getTestEndpoint(num=1))
            communicator.getProperties().setProperty(
                "ControllerAdapter.ThreadPool.Size", "1")

            adapter = communicator.createObjectAdapter("TestAdapter")
            adapter2 = communicator.createObjectAdapter("ControllerAdapter")

            testController = TestI.TestIntfControllerI(adapter)

            adapter.add(TestI.TestIntfI(), Ice.stringToIdentity("test"))
            adapter.activate()

            adapter2.add(testController,
                         Ice.stringToIdentity("testController"))
            adapter2.activate()

            communicator.waitForShutdown()

        Dispatcher.Dispatcher.terminate()
    def __init__(self):

        self.ns_arguments = None
        self.dict_args_info = None
        self.str_orig_output_dir = None
        self.f_is_multi_job = False
        self.prog = "custom"

        # Retrieve and manage arguments
        self.func_manage_arguments()
        self.func_manage_output_dir()

        # Keeps tack of errors
        f_error_occured = False

        # Job dispatcher.
        self.dspr_cur = Dispatcher.func_make_job_runner(self.ns_arguments.str_job_system)

        # Get logging
        self.logr_job = self.func_make_job_logger()

        # Set in func_parse_jobs()
        self.str_possible_config_file = None
        self.llstr_sample_data = self.func_parse_jobs()

        # Check version
        self.version = None

        # If a resource config file is given,
        # the pipeline config file must be given
        if (self.ns_arguments.str_resource_config and
            not self.str_possible_config_file):
            self.logr_job.error("".join(["A pipeline config file must be used ",
                                         "to map resources from the Resource ",
                                         "Config file to the command. Please ",
                                         "use a pipeline config file."]))
            exit(996)
Beispiel #31
0
 def testBuildGenerators3d(self):
     self.params['dimensions'] = [self.dim, self.dim, self.dim]
     for i in ['hypertable', 'halton']:
         self.params['coordinateGenerator'] = i
         _ = disp.getObject(self.params)
Beispiel #32
0
if S == "Winter":
    season = 3
if S == "Spring":
    season = 4

menu = Menu(gui2.root2)
gui2.root2.config(menu=menu)
subMenu = Menu(menu)
menu.add_cascade(label="File", menu = subMenu)
subMenu.add_command(label = "Scenario 1 = Summer", command = doSummer)
subMenu.add_command(label = "Scenario 2 = Fall", command = doFall)
subMenu.add_command(label = "Scenario 3 = Winter", command = doWinter)
subMenu.add_command(label = "Scenario 4 = Spring", command = doSpring)
subMenu.add_separator()
subMenu.add_command(label = "Exit", command = closeWindow)

dispatcher1 = Dispatcher.Dispatcher()
dispatcher1.event_list = []
dispatcher1.current_time = 0

dispatcher1.add_events_from_lists(houses.house1.list_events)
dispatcher1.add_events_from_lists(houses.house2.list_events)
dispatcher1.add_events_from_lists(houses.house3.list_events)
dispatcher1.add_events_from_lists(houses.house4.list_events)

dispatcher1.run_dispatcher(houses.list_house,season)




Beispiel #33
0
class Irc:

    def __init__(self, host, port, channel, nick):
        self.host = host
        self.port = port
        self.channel = channel
        self.socket = socket.socket()
        self.socket.settimeout(5)
        self.connected = False

        self.nick = nick
        self.ops = []

        listener = Listener(IRC_RECV, self.parseIRCString)
        getEventManager().addListener(listener)

        self.connect()

    def connect(self):
        self.listenThread = ListenThread(self.socket, self)

        try:
            self.socket.connect((self.host, self.port))
        except Exception as e:
            print "error connecting, aborting", e.args
            return

        self.connected = True

        self.listenThread.start()

        self.socket.send("NICK %s\r\n" % self.nick)
        self.socket.send("USER flossbot %s Bototo :Floss-PA Bot\r\n" % self.host)

        self.dispatcher = Dispatcher(self)

        listener = Listener(IRC_MSG, self.dispatcher.recvIRCMsg)
        getEventManager().addListener(listener)

        listener2 = Listener(IRC_SEND, self.send)
        getEventManager().addListener(listener2)

    def disconnect(self):
        self.connected = False
        self.stop()
        self.socket = socket.socket()
        self.socket.settimeout(5)
        if self.listenThread and self.listenThread.is_alive():
            self.listenThread.join()
        self.listenThread = None
        self.dispatcher.stop_plugins()
        self.dispatcher = None

    def deleteOp(self, op):
        self.ops[:] = (value for value in self.ops if value != op)

    def parseIRCString(self, event):
        string = event.arg
        if string.find("PING") == 0:
            self.socket.send("PONG " + string[5:] + "\r\n")
            print "PONG", string[5:]
        elif string[0] == ":":
            print string
            info = string.split(" ")
            if info[1] == "MODE": #and info[2] == self.channel:
                if info[3] == "+o":
                    self.ops.append(info[4])
                elif info[3] == "-o":
                    self.deleteOp(info[4])
            elif info[2] == self.nick and (info[3] == "=" or info[3] == "@"): #and info[4] == self.channel:
                for op in info[5:]:
                    if len(op) == 0:
                        continue
                    op = op.replace(':', '')
                    if op[0] == "@":
                        self.ops.append(op[1:])
                print "Connection succesful"
            elif info[1] == "002":
                for to_join in self.channel:
                    self.socket.send("JOIN %s\r\n" % to_join)
            elif info[1] == "KICK" and info[3] == self.nick:
                self.socket.send("JOIN %s\r\n" % info[2])
            else: 
                event = Event(IRC_MSG, string)
                getEventManager().signalEvent(event)
        else:
            print "SCRAP", string
            if string == "ERROR :All connections in use":
                print "retrying in 5 seconds"
                self.disconnect()

                event = Event(IRC_RESTART, None)
                getEventManager().signalEvent(event)

    def send(self, event):
        message = event.arg
        self.socket.send(message)

    def stop(self):
        if self.listenThread:
            self.listenThread.stop()
            
    def getNick(self):
        return self.nick
Beispiel #34
0
 def testGetModuleDocs(self):
     modules = disp.getImplementingModules()
     for mod in modules:
         doc = mod.__doc__
         self.assertTrue(doc != None and doc != "",
                         "can't find module documentation")  #??
Beispiel #35
0
class AgentClient(threading.Thread):
    serverName = 'AgentClient'

    def __init__(self):
        super(AgentClient, self).__init__()
        self.config = AgentClientConfig()
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.ip_addr = self.config.server_ip
        self.port = self.config.server_port
        self.receiver = MessageReceiver(self.sock)
        self.handler = ScanMessageHandler()
        self.connection = ClientConnection(self, self.sock, self.ip_addr)
        self.checker = HeartBeatChecker(self.connection,
                                        self.config.heartbeat_interval)
        self.epoll = select.epoll()
        self.dispatch_queue = Queue.Queue()
        self.dispatcher = Dispatcher(self.dispatch_queue)

    #self.event_manager = EventManager()

    def getServerIp(self):
        return self.ip_addr

    def isCenterServer(self):
        return False

    def run(self):
        print "start serve"
        self.sock.connect((self.ip_addr, self.port))
        self.sock.setblocking(0)
        self.epoll.register(self.sock.fileno(), select.EPOLLOUT)
        self.connection.sendMachineInfo()

        try:
            while True:
                events = self.epoll.poll(2)
                for fileno, event in events:
                    if fileno != self.sock.fileno():
                        print "not current connection"
                        pass
                    elif event & select.EPOLLIN:
                        self.connection.receive()
                    elif event & select.EPOLLOUT:
                        self.connection.send()
                        self.epoll.modify(self.sock.fileno(), select.EPOLLIN)
                    else:
                        pass
        except:
            traceback.print_exc()
        finally:
            self.epoll.unregister(self.sock.fileno())
            self.epoll.close()
            self.sock.close()

    def start_other(self):
        if self.connection.last_read_time == 0:
            self.connection.last_read_time = int(time.time())
        task = Task(
            self.checker,
            self.connection.last_read_time + self.config.heartbeat_interval)
        self.checker.enqueue(task)
        self.checker.start()

        self.dispatcher.start()

        #daemon_thread = threading.Thread(target=self.serve())
        #daemon_thread.start()

        #self.event_manager.genForCurrent()

    def enqueue(self, message):
        self.dispatch_queue.put(message)
class MainHandler(tornado.websocket.WebSocketHandler):
    dispatcher = Dispatcher.Dispatcher()
    #timer = threading.Timer(1.0,dispatcher.run())
    users=set()
    user2room_id={}
    def broadcast(self, state):
        for i in self.users:
            i.write_message(str(state[self.user2room_id[i]]))
    def get_reply(self,r_json):
        if "poweron" in r_json:
            r_json = r_json['poweron']
            self.user2room_id[self] = r_json["room_id"]
            flag = self.dispatcher.create_service(r_json['room_id'],r_json['cur_temp'])
            if flag == 2:
                self.write_message(json.dumps({"poweron":"ok"}))
            elif flag == 1:
                self.write_message(json.dumps({"poweron":"busy"}))
            else:
                self.write_message(json.dumps({"poweron":"error"}))
            para = {
                    "setpara" : {
                    "mode" : Config.mode,
                    "target_temp" : Config.default_temp,
                    "highlimit_temp" : Config.max_temp,
                    "lowlimit_temp" : Config.min_temp,
                    "highfan_change_temp" : Config.FeeRate_H,
                    "lowfan_change_temp" : Config.FeeRate_L,
                    "medfan_change_temp": Config.FeeRate_M,
                    "fan" : Config.default_speed
                    }
                }
            return json.dumps(para)
        elif "poweroff" in r_json:
            r_json = r_json['poweroff']

            if self.dispatcher.delete_service(r_json['room_id']):
                return json.dumps({'poweroff':'ok'})
            else:
                return json.dumps({'poweroff':'fail'})
        elif "config" in r_json:
            r_json = r_json['config']
            if 'mode' in r_json:
                self.dispatcher.change_mode(r_json['room_id'],r_json['mode'])
            if 'target_temp' in r_json:
                self.dispatcher.change_temperature(r_json['room_id'],r_json['target_temp'])
            if 'fan' in r_json:
                print(r_json['fan'])
                self.dispatcher.change_fan_speed(r_json['room_id'],r_json['fan'])
                print(self.dispatcher.show_state())
                self.broadcast(self.dispatcher.show_state())
            return json.dumps({"config":"ok"})
        elif "temp_update" in r_json:
            r_json = r_json['temp_update']
            state = self.dispatcher.show_state()
            print(1,state)
            self.dispatcher.set_indoor_temp(r_json['room_id'],r_json['cur_temp'])
            state = self.dispatcher.show_state()
            print(2,state)
            self.dispatcher.dispatch()
            state = self.dispatcher.show_state()
            print(3,state)
            self.broadcast(state)
            return json.dumps({"finish":""})
        elif "server_config" in r_json:
            r_json = r_json['server_config']
            self.dispatcher.SetPara(
                r_json['Temp_lowLimit'],
                r_json['Temp_highLimit'],
                r_json['min_speed'],
                r_json['max_speed'],
                r_json['FeeRate_H'],
                r_json['FeeRate_M'],
                r_json['FeeRate_L']
                )
            return json.dumps({'server_config':'ok'})
        elif "CheckRoomState" in r_json:
            ret = self.dispatcher.check_room_state()
            return ret
        elif "startUp" in r_json:
            self.dispatcher.PowerON()
            return json.dumps({'startUp':'ok'})
        else:
            print("json format error")

    def check_origin(self, origin):
        return True

    def open(self):
        self.users.add(self)
        logging.info("A client connected.")
        self.write_message('server connected.')

    def on_close(self):
        self.users.remove(self)
        logging.info("A client disconnected")
        self.write_message('server disconnected.')

    def on_message(self, message):
        receive_json = json.loads(message)
        '''
        reply = {}
        reply['message'] = 'sucess:' + message
        reply['name'] = 'air condition'
        logging.info("message: {}".format(message))
        reply_json = json.dumps(reply)
        '''
        #reply_json = json.dumps(receive_json)
        reply_json = self.get_reply(receive_json)
        self.write_message(reply_json)
Beispiel #37
0
 def testGetModuleDocs(self):
     modules = disp.getImplementingModules()
     for mod in modules:
         doc = mod.__doc__
         self.assertTrue( doc != None and doc != "", "can't find module documentation")#??
Beispiel #38
0
 def testGetModules(self):
     modules = disp.getImplementingModules() 
     self.assertTrue(len(modules) > 0, "there are no modules implementing the interface")
Beispiel #39
0
from FSM import FSM
from MyTransitions import MyTransitions
from Actor import Actor
import Dispatcher

print("__name__ value: ", __name__)

actors = dict()
actions = ['tjäna', 'köpa', 'törstig', 'glad', 'trött']
dispatcher = Dispatcher.Dispatcher()


def main():

    trans = MyTransitions()
    fsm = {}
    for n in range(0, 4):
        fsm[n] = FSM([
            ("Sova", "Äta", 'hungrig', lambda x: x == trans.sova('hungrig')),
            ("Sova", "Umgås", 'glad', lambda x: x == trans.sova('glad')),
            ("Sova", "Jobba", 'tjäna', lambda x: x == trans.sova('tjäna')),
            ("Sova", "Dricka", 'törstig',
             lambda x: x == trans.sova('törstig')),
            ("Äta", "Sova", 'trött', lambda x: x == trans.ata('trött')),
            ("Äta", "Jobba", 'tjäna', lambda x: x == trans.ata('tjäna')),
            ("Äta", "Umgås", 'glad', lambda x: x == trans.ata('glad')),
            ("Umgås", "Äta", 'hungrig', lambda x: x == trans.umgas('hungrig')),
            ("Umgås", "Dricka", 'törstig',
             lambda x: x == trans.umgas('törstig')),
            ("Umgås", "Sova", 'trött', lambda x: x == trans.umgas('trött')),
            ("Jobba", "Sova", 'trött', lambda x: x == trans.jobba('trött')),
Beispiel #40
0
    def nevigation(self):
        self.req_ori = self.mesh[self.x][self.y].request()
        yield self.req_ori
        #print("Vehicle ", self.ID, " now at ", [self.x, self.y], " (Time: ", self.env.now, ")")

        dp.VID(self.Controller, self, self.Controller.AGV_disRuleV,
               self.Controller.routRule, self.Controller.Parameter)
        while True:
            if self.status != []:
                if self.status[0] == 1:
                    nextpos = [self.x, self.y + 1]
                elif self.status[0] == 2:
                    nextpos = [self.x, self.y - 1]
                elif self.status[0] == 3:
                    nextpos = [self.x - 1, self.y]
                elif self.status[0] == 4:
                    nextpos = [self.x + 1, self.y]
                if self.detect(self.mesh[nextpos[0]][nextpos[1]].users):
                    yield self.env.timeout(0)
                    if self.status == []:
                        nextpos = [self.x, self.y]
                    elif self.status[0] == 1:
                        nextpos = [self.x, self.y + 1]
                    elif self.status[0] == 2:
                        nextpos = [self.x, self.y - 1]
                    elif self.status[0] == 3:
                        nextpos = [self.x - 1, self.y]
                    elif self.status[0] == 4:
                        nextpos = [self.x + 1, self.y]

                self.Redet = False

                self.req_tar = self.mesh[nextpos[0]][nextpos[1]].request()

                self.redet.succeed()

                #self.req_ori.append(req_tar)
                yield self.req_tar | self.Waiting
                self.Waiting = self.env.event()
                self.wait.interrupt()
                if self.Redet:
                    #if False:
                    #self.Redet = False

                    if self.req_tar in self.mesh[nextpos[0]][nextpos[1]].users:
                        self.mesh[nextpos[0]][nextpos[1]].release(self.req_tar)
                    if self.req_tar in self.mesh[nextpos[0]][nextpos[1]].queue:
                        self.mesh[nextpos[0]][nextpos[1]].queue.remove(
                            self.req_tar)
                        #self.req_tar.pop(0)
                else:
                    self.Redet = False

                    for i in range(self.Controller.split):

                        yield self.env.timeout(1 / self.Controller.split)
                        if self.status != []:
                            self.moving(self.status[0])

                    #yield self.env.timeout(1)

                    self.mesh[self.x][self.y].release(self.req_ori)

                    self.x = nextpos[0]
                    self.y = nextpos[1]
                    self.req_ori = self.req_tar
                    if self.status != []:
                        self.status.pop(0)
                    #print("Vehicle ", self.ID, " now at ", [self.x, self.y], " (Time: ", self.env.now, ")")

            #AGV load job
            elif self.nextpath != 0:
                yield self.env.timeout(1)
                self.content = self.Goal
                self.content.position.out_buffer.release(self.content.out_req)
                self.Goal = 0
                self.content.position.out_num -= 1
                self.content.position.out_queue.remove(self.content)
                self.content.position = self
                self.path = self.nextpath
                self.status = self.path.direct
                self.nextpath = 0

            #AGV Unload job
            elif self.content != 0:
                yield self.env.timeout(1)
                self.content.Queue.succeed()

                self.Controller.IV_num += 1
                self.Controller.IV.append(self)
                self.Controller.Rtravel -= 1
                self.content = 0
                if self.Electricity > 1 / 20:
                    dp.VID(self.Controller, self, self.Controller.AGV_disRuleV,
                           self.Controller.routRule, self.Controller.Parameter)
                else:
                    self.Charging = True
                    self.Controller.IV_num -= 1
                    self.Controller.IV.remove(self)
                    self.path = sp([self.x, self.y], [self.Controller.Cstation.x\
                                        , self.Controller.Cstation.y]\
                                        , self.Controller.routRule, self.Controller.x-1\
                                        , self.Controller.y-1, self.Controller.BLOCK, self, self.Controller.Parameter)
                    self.status = self.path.direct
                    self.startIdle = self.Controller.Time
                    self.Idling = self.Controller.Time

            #Start Charging
            elif self.Charging:
                yield self.env.timeout(300)
                self.Electricity = 1
                self.Charging = False
                self.Controller.IV_num += 1
                self.Controller.IV.append(self)
            #Start Parking
            elif self.Parking:
                self.Parking = False
                self.Controller.IV_num += 1
                self.Controller.IV.append(self)
                self.content = 0
                #dp.VID(self.Controller, self, self.Controller.AGV_disRule, self.Controller.routRule, self.Controller.Parameter)
                self.startIdle = self.Controller.Time
                self.Idling = self.Controller.Time

            else:
                #dp.VID(self.Controller, self, self.Controller.AGV_disRuleV, self.Controller.routRule, self.Controller.Parameter)
                #yield self.env.timeout(1)
                if self.Electricity > 1 / 20:
                    yield self.env.timeout(1)
                else:
                    self.Charging = True
                    self.Controller.IV_num -= 1
                    self.Controller.IV.remove(self)
                    self.path = sp([self.x, self.y], [self.Controller.Cstation.x\
                                        , self.Controller.Cstation.y]\
                                        , self.Controller.routRule, self.Controller.x-1\
                                        , self.Controller.y-1, self.Controller.BLOCK, self, self.Controller.Parameter)
                    self.status = self.path.direct
                    self.startIdle = self.Controller.Time
                    self.Idling = self.Controller.Time
Beispiel #41
0
 def testBuildSelectors3D(self):
     self.params['dimensions'] = [self.dim, self.dim, self.dim]
     for selector in self.Selectors3d:
         self.params['pointSelector'] = selector
         disp.getObject(self.params)
Beispiel #42
0
    from os import sys, path
    sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))

import daemon
import Dispatcher

import logging
logger = logging.getLogger( __name__ )

logger.setLevel(logging.DEBUG)
fh = logging.FileHandler("/var/log/dispatcher.txt")
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fh.setFormatter(formatter)
logger.addHandler(fh)

daemonLogFile = open('/var/log/dispatcherLog.txt', 'w')
context = daemon.DaemonContext(
   files_preserve = [
      fh.stream,
   ],
    stdout = daemonLogFile,
    stderr = daemonLogFile
    )


logger.debug( "Before daemonizing." )
context.open()
logger.debug( "After daemonizing." )
with context:
   Dispatcher.go() 
Beispiel #43
0
 def testBuildSelectors1D(self):
     for selector in self.Selectors1d:
         self.params['pointSelector'] = selector
         disp.getObject(self.params)
Beispiel #44
0
        raise RuntimeError('test assertion failed')


def run(args, communicator):
    AllTests.allTests(communicator, False)
    return True


try:
    initData = Ice.InitializationData()
    initData.properties = Ice.createProperties(sys.argv)

    #
    # Limit the send buffer size, this test relies on the socket
    # send() blocking after sending a given amount of data.
    #
    initData.properties.setProperty("Ice.TCP.SndSize", "50000")

    d = Dispatcher.Dispatcher()
    initData.dispatcher = d.dispatch

    with Ice.initialize(sys.argv, initData) as communicator:
        status = run(sys.argv, communicator)
except:
    traceback.print_exc()
    status = False

Dispatcher.Dispatcher.terminate()

sys.exit(not status)
Beispiel #45
0
 def testGetModules(self):
     modules = disp.getImplementingModules()
     self.assertTrue(
         len(modules) > 0,
         "there are no modules implementing the interface")
Beispiel #46
0
class AgentClient(threading.Thread):
    serverName = 'AgentClient'
    def __init__(self):
	super(AgentClient, self).__init__()
        self.config = AgentClientConfig()
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.ip_addr = self.config.server_ip
        self.port = self.config.server_port
        self.receiver = MessageReceiver(self.sock)
        self.handler = ScanMessageHandler()
        self.connection = ClientConnection(self, self.sock, self.ip_addr)
        self.checker = HeartBeatChecker(self.connection, self.config.heartbeat_interval)
        self.epoll = select.epoll()
        self.dispatch_queue = Queue.Queue()
        self.dispatcher = Dispatcher(self.dispatch_queue)

        #self.event_manager = EventManager()

    def getServerIp(self):
        return self.ip_addr

    def isCenterServer(self):
	return False

    def run(self):
        print "start serve"
        self.sock.connect((self.ip_addr, self.port))
        self.sock.setblocking(0)
        self.epoll.register(self.sock.fileno(), select.EPOLLOUT)
	self.connection.sendMachineInfo()

        try:
            while True:
                events = self.epoll.poll(2)
                for fileno, event in events:
                    if fileno != self.sock.fileno():
                        print "not current connection"
                        pass
                    elif event & select.EPOLLIN:
                        self.connection.receive()
                    elif event & select.EPOLLOUT:
                        self.connection.send()
			self.epoll.modify(self.sock.fileno(), select.EPOLLIN)
                    else:
                        pass
        except:
            traceback.print_exc()
        finally:
            self.epoll.unregister(self.sock.fileno())
            self.epoll.close()
            self.sock.close()

    def start_other(self):
        if self.connection.last_read_time == 0:
            self.connection.last_read_time = int(time.time())
        task = Task(self.checker, self.connection.last_read_time + self.config.heartbeat_interval)
        self.checker.enqueue(task)
        self.checker.start()

        self.dispatcher.start()

        #daemon_thread = threading.Thread(target=self.serve())
        #daemon_thread.start()

        #self.event_manager.genForCurrent()


    def enqueue(self, message):
	self.dispatch_queue.put(message)
Beispiel #47
0
 def testBuildGenerators3d(self):
     self.params["dimensions"] = [self.dim, self.dim, self.dim]
     for i in ["hypertable", "halton"]:
         self.params["coordinateGenerator"] = i
         _ = disp.getObject(self.params)
Beispiel #48
0
 def testBuildSelectors3d(self):
     params = {'dimensions': [self.dim, self.dim, self.dim], 'specialHaltonPoints': 2000}
     for i in self.imps:
         params['forcedSelector'] = i
         _ = disp.getObject(params)
Beispiel #49
0
 def testBuildMappers1D(self):
     for mapper in self.mappers1d:
         self.params['quadratureMapper'] = mapper
         disp.getObject(self.params)
Beispiel #50
0
 def testBuildMappers3D(self):
     self.params['dimensions'] = [self.dim, self.dim, self.dim]
     for mapper in self.mappers3d:
         self.params['quadratureMapper'] = mapper
         disp.getObject(self.params)
Beispiel #51
0
    def map(self, function_to_apply, list_of_objects_to_calculate, index_of_slowest_calculation = -1, time_multiplier_worst_case = 6.0, memory_multiplier_worst_case = 1.2):
        "Use the cluster pool to map a function called calculate() on every member of the supplied list"

        self.list_of_objects_to_calculate = list_of_objects_to_calculate

        self.slowest_calculation = self.list_of_objects_to_calculate[index_of_slowest_calculation]

        self.my_function_to_apply = function_to_apply

        print "testing time and memory requirements..."
        self.slowest_calculation_completed = None

        start_time = time.time()

        if self.TEST_MODE:
            self.slowest_calculation_completed =self.slowest_calculation.calculate_safely()
        else:
            self.slowest_calculation_completed =self.slowest_calculation.calculate()
        self.slowest_time_elapsed_s = time.time() - start_time
        process_completion_time_to_request_minutes = ( time_multiplier_worst_case * self.slowest_time_elapsed_s ) / 60.0
        process_memory_to_request_MB = memory_multiplier_worst_case * self.peak_memory_usage_megabytes()

        number_of_processes_per_trawler = int(math.ceil(Pool.TARGET_PROCESS_TIMES_MINUTES / process_completion_time_to_request_minutes))
        number_of_trawlers_to_create = int(math.ceil(float(len(list_of_objects_to_calculate) / number_of_processes_per_trawler)))
        number_of_trawlers_to_create = max([number_of_trawlers_to_create, Pool.MINIMUM_NUMBER_TRAWLERS])

        print "done!  child processes will request %s MB of RAM and %s minutes per core" % (str(process_memory_to_request_MB), str(process_completion_time_to_request_minutes)  )

        print "creating dispatcher"
        my_dispatcher = Dispatcher.return_appropriate_dispatcher_object(self.cluster_dispatcher_type)(process_completion_time_to_request_minutes, process_memory_to_request_MB)

        process_id_to_list_index_dict = {}
        unfinished_process_ids = []

        calculated_objects = []
        print("creating saved objects")
        for i, obj in enumerate(list_of_objects_to_calculate):
            calculated_objects.append(None)
            if i == index_of_slowest_calculation or i == (index_of_slowest_calculation + len(self.list_of_objects_to_calculate)):
                continue
            new_id = my_dispatcher.save_python_object_file_return_id(obj)
            process_id_to_list_index_dict[new_id] = i
            unfinished_process_ids.append(new_id)

        calculated_objects[index_of_slowest_calculation] = self.slowest_calculation_completed

        print("Spawning Trawlers")
        my_dispatcher.start_subprocess_trawlers(number_of_trawlers_to_create)

        myTrawler = Trawler.Trawler(my_dispatcher.file_directory(), number=-1, TEST_MODE = self.TEST_MODE, IGNORE_MUTEX=True)

        total_completed_calculations = 1
        loop_count = 0

        # time.sleep(5)
        print("checking for finished calculations...")
        while len(unfinished_process_ids) > 0:
            time.sleep(5)
            try:
                myTrawler.find_and_complete_calculation()

            except Trawler.noMoreFilesToCalculate:
                pass

            loop_count = loop_count + 1

            #check for completed processes
            for process_id in unfinished_process_ids:
                try:
                    calc_obj = my_dispatcher.return_calculated_object(process_id)
                    calculated_objects[process_id_to_list_index_dict[process_id]] = calc_obj
                    unfinished_process_ids.remove(process_id)
                    my_dispatcher.delete_all_temp_files(process_id)

                    total_completed_calculations += 1
                    print("%i finished!" % total_completed_calculations)
                    continue

                except:

                    continue
            #TODO: add trawler re-start for killed processes

        my_dispatcher.kill_dispatcher()
        return calculated_objects
Beispiel #52
0
from tkinter import *
from Dispatcher import *
import tkinter as tk
import sys

# New Instance Of Dispatcher Class
D = Dispatcher()


# Class to make Gui
class Gui(Frame):
    def __init__(self, master=None):
        Frame.__init__(self, master)

        self.master = master
        self.init_window()

    def init_window(self):
        self.master.title("Dispatcher Simulation (by Cameron Norman)")
        self.pack(fill=BOTH, expand=1)

        # buttons creation and configuration
        populate_queues_button = Button(
            self,
            text="Populate Ready Queue \nand Blocked List",
            fg="black",
            bg="#4682B4",
            command=D.populateReadyQueue)
        populate_queues_button.place(relx=0.8, rely=0.15, anchor=CENTER)
        populate_queues_button.config(height=4, width=20)