Exemplo n.º 1
0
    def persist(self, timestamp, buffer, bucket):
        def doit():
            count = bucket.interval.total_seconds() / self.config.buckets[0].interval.total_seconds()
            data = self.bucket_buffers[0].data
            mean = np.mean(list(zip(*data[-count:]))[1])
            buffer.push(timestamp, mean)

        threadpool.apply(doit)
Exemplo n.º 2
0
    def persist(self, timestamp, buffer, bucket):
        def doit():
            count = bucket.interval.total_seconds(
            ) / self.config.buckets[0].interval.total_seconds()
            data = self.bucket_buffers[0].data
            mean = np.mean(list(zip(*data[-count:]))[1])
            buffer.push(timestamp, mean)

        threadpool.apply(doit)
Exemplo n.º 3
0
	def cursor(self):
		threadpool = self._context.get("threadpool", gevent.get_hub().threadpool)
		methods = ("callproc", "close", "execute", "executemany",
			"fetchone", "fetchmany", "fetchall", "nextset", "setinputsizes", "setoutputsize")
		return type("CursorProxy", (Proxy,), {
			"_inner": threadpool.apply(self._inner.cursor, None, None),
			"_context": dict(self._context.items()+[("methods", methods),]) })()
Exemplo n.º 4
0
	def connect(self, *args, **kwargs):
		threadpool = self._context.get("threadpool", gevent.get_hub().threadpool)
		if self._context.get("single_thread_connection"):
			threadpool = gevent.threadpool.ThreadPool(1)
		methods = ("close", "commit", "rollback", "cursor")
		return type("ConnectionProxy", (ConnectionProxy,), {
			"_inner": threadpool.apply(self._inner.connect, args, kwargs),
			"_context": dict(self._context.items()+[("methods", methods), ("threadpool", threadpool)]) })()
Exemplo n.º 5
0
    def query(self, start, end, frequency):
        self.logger.debug('Query: start={0}, end={1}, frequency={2}'.format(start, end, frequency))
        buckets = list(self.config.get_covered_buckets(start, end))

        def doit():
            df = pd.DataFrame()

            for b in buckets:
                new = self.bucket_buffers[b.index].df
                if new is not None:
                    df = pd.concat((df, new))

            df = df.reset_index().drop_duplicates(subset='index').set_index('index')
            if len(buckets):
                df = df.sort()[0]
                df = df[start:end]
                df = df.resample(frequency, how='mean').interpolate()
            return df

        return threadpool.apply(doit)
Exemplo n.º 6
0
    def query(self, start, end, frequency):
        self.logger.debug('Query: start={0}, end={1}, frequency={2}'.format(
            start, end, frequency))
        buckets = list(self.config.get_covered_buckets(start, end))

        def doit():
            df = pd.DataFrame()

            for b in buckets:
                new = self.bucket_buffers[b.index].df
                if new is not None:
                    df = pd.concat((df, new))

            df = df.reset_index().drop_duplicates(
                subset='index').set_index('index')
            if len(buckets):
                df = df.sort()[0]
                df = df[start:end]
                df = df.resample(frequency, how='mean').interpolate()
            return df

        return threadpool.apply(doit)