コード例 #1
0
def createDataset(colStr, colName, matchValue):
    if 'df' in Brain.object_map(brain):
        df = brain['df']
        d = df.filter(regex=colStr).dropna(how='all').head(1000)
        if colName and matchValue:
            d = d[d[colName] == int(matchValue)]
        return d
    else:
        return pd.DataFrame()
コード例 #2
0
import pickle
import os
import time


# utilities
def show(t, task, method, code_string, n):
    print(' || '.join([
        str(x) for x in
        [round((time.time() - t) * 1000, 4), task, method, n, code_string]
    ]))


s = '--------'
mem, pic, bra = ('in-memory', 'pickle', 'brain-plasma')
brain = Brain()  # need at least 2GB
track = pd.DataFrame(columns=['task', 'method', 'time', 'round', 'code'])
i = 0

print(s, '\nSaving large objects - 10,000,000x10 DataFrame of integers', s)
task = 'save large'

method = mem
code = 'x = 5'
for n in [1, 2, 3]:
    start = time.time()
    x = 5
    show(start, task, method, code, n)
    track.loc[i] = [
        task, method,
        round((time.time() - start) * 1000, 4), n, code
コード例 #3
0
from brain_plasma import Brain
import json
import pandas as pd
import numpy as np
import os

# create a Brain with a store running
print('starting plasma_state')

# start the plasma_store at 
path = '/tmp/brain_plasma_test'
brain = Brain(path=path)

# create python objects
a = dict(this=[1,2,3,4],that=[2,3,4,5])
b = 'this is a string'
c = b'this is a byte string'
d = ['this','is','a','list']
e = json.dumps(a)
f = set([1,2,3,4,5])
g = None
h = (3,4,5)
def i(name):
    print(name)
j = 5
k = str
for thing,name in zip([a,b,c,d,e,f,g,h,i,j,k],[i for i in 'abcdefghijk']):
    brain.learn(name,thing)

# read python object
assert a==brain.recall('a')
コード例 #4
0
ファイル: table.py プロジェクト: henrywiechert/yacvis
from app import app
import dash_core_components as dcc
import dash_html_components as html
import dash_table
from dash.dependencies import Input, Output, State
import pandas as pd
from brain_plasma import Brain
import plotly.express as px
import dash_bootstrap_components as dbc
import plotly.graph_objects as go

brain = Brain()


def get_country_df_cases(country):
    df = brain['df_covid_cases'].tail(1).T
    if not country:
        return df
    else:
        return df.filter(country, axis=0)


def get_data_cases(country):
    df = brain['df_covid_cases']
    return df[country]


def get_data_frame_cases():
    df = brain['df_covid_cases']
    return df
コード例 #5
0
def brain():
    """Brain with mocked plasma_store client"""
    return Brain(ClientClass=MockPlasmaClient)
コード例 #6
0
def test_init_other():
    test = Brain(namespace="nondefault", ClientClass=MockPlasmaClient)
    assert test.namespace == "nondefault"
コード例 #7
0
ファイル: many_vals.py プロジェクト: tebb/brain-plasma
import time
import uuid

from brain_plasma.v02compatibility import Brain as v02Brain
from brain_plasma import Brain

brain = v02Brain(path="/tmp/brain")
hbrain = Brain(path="/tmp/hash-brain")
few = 10
many = 100
times = {few: {"old":{},'hash':{}}, many: {"old":{},'hash':{}}}

#################################################################
# few things
#################################################################
# make a few things
ids = [uuid.uuid1().hex for x in range(few)]

start = time.time()
sets = [brain.learn(ID, ID) for ID in ids]
times[few]['old']['learn'] = time.time()-start

start = time.time()
hsets = [hbrain.learn(ID, ID) for ID in ids]
times[few]['hash']['learn'] = time.time()-start

# test speed with a few things
start = time.time()
outs = [brain[ID] for ID in ids]
times[few]["old"]['recall'] = time.time() - start
start = time.time()