From e3361e948292f8afdd22885abc18ad5151f87950 Mon Sep 17 00:00:00 2001 From: alban Date: Sun, 27 Sep 2020 10:37:52 +0200 Subject: [PATCH] [enh] adds a tunnel generator and a null output --- clitools/exports/toNull.py | 46 ++++++++++++++ clitools/generators/tunnel.py | 111 ++++++++++++++++++++++++++++++++++ 2 files changed, 157 insertions(+) create mode 100755 clitools/exports/toNull.py create mode 100644 clitools/generators/tunnel.py diff --git a/clitools/exports/toNull.py b/clitools/exports/toNull.py new file mode 100755 index 0000000..08b4dfc --- /dev/null +++ b/clitools/exports/toNull.py @@ -0,0 +1,46 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- +# -*- mode: Python -*- + + +''' + +The exporter that drops all traffic ! +v0.1.0 + +A basic exporter + +LICENCE : CC + +by cocoa + + +''' +from __future__ import print_function +import sys +import os +import argparse +import redis +import time + +argsparser = argparse.ArgumentParser(description="Null exporter LJ") +argsparser.add_argument("-v","--verbose",action="store_true",help="Verbose") +args = argsparser.parse_args() + +verbose=args.verbose + +name = "exports::toNull" +def debug(*args, **kwargs): + if( verbose == False ): + return + print(*args, file=sys.stderr, **kwargs) + +try: + while True: + line = sys.stdin.readline() + if line == "": + time.sleep(0.01) + debug(name,"dumping: "+line) +except EOFError: + debug("break")# no more information + diff --git a/clitools/generators/tunnel.py b/clitools/generators/tunnel.py new file mode 100644 index 0000000..d9bd5df --- /dev/null +++ b/clitools/generators/tunnel.py @@ -0,0 +1,111 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- +# -*- mode: Python -*- + + +''' + +Woooh! I'm progressing in a tunnel ! +v0.1.0 + +Use it to test your filters and outputs + +LICENCE : CC + +by cocoa + +''' + +from __future__ import print_function +import time +import argparse +import sys +name="generator::tunnel" + +def debug(*args, **kwargs): + if( verbose == False ): + return + print(*args, file=sys.stderr, **kwargs) + + +argsparser = argparse.ArgumentParser(description="tunnel generator") +argsparser.add_argument("-x","--centerX",help="geometrical center X position",default=300,type=int) +argsparser.add_argument("-y","--centerY",help="geometrical center Y position",default=300,type=int) +argsparser.add_argument("-s","--speed",help="point per frame progress",default=3,type=int) +argsparser.add_argument("-i","--interval",help="point per form interval",default=30,type=int) +argsparser.add_argument("-m","--max-size",help="maximum size for objects",default=300,type=int) +argsparser.add_argument("-f","--fps",help="Frame Per Second",default=30,type=int) +argsparser.add_argument("-c","--color",help="Color",default=65280,type=int) +argsparser.add_argument("-v","--verbose",action="store_true",help="Verbose output") + +args = argsparser.parse_args() +color = args.color +fps = args.fps +centerX = args.centerX +centerY = args.centerY +interval = args.interval +max_size = args.max_size +speed = args.speed +verbose = args.verbose + +optimal_looptime = 1 / fps +square = [ + [-1,1], + [1,1], + [1,-1], + [-1,-1], + [-1,1] + ] + +class polylineGenerator( object ): + + def __init__( self ): + self.polylineList = [0] + self.buf = [] + + def draw( self ): + self.buf = [] + for it_pl, size in enumerate(self.polylineList): + for it_sqr, point in enumerate(square): + x = centerX + point[0]*size + y = centerY + point[1]*size + # Add an invisible point in first location + if 0 == it_sqr: + self.buf.append([x,y,0]) + self.buf.append([x,y,color]) + debug( name, "buf size:", str(len(self.buf)) ) + return self.buf + + def increment(self): + self.buffer = [] + min_size = 9999 + delList = [] + for i, size in enumerate(self.polylineList): + size += speed + if size < min_size : min_size = size + if size > max_size : delList.append(i) + self.polylineList[i] = size + for i in delList: + del self.polylineList[i] + if min_size >= interval: self.polylineList.append(0) + debug(name, "polyline:",self.polylineList) + +pgen = polylineGenerator() + + +while True: + start = time.time() + + # Generate + pgen.increment() + + # send + print(pgen.draw(), flush=True); + + + looptime = time.time() - start + if( looptime < optimal_looptime ): + time.sleep( optimal_looptime - looptime) + debug(name+" micro sleep:"+str( optimal_looptime - looptime)) + +