コード例 #1
0
def setup_depends() -> Server:
    log = logging.getLogger("server.py")
    events = Events()
    discord_db = DiscordDatabase(
        log, events)  # TODO: a database per guild, so database factory
    discord_db.configure_event_handler("./.data/discord/messages.db")
    discord = DiscordClient(log, events)
    cmd_shutdown = ShutdownCommand(log, events, discord)
    discord.commands = [cmd_shutdown]
    server = Server(log, events, discord)
    return server
コード例 #2
0
class TestEvents:
    def setup(self):
        self.boto3_session = MagicMock()
        self.default = Events(boto3_session=self.boto3_session)
        self.subject = Events('slack', boto3_session=self.boto3_session)

    def test_bus_name(self):
        assert self.default.bus == 'default'
        assert self.subject.bus == 'slack'

    def test_publish(self):
        self.subject.publish('type', {'fizz': 'buzz'}, 'TRACE-ID')
        self.subject.boto3_session\
            .client.return_value\
            .put_events.assert_called_once_with(Entries=[{
                'Detail': json.dumps({'fizz': 'buzz'}),
                'DetailType': 'type',
                'EventBusName': 'slack',
                'Source': 'slack',
                'TraceHeader': 'TRACE-ID',
            }])
コード例 #3
0
    def run(self):
        """
        Main method.
        """
        if not is_valid_directory(self.input):
            raise RuntimeError("The input directory is missing")

        spark = get_session()
        # TODO: to support other output types a strategy pattern should be implemented
        #       based on the directory files and the correct type should be choosen via code.
        df = spark.read.json(self.input)

        df = Events(df).filter_column(self.column, self.values)
        count = df.count()
        if count == 0:
            logger.info("No Data!")

        # Partitioning column - this means that each day will have it's own graph.
        # TOOD: Consider differerent partitioning per graph - for example scatter graph
        df = df.withColumn(CSV_PARTITION_COLUMNS,
                           to_date(df.created_at, "yyyy-MM-dd"))

        # Datetime
        df = df.withColumn("hour", hour(df.created_at))

        df.createOrReplaceTempView("events")
        # Note: we don't need the events_percentage since any relevant chart (like pie) does the math on it's on.
        #       however, it is possible that this will be required for other future calculations that are better
        #       kept in the output file instead of calculating them upon request later on.
        df_results = spark.sql("""
            SELECT date, hour, count(hour) as events, count(hour)*100/{} AS `events_percentage`
            FROM events GROUP BY date, hour order by date, hour
            """.format(count))

        # Show the results for debugging
        if self.debug:
            df_results.show(df_results.count(), truncate=False)

        # TODO: if this operation becomes slow we can run it in a different process
        #       with the multiprocess lib
        Outputs(df_results, self.output).output_type(CSV)

        self.display_graph(df_results)
コード例 #4
0
ファイル: index.py プロジェクト: Para-chute/getaware
        '/?authSource=admin')

client = InfluxDBClient(host='influxdb', port=8086)


def json_error(status, message, traceback, version):
    cherrypy.response.headers['Content-Type'] = 'application/json'
    return json.dumps({'status': status, 'message': message})


if __name__ == '__main__':
    conf = {
        '/': {
            'request.dispatch': cherrypy.dispatch.MethodDispatcher(),
            'tools.response_headers.on': True,
            'tools.gzip.on': True,
            'error_page.default': json_error
        }
    }

    cherrypy.config.update({
        'server.socket_host': '0.0.0.0',
        'server.socket_port': 5000
    })

    cherrypy.tree.mount(Events(client), '/api/v1/events', conf)
    cherrypy.tree.mount(Groups(), '/api/v1/groups', conf)
    cherrypy.tree.mount(Devices(), '/api/v1/devices', conf)
    cherrypy.engine.start()
    cherrypy.engine.block()
コード例 #5
0
 def setup(self):
     self.boto3_session = MagicMock()
     self.default = Events(boto3_session=self.boto3_session)
     self.subject = Events('slack', boto3_session=self.boto3_session)
コード例 #6
0
import pygame

from src.init import Init
from src.Utilities.game_settings import GameSettings
from src.context import Context
from src.Utilities.colors import Colors
from src.events import Events

Init.initialise()

# init objects

# main game loop
while True:
    Init.clock.tick(GameSettings.FRAME_RATE)
    Init.gameDisplay.fill(Colors.BLACK)

    Events.event_control()

    # display objects

    pygame.display.update()
コード例 #7
0
ファイル: main.py プロジェクト: aritropaul/vlr.gg-scraper
async def events():
    """
    Gets all events from the VLR events page
    """
    events = Events()
    return events.events("")
コード例 #8
0
ファイル: main.py プロジェクト: aritropaul/vlr.gg-scraper
async def events(id):
    """
    Gets event details of the event with the given ID
    """
    events = Events()
    return events.event(id)
コード例 #9
0
ファイル: main.py プロジェクト: aritropaul/vlr.gg-scraper
async def events(region):
    """
    Gets all events in a particular region
    """
    events = Events()
    return events.events(region)