コード例 #1
0
    def setup(self):
        if RUN_NETWORK_TESTS:
            time.sleep(1) # Reduce test interdependence
        self.got_response = False
        self.got_timeout = False
        self.got_error = False
        self.found_nodes = False

        self.got_routing_response = False
        self.got_routing_error = False
        self.got_routing_timeout = False
        self.got_routing_nodes_found = False

        self.querier_mock = querier.QuerierMock(tc.CLIENT_ID)

        self.r = minitwisted.ThreadedReactor(task_interval=.01)
        self.rpc_m = rpc_manager.RPCManager(self.r,
                                            tc.CLIENT_ADDR[1])
        self.querier = querier.Querier(self.rpc_m,
                                            tc.CLIENT_NODE)
        self.querier_routing = querier.Querier(self.rpc_m,
                                               tc.CLIENT_NODE)
        self.querier_routing.set_on_response_received_callback(
            self.on_routing_response)
        self.querier_routing.set_on_error_received_callback(
            self.on_routing_error)
        self.querier_routing.set_on_timeout_callback(
            self.on_routing_timeout)
        self.querier_routing.set_on_nodes_found_callback(
            self.on_routing_nodes_found)
  
        self.r.start()
コード例 #2
0
    def setup(self):
        import rpc_manager
        global time

        time = minitwisted.time = querier.time = MockTime()

        self.got_response = False
        self.got_timeout = False
        self.got_error = False

        self.querier = querier.Querier(tc.CLIENT_ID)

        self.r = minitwisted.ThreadedReactor(task_interval=.01)
        self.rpc_m = rpc_manager.RPCManager(self.r)
        self.querier = querier.Querier(tc.CLIENT_NODE)
        self.r.start()
コード例 #3
0
 def setup(self):
     self.got_peers = None
     querier_ = querier.Querier(tc.CLIENT_ID)
     routing_m = RoutingManagerMock()
     self.bootstrap_nodes = routing_m.get_closest_rnodes(tc.INFO_HASH_ZERO)
     self.lm = lookup_manager.LookupManager(tc.CLIENT_ID, querier_,
                                            routing_m, 2)
     self.lookup = self.lm.get_peers(tc.INFO_HASH, self._on_got_peers,
                                     tc.BT_PORT)
コード例 #4
0
    def setup(self):
        time.mock_mode()

        self.controller = controller.Controller(PYMDHT_VERSION, tc.CLIENT_NODE,
                                                'test_logs/state.dat',
                                                routing_m_mod, lookup_m_mod,
                                                exp_m_mod, None)
        self.my_id = self.controller._my_id
        self.querier2 = querier.Querier()  #self.my_id)
        self.servers_msg_f = message.MsgFactory(PYMDHT_VERSION, tc.SERVER_ID)
コード例 #5
0
# Authors: Thierry Moudiki
#
# License: BSD 3

import pandas as pd
import querier as qr

# Import data -----

url = ('https://raw.github.com/pandas-dev'
       '/pandas/master/pandas/tests/data/tips.csv')
df = pd.read_csv(url)

# Example 1 -----

qrobj = qr.Querier(df=df)

df1 = qrobj\
.select(req="tip, sex, smoker, time")\
.filtr(req="smoker == 'No'")\
.summarize(req="sum(tip), sex, time", group_by="sex, time")\
.df

print(df1)

# Example 2 -----

df2 = qr.Querier(df)\
.select(req='tip, sex, day,size')\
.filtr(req="(day == 'Sun') | (day == 'Sat')")\
.summarize(req="avg(tip), sex, day", group_by="sex, day")\
コード例 #6
0
def corrtarget_encoder(df, target, rho=0.4, verbose=1, seed=123):
    """ Encode non-numerical columns using correlations.
   
       Parameters
       ----------
       df: a data frame
           a data frame
       
       target: str
           target column a.k.a response
       
       rho: float
           correlation between pseudo target (used for averaging) and target
           
       verbose: int
           currently 0 = nothing printed; 1 = progress bar printed
       
       seed: int
           reproducibility seed
       
       Returns
       --------
       a tuple: numerical data frame and achieved correlation
   
    """

    target_ = df[target].values
    target_mean = target_.mean()
    target_std = target_.std()
    n_target = len(target_)

    C = np.eye(2)
    C[0, 1] = rho
    C[1, 0] = rho
    C_ = np.linalg.cholesky(C).T

    np.random.seed(seed)
    temp = np.vstack((target_, np.random.normal(size=n_target))).T
    df_ = pickle.loads(pickle.dumps(df, -1))
    df_["pseudo_target"] = target_mean + np.dot(temp, C_)[:, 1] * target_std

    covariates_names = df.columns.values[df.columns.values != target].tolist()
    X = qr.select(df, ", ".join(covariates_names))
    X_dtypes = X.dtypes
    X_numeric = pickle.loads(pickle.dumps(df, -1))

    col_iterator = covariates_names if verbose == 0 else tqdm(covariates_names)

    for col in col_iterator:

        if X_dtypes[col] == np.object:  # something like a character string

            X_temp = qr.summarize(df_,
                                  req=col + ", avg(pseudo_target)",
                                  group_by=col)
            levels = np.unique(qr.select(X, col).values)

            for l in levels:

                qrobj = qr.Querier(X_temp)

                val = np.float(
                    qrobj.filtr(col + '== "' + l +
                                '"').select("avg_pseudo_target").df.values)

                X_numeric = qr.setwhere(X_numeric,
                                        col=col,
                                        val=l,
                                        replace=val,
                                        copy=False)

        else:  # a numeric column

            X_numeric[col] = X[col]

    return (
        X_numeric,
        np.corrcoef(df[target].values, df_["pseudo_target"].values)[0, 1],
    )
コード例 #7
0
#
# License: BSD 3

import pandas as pd
import querier as qr
import sqlite3
import sys

# data -----

url = ('https://raw.github.com/pandas-dev'
       '/pandas/master/pandas/tests/data/tips.csv')

# Example 1 - Import from csv -----

qrobj1 = qr.Querier(source=url)

df1 = qrobj1\
.select(req="tip, sex, smoker, time")\
.filtr(req="smoker == 'No'")\
.summarize(req="sum(tip), sex, time", group_by="sex, time")\
.df

print(df1)

# Example 2 - Import from sqlite3 -----

# an sqlite3 database  connexion
con = sqlite3.connect('people.db')

with con: