Exemplo n.º 1
0
    def __init__(self, bdb, meta_logger=None, session_logger=None):
        bayesdb_schema_required(bdb, 7, 'sessions')
        self.bdb = bdb

        if meta_logger is None:
            meta_logger = BqlLogger()
        self._logger = meta_logger
        if session_logger is None:
            session_logger = CallHomeStatusLogger()
        self._session_logger = session_logger

        self._qid_to_entry_id = {}
        self._sql_tracer = _SessionTracer("sql", self)
        self._bql_tracer = _SessionTracer("bql", self)
        self.start_saving_sessions()
        self._suggested_send = False
        self._start_new_session()
Exemplo n.º 2
0
    def __init__(self,
                 name,
                 csv_path=None,
                 bdb_path=None,
                 df=None,
                 logger=None,
                 session_capture_name=None):
        """Create a Population object, wrapping a bayeslite.BayesDB.

    name : str  REQUIRED.
        A name for the population, should use letters and underscores only.
        This will also be used as a table name in the bdb, and %t in queries
        will expand to this name. %g in queries will expand to the current
        population metamodel, also based on this name.
    csv_path : str
        The path to a comma-separated values file. If specified, will be used
        to populate the bdb. It must exist and be both readable and non-empty.
    df : pandas.DataFrame
        If specified, these data will be used to populate the bdb, superseding
        any csv_path. It must not be empty.
    bdb_path : str
        If specified, store data and analysis results here. If no other data
        source (csv or df) is specified, then it must already have been
        populated. If not specified, we will use a volatile in-memory bdb.
    logger : object
        Something on which we can call .info or .warn to send messages to the
        user. By default a bayeslite.loggers.BqlLogger, but could be QuietLogger
        (only results), SilentLogger (nothing), IpyLogger, CaptureLogger,
        LoggingLogger, or anything else that implements the BqlLogger interface.
    session_capture_name : String
        Signing up with your name and email and sending your session details
        to the MIT Probabilistic Computing Group helps build a community of
        support and helps improve your user experience. You can save your choice
        in a file called 'bayesdb-session-capture-opt.txt' in the directory
        where you run the software, or any parent directory. This option
        overrides any setting in such a file. Any string is interpreted as
        opting in to sending session details. False is interpreted as opting
        out. You must choose. If you choose to use an organization name or
        email, then please send a note to [email protected] to help us connect
        your sessions to you.

        If you encounter a bug, or something surprising, please include your
        session capture name in your report.

        If you opt out, you still allow us to count how often users opt out.

        DO NOT USE THIS SOFTWARE FOR HIPAA-COVERED, PERSONALLY IDENTIFIABLE,
        OR SIMILARLY SENSITIVE DATA! Opting out does not guarantee security.
    """
        Population.method_imports()
        assert re.match(r'\w+', name)
        assert df is not None or csv_path or bdb_path
        self.name = name
        self.generator_name = name + '_cc'  # Because we use the default metamodel.
        self.csv_path = csv_path
        self.df = df
        self.bdb_path = bdb_path
        if logger is None:
            if 'IPython' in sys.modules:
                from bdbcontrib.loggers import IPYTHON_LOGGER as ipy
                self.logger = ipy
            else:
                self.logger = BqlLogger()
        else:
            self.logger = logger
        self.bdb = None
        self.status = None
        self.session_capture_name = None
        self.generators = []
        with logged_query('count-beacon', None, name='count-beacon'):
            self.initialize_session_capture(session_capture_name)
        self.initialize()