Пример #1
0
	def __init__(self, app, dtype='float_', start_time=None, resolution=60, columns=15, clock_driven=False, id=None, config=None):
		self.Columns = columns
		if start_time is None:
			start_time = time.time()

		start = (1 + (start_time // resolution)) * resolution
		self.Start = start
		self.Resolution = resolution

		super().__init__(app, dtype=dtype, id=id, config=config)

		if clock_driven:
			advance_period = resolution / 4
			self.Timer = asab.Timer(app, self.on_clock_tick, autorestart=True)
			self.Timer.start(advance_period)
		else:
			self.Timer = None

		self.ClockDriven = clock_driven
		metrics_service = app.get_service('asab.MetricsService')
		self.Counters = metrics_service.create_counter(
			"EarlyLateEventCounter",
			tags={
				'matrix': self.Id,
			},
			init_values={
				'events.early': 0,
				'events.late': 0,
			}
		)
Пример #2
0
    def __init__(self, app, pipeline, id=None, config=None):
        super().__init__(app, pipeline, id=id, config=config)

        self.History = []
        self.HistorySize = self.Config['history_size']

        metrics_service = app.get_service('asab.MetricsService')

        self.DifferenceCounter = metrics_service.create_counter(
            "timedrift.difference",
            tags={},
            init_values={
                'positive': 0,
                'negative': 0
            })
        self.Gauge = metrics_service.create_gauge("timedrift",
                                                  tags={
                                                      'pipeline': pipeline.Id,
                                                  },
                                                  init_values={
                                                      "avg": 0.0,
                                                      "median": 0.0,
                                                      "stddev": 0.0,
                                                      "min": 0.0,
                                                      "max": 0.0,
                                                  })

        self.EventCount = 0
        self.SparseCount = int(self.Config['sparse_count'])

        self.Timer = asab.Timer(app, self.on_tick, autorestart=True)
        self.Timer.start(self.Config['stats_period'])

        self.App = app
Пример #3
0
	def __init__(self, app, interval=None, id=None):
		'''
		Interval is in seconds, can be a float or int.
		'''

		super().__init__(app, id)
		self.Timer = asab.Timer(app, self.on_timer, autorestart=True)
		self.Timer.start(interval)
Пример #4
0
	def __init__(self, app, pipeline, analyze_on_clock=False, id=None, config=None):
		super().__init__(app, pipeline, id=id, config=config)
		self.AnalyzePeriod = float(self.Config['analyze_period'])
		self.AnalyzeOnClock = analyze_on_clock

		if analyze_on_clock:
			self.Timer = asab.Timer(app, self.on_clock_tick, autorestart=True)
			app.PubSub.subscribe("Application.run!", self.start_timer)
		else:
			self.Timer = None
Пример #5
0
	def __init__(self, app, pipeline, analyze_on_clock=False, id=None, config=None):
		super().__init__(app, pipeline, id=id, config=config)
		self.AnalyzePeriod = float(self.Config['analyze_period'])
		self.AnalyzeOnClock = analyze_on_clock

		if analyze_on_clock:
			self.Timer = asab.Timer(app, self.on_clock_tick, autorestart=True)
			self.Timer.start(self.AnalyzePeriod)
		else:
			self.Timer = None
Пример #6
0
    def __init__(self,
                 app,
                 pipeline,
                 labels=None,
                 dimension=None,
                 start_time=None,
                 clock_driven=True,
                 time_windows=None,
                 id=None,
                 config=None):
        '''
		time_windows is dictionary with provided windows and labels.

		Labels are the names of multiple time windows, it should be an array of them. If labels are not specified,
		one time window will be created and labelled as self.TimeWindows['default'] and set self.TimeWindow as an alias.

		Dimension is an optional integer, specifying the length of 3rd dimension for all windows.

		Examples:
		a) labels=None, dimension=3 => one time window with shape (n, m, 3) will be created.
		b) labels=None, dimension=None => one time window with shape (n, m) will be created.
		c) labels=['1st', '2nd', '3rd'], dimension=None => 3 time windows with shapes (n_i, m_i) will be created.
		d) labels=['1st', '2nd', '3rd'], dimension=x => 3 time windows with shapes (n_i, m_i, x) will be
		created.
		'''

        super().__init__(app, pipeline, id, config)

        if (labels is not None) and (time_windows is not None):
            raise RuntimeError(
                "There cannot be labels and time_window specified at the same time"
            )

        if time_windows is None:
            self._create_time_windows(app,
                                      pipeline,
                                      labels=labels,
                                      dimension=dimension,
                                      start_time=start_time)
        else:
            if time_windows == {}:
                raise RuntimeError(
                    "time_windows cannot be an empty dictionary")

            self.TimeWindows = time_windows
            self.TimeWindow = list(self.TimeWindows.keys())[0]

        if clock_driven:
            self.Timer = asab.Timer(app, self._on_tick, autorestart=True)
            self.Timer.start(int(self.Config['resolution']) /
                             4)  # 1/4 of the sampling
        else:
            self.Timer = None
Пример #7
0
	def __init__(self, app, pipeline_id=None):
		super().__init__(app, pipeline_id)

		self.Timer = asab.Timer(self, self.on_tick, autorestart=True)
		self.Timer.start(1)

		self.build(
			bspump.http.HTTPClientSource(app, self, config={
				'url': 'https://api.coindesk.com/v1/bpi/currentprice.json'
			}).on(bspump.trigger.PeriodicTrigger(app, 5)),
			bspump.common.JsonBytesToDictParser(app, self),
			HTTPDelayProcessor(app, self),
			SleepProcessor(app, self),
			bspump.common.NullSink(app, self)
		)
Пример #8
0
    def __init__(self,
                 app,
                 matrix_id=None,
                 dtype='float_',
                 on_clock_update=False,
                 id=None,
                 config=None,
                 lazy=False):

        super().__init__(app, id=id, config=config, lazy=lazy)
        self.Indexes = {}

        svc = app.get_service("bspump.PumpService")
        if matrix_id is None:
            s_id = self.Id + "Matrix"
            self.Matrix = SessionMatrix(app, dtype, id=s_id)
            svc.add_matrix(self.Matrix)
        else:
            self.Matrix = svc.locate_matrix(matrix_id)

        self.MatrixPubSub = None
        self.Timer = None

        self.Target = None

        if self.is_master():
            if on_clock_update:
                self.UpdatePeriod = float(self.Config['update_period'])
                self.Timer = asab.Timer(app,
                                        self._on_clock_tick,
                                        autorestart=True)
                self.Timer.start(self.UpdatePeriod)

            else:
                self.MatrixPubSub = self.Matrix.PubSub
                self.MatrixPubSub.subscribe("Matrix changed!",
                                            self._on_matrix_changed)
Пример #9
0
	def __init__(self, app, pipeline, column_formats, column_names, id=None, config=None):
		super().__init__(app, pipeline, column_formats, column_names, id, config)
		self.AnalyzeTimer = asab.Timer(app, self._on_tick_analyze, autorestart=True)
		self.AnalyzeTimer.start(3)