Ejemplo n.º 1
0
def load_data():

    if environ.get('REDIS_SERVER') is not None:
        redis_server = environ.get('REDIS_SERVER')
    else:
        redis_server = 'localhost'

    if environ.get('REDIS_PORT') is not None:
        redis_port = int(environ.get('REDIS_PORT'))
    else:
        redis_port = 6379

    if environ.get('REDIS_PASSWORD') is not None:
        redis_password = environ.get('REDIS_PASSWORD')
    else:
        redis_password = ''

    rdb = redis.Redis(host=redis_server,
                      port=redis_port,
                      password=redis_password)
    rb = RedisBloom(host=redis_server,
                    port=redis_port,
                    password=redis_password)
    rts = RedisTimeseries(host=redis_server,
                          port=redis_port,
                          password=redis_password)

    rdb.set("CONFIG", "YES")

    rts.create('s-unfiltered', retention_ms=60000)
    rts.create('s-filtered', retention_ms=60000)
    rts.create('unfiltered', labels={'Type': 'Final'}, retention_ms=86400000)
    rts.create('filtered', labels={'Type': 'Final'}, retention_ms=86400000)
    rts.createrule('s-unfiltered', 'unfiltered', 'last', 1000)
    rts.createrule('s-filtered', 'filtered', 'last', 1000)

    for gear in ['./dedup.py']:
        file = open(gear, mode='r')
        g = file.read()
        rdb.execute_command('RG.PYEXECUTE', g)
        file.close()

    if environ.get('REDIS_SCRABBLE') is not None:
        for line in fileinput.input("2019_Collins_Scrabble_Words.txt"):
            rb.bfAdd("Scrabble-Bloom", line.rstrip())
Ejemplo n.º 2
0
pool = redis.ConnectionPool(host=redis_host, port=redis_port)
r = redis.Redis(connection_pool=pool)

try:
    r.xadd("mystream", {'event_type': 'startup', 'user': '******'})
    r.xgroup_create("mystream", "consumerGroup", '$')
except:
    print("group already exists")

while True:
    msgs = r.xreadgroup("consumerGroup",
                        "consumerName",
                        streams={"mystream": '>'},
                        count=10,
                        block=1000,
                        noack=False)
    for msg in msgs:
        for m in msg[1]:
            evnt = m[1]['event_type']
            try:
                rts.info(evnt)
            except:
                rts.create(evnt, retentionSecs=60, labels={'event_type': evnt})
                rts.create(evnt + "_minute",
                           retentionSecs=0,
                           labels={'event_type': evnt})
                rts.createrule(evnt, evnt + "_minute", 'count', 60)

            rts.incrby(evnt, 1)
Ejemplo n.º 3
0
                'PRICETYPE':'INTRADAY',
                'COMPANYNAME': 'GOLDMAN_SACHS_GROUP'
            })

rts.create('DAILYRSI15MINRNG:GS',
            labels={
                'SYMBOL': 'GS',
                'DESC': 'RELATIVE_STRENGTH_INDEX',
                'INDEX': 'DJIA',
                'TIMEFRAME': '15_MINUTES',
                'AGGREGATION': 'RANGE',
                'INDICATOR': 'RSI',
                'COMPANYNAME': 'GOLDMAN_SACHS_GROUP'
            })
            # 900 = 60 seconds * 15 min
rts.createrule('DAILYRSI:GS','DAILYRSI15MINRNG:GS','range',900)

rts.create('INTRADAYPRICES15MINRNG:GS',
            labels={
                'SYMBOL': 'GS',
                'DESC': 'SHARE_PRICE',
                'INDEX': 'DJIA',
                'PRICETYPE':'RANGE',
                'AGGREGATION': 'RANGE',
                'DURATION': '15_MINUTES',
                'COMPANYNAME': 'GOLDMAN_SACHS_GROUP'
            })
rts.createrule('INTRADAYPRICES:GS','INTRADAYPRICES15MINRNG:GS','range',900)

rts.create('INTRADAYPRICES15MINSTDP:GS',
            labels={
Ejemplo n.º 4
0
               'SYMBOL': 'GS',
               'DESC': 'RELATIVE STRENGTH INDEX',
               'INDEX': 'DJIA',
               'TIMEFRAME': '15-MINUTES',
               'AGGREGATION': 'MAX',
               'INDICATOR': 'RSI',
               'COMPANYNAME': 'GOLDMAN_SACHS_GROUP'
           })

#
# The "createrule" will apply the range, first, last, min, and max aggregations
# on the Goldman Sachs' daily RSI values and stores the aggregated value in
# the respective time series that we created above.
# You can do similar aggregations on other stocks in the market.
#
rts.createrule('DAILYRSI:GS', 'DAILYRSI15MINRNG:GS', 'range', 900 * 1000)
rts.createrule('DAILYRSI:GS', 'DAILYRSI15MINFIRST:GS', 'first', 900 * 1000)
rts.createrule('DAILYRSI:GS', 'DAILYRSI15MINLAST:GS', 'last', 900 * 1000)
rts.createrule('DAILYRSI:GS', 'DAILYRSI15MINMIN:GS', 'min', 900 * 1000)
rts.createrule('DAILYRSI:GS', 'DAILYRSI15MINMAX:GS', 'max', 900 * 1000)

#
# A Redis TimeSeries for storing the intraday prices
# for Goldman Sachs' stock price
#
#
rts.create('INTRADAYPRICES:GS',
           labels={
               'SYMBOL': 'GS',
               'DESC': 'SHARE_PRICE',
               'INDEX': 'DJIA',