Example #1
0
 def __init__(self,
              console_path=CNSL_PLUGIN_PATH,
              find_cnsl=True,
              emitter_path=EMIT_PLUGIN_PATH,
              find_emitters=True,
              poll_interval=5,
              emit_interval=60):
     """Iterate over available PWS console plugins.  Once a plugin
     is found that returns a connection object from its discover method,
     create an instance of the discovered console.
     """
     #TODO Load config file
     self.poll_interval = poll_interval
     self.emit_interval = emit_interval
     self._obs = None
     self.db = Database()
     self.console = None
     self._console_path = console_path
     self.emitters = []
     self._emitter_path = emitter_path
     if find_cnsl:
         self.find_console()
     if find_emitters:
         self.find_emitters()
Example #2
0
 def __init__(self, console_path=CNSL_PLUGIN_PATH, find_cnsl=True, 
              emitter_path=EMIT_PLUGIN_PATH, find_emitters=True, 
              poll_interval=5, emit_interval=60):
     """Iterate over available PWS console plugins.  Once a plugin
     is found that returns a connection object from its discover method,
     create an instance of the discovered console.
     """
     #TODO Load config file
     self.poll_interval = poll_interval
     self.emit_interval = emit_interval
     self._obs = None
     self.db = Database()
     self.console = None
     self._console_path = console_path
     self.emitters = []
     self._emitter_path = emitter_path
     if find_cnsl:
         self.find_console()
     if find_emitters:
         self.find_emitters()
Example #3
0
import os

from flask import Flask, Response, request
from flask_cors import CORS
from threading import Thread
from mongo import Database
from player import Player, get_status
from settings import DB, DB_NAME, PROD_DB
from algo import explore, traverse_player_to_target

app = Flask(__name__)
CORS(app)

p = Player(get_status())
db = Database(DB, DB_NAME)
db_id = db.get_id()
atlas_db = Database(PROD_DB, DB_NAME)
atlas_id = atlas_db.get_id()

# MANUAL COMMANDS. ONLY RUN ONE AT A TIME
# print(p.dash('w', '7', '327,256,243,178,90,86,80'))
# print(f"{p.move('w')}")
# print(f"{p.wise_explore('s', 22)}")

# print(p.sell_item('nice jacket'))
# print(p.examine_item('amazing treasure'))
# print(p.examine_player('shiny treasure'))
# print(f"{p.take_item('shiny treasure')}")
# print(f"{p.drop_item('small treasure')}")
# print(p.pray())
# print(p.fly('s'))
Example #4
0
class Observer(object):
    def __init__(self, console_path=CNSL_PLUGIN_PATH, find_cnsl=True, 
                 emitter_path=EMIT_PLUGIN_PATH, find_emitters=True, 
                 poll_interval=5, emit_interval=60):
        """Iterate over available PWS console plugins.  Once a plugin
        is found that returns a connection object from its discover method,
        create an instance of the discovered console.
        """
        #TODO Load config file
        self.poll_interval = poll_interval
        self.emit_interval = emit_interval
        self._obs = None
        self.db = Database()
        self.console = None
        self._console_path = console_path
        self.emitters = []
        self._emitter_path = emitter_path
        if find_cnsl:
            self.find_console()
        if find_emitters:
            self.find_emitters()

    def find_console(self):
        """Look for available console."""
        plugin_manager = ObsPluginManager()
        plugin_manager.setPluginPlaces([self._console_path])
        plugin_manager.collectPlugins()

        for plugin in plugin_manager.getAllPlugins():
            logging.debug('Found potential console plugin: {0}'.format(plugin.plugin_object))
            if hasattr(plugin.plugin_object, 'discover'):
                logging.debug('Class {0} has discover method'.format(plugin.plugin_object))
                self.console = plugin.plugin_object.discover()
                if self.console is not None:
                    break

        if not self.console:
            logging.warning('No consoles found.')

    def find_emitters(self):
        """Look for available emitter plugins"""
        plugin_manager = ObsPluginManager()
        plugin_manager.setPluginPlaces([self._emitter_path])
        plugin_manager.collectPlugins()

        for plugin in plugin_manager.getAllPlugins():
            logging.debug('Found potential console plugin: {0}'.format(plugin.plugin_object))
            if hasattr(plugin.plugin_object, 'connect'):
                logging.debug('Class {0} has connect method'.format(plugin.plugin_object))
                emitter = plugin.plugin_object.connect()
                if emitter is not None:
                    self.emitters.append(emitter)

        if not self.emitters:
            logging.warning('No emitters found.')

    def _emit(self):
        while True:
            if self._obs is not None:
                obs = self._obs.as_dict()
                self.db.save(obs)
                for emitter in self.emitters:
                    emitter.send(obs)
                self._obs = None
                gevent.sleep(self.emit_interval)

    def _poll(self):
        """Start PWS monitor service"""
        while True:
            #TODO Apply filters to obersvation data
            #TODO Backfill and resume after connection failure
            if self._obs is None:
                ts = datetime.datetime.utcnow()
                obs = self.console.measure()
                self._obs = Observation(ts, obs, maxes=['wind_speed'])
            else:
                self._obs.update(self.console.measure())
            gevent.sleep(self.poll_interval)

    def start(self):
        threads = [gevent.spawn(self._poll),
                   gevent.spawn(self._emit)]
        print threads
        gevent.joinall(threads)
Example #5
0
class Observer(object):
    def __init__(self,
                 console_path=CNSL_PLUGIN_PATH,
                 find_cnsl=True,
                 emitter_path=EMIT_PLUGIN_PATH,
                 find_emitters=True,
                 poll_interval=5,
                 emit_interval=60):
        """Iterate over available PWS console plugins.  Once a plugin
        is found that returns a connection object from its discover method,
        create an instance of the discovered console.
        """
        #TODO Load config file
        self.poll_interval = poll_interval
        self.emit_interval = emit_interval
        self._obs = None
        self.db = Database()
        self.console = None
        self._console_path = console_path
        self.emitters = []
        self._emitter_path = emitter_path
        if find_cnsl:
            self.find_console()
        if find_emitters:
            self.find_emitters()

    def find_console(self):
        """Look for available console."""
        plugin_manager = ObsPluginManager()
        plugin_manager.setPluginPlaces([self._console_path])
        plugin_manager.collectPlugins()

        for plugin in plugin_manager.getAllPlugins():
            logging.debug('Found potential console plugin: {0}'.format(
                plugin.plugin_object))
            if hasattr(plugin.plugin_object, 'discover'):
                logging.debug('Class {0} has discover method'.format(
                    plugin.plugin_object))
                self.console = plugin.plugin_object.discover()
                if self.console is not None:
                    break

        if not self.console:
            logging.warning('No consoles found.')

    def find_emitters(self):
        """Look for available emitter plugins"""
        plugin_manager = ObsPluginManager()
        plugin_manager.setPluginPlaces([self._emitter_path])
        plugin_manager.collectPlugins()

        for plugin in plugin_manager.getAllPlugins():
            logging.debug('Found potential console plugin: {0}'.format(
                plugin.plugin_object))
            if hasattr(plugin.plugin_object, 'connect'):
                logging.debug('Class {0} has connect method'.format(
                    plugin.plugin_object))
                emitter = plugin.plugin_object.connect()
                if emitter is not None:
                    self.emitters.append(emitter)

        if not self.emitters:
            logging.warning('No emitters found.')

    def _emit(self):
        while True:
            if self._obs is not None:
                obs = self._obs.as_dict()
                self.db.save(obs)
                for emitter in self.emitters:
                    emitter.send(obs)
                self._obs = None
                gevent.sleep(self.emit_interval)

    def _poll(self):
        """Start PWS monitor service"""
        while True:
            #TODO Apply filters to obersvation data
            #TODO Backfill and resume after connection failure
            if self._obs is None:
                ts = datetime.datetime.utcnow()
                obs = self.console.measure()
                self._obs = Observation(ts, obs, maxes=['wind_speed'])
            else:
                self._obs.update(self.console.measure())
            gevent.sleep(self.poll_interval)

    def start(self):
        threads = [gevent.spawn(self._poll), gevent.spawn(self._emit)]
        print threads
        gevent.joinall(threads)