How to use outcome - 10 common examples

To help you get started, we’ve selected a few outcome examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dssg / cincinnati / model / features / featurebot.py View on Github external
#Get existing tables
    existing_tables =  tables_in_schema(schema)
    
    # set the search path, otherwise won't find ST_DWithin()
    cur = con.cursor()
    cur.execute("SET search_path TO {schema}, public;".format(schema=schema))

    # make a new table that contains one row for every parcel in Cincinnati
    # this table has three columns: parcel_id, inspection_date, viol_outcome
    # inspection_date is the one given as a parameter and
    # is the same for all parcels
    if 'parcels_inspections' not in existing_tables:
        logger.info('Creating parcels_inspections table...')

        if inspection_date is None:
            inspections = outcome.generate_labels()
        else:
          if insp_set=='all_inspections':
            inspections = outcome.make_fake_inspections_all_parcels_cincy(inspection_date)
          elif insp_set=='field_test':
            inspections = outcome.load_inspections_from_field_test(inspection_date)

        inspections.to_sql("parcels_inspections", engine, chunksize=50000,
                      if_exists='fail', index=False, schema=schema)
        logging.debug("... table has {} rows".format(len(inspections)))
        #Create an index to make joins with events_Xmonths_* tables faster
        cur.execute('CREATE INDEX ON parcels_inspections (parcel_id);')
        cur.execute('CREATE INDEX ON parcels_inspections (inspection_date);')
        cur.execute('CREATE INDEX ON parcels_inspections (parcel_id, inspection_date);')
        con.commit()
    else:
        logger.info('parcels_inspections table already exists, skipping...')
github dssg / cincinnati / model / features / featurebot.py View on Github external
cur.execute("SET search_path TO {schema}, public;".format(schema=schema))

    # make a new table that contains one row for every parcel in Cincinnati
    # this table has three columns: parcel_id, inspection_date, viol_outcome
    # inspection_date is the one given as a parameter and
    # is the same for all parcels
    if 'parcels_inspections' not in existing_tables:
        logger.info('Creating parcels_inspections table...')

        if inspection_date is None:
            inspections = outcome.generate_labels()
        else:
          if insp_set=='all_inspections':
            inspections = outcome.make_fake_inspections_all_parcels_cincy(inspection_date)
          elif insp_set=='field_test':
            inspections = outcome.load_inspections_from_field_test(inspection_date)

        inspections.to_sql("parcels_inspections", engine, chunksize=50000,
                      if_exists='fail', index=False, schema=schema)
        logging.debug("... table has {} rows".format(len(inspections)))
        #Create an index to make joins with events_Xmonths_* tables faster
        cur.execute('CREATE INDEX ON parcels_inspections (parcel_id);')
        cur.execute('CREATE INDEX ON parcels_inspections (inspection_date);')
        cur.execute('CREATE INDEX ON parcels_inspections (parcel_id, inspection_date);')
        con.commit()
    else:
        logger.info('parcels_inspections table already exists, skipping...')

    for feature in features_to_generate:
        logging.info("Generating {} features".format(feature.table))
        #Try generating features with the n_months argument
        try:
github dssg / cincinnati / model / features / featurebot.py View on Github external
# set the search path, otherwise won't find ST_DWithin()
    cur = con.cursor()
    cur.execute("SET search_path TO {schema}, public;".format(schema=schema))

    # make a new table that contains one row for every parcel in Cincinnati
    # this table has three columns: parcel_id, inspection_date, viol_outcome
    # inspection_date is the one given as a parameter and
    # is the same for all parcels
    if 'parcels_inspections' not in existing_tables:
        logger.info('Creating parcels_inspections table...')

        if inspection_date is None:
            inspections = outcome.generate_labels()
        else:
          if insp_set=='all_inspections':
            inspections = outcome.make_fake_inspections_all_parcels_cincy(inspection_date)
          elif insp_set=='field_test':
            inspections = outcome.load_inspections_from_field_test(inspection_date)

        inspections.to_sql("parcels_inspections", engine, chunksize=50000,
                      if_exists='fail', index=False, schema=schema)
        logging.debug("... table has {} rows".format(len(inspections)))
        #Create an index to make joins with events_Xmonths_* tables faster
        cur.execute('CREATE INDEX ON parcels_inspections (parcel_id);')
        cur.execute('CREATE INDEX ON parcels_inspections (inspection_date);')
        cur.execute('CREATE INDEX ON parcels_inspections (parcel_id, inspection_date);')
        con.commit()
    else:
        logger.info('parcels_inspections table already exists, skipping...')

    for feature in features_to_generate:
        logging.info("Generating {} features".format(feature.table))
github Fuyukai / curious / curious / core / event / manager.py View on Github external
raise
            except Exception as e:
                # something bad happened, set exception and exit
                logger.exception("Exception in wait_for predicate!")
                # signal that an error happened
                await p.set(outcome.Error(e))
                raise ListenerExit
            else:
                # exit now if result is true
                if res is True:
                    await p.set(outcome.Value(args))
                    raise ListenerExit

        self.add_temporary_listener(name=event_name, listener=listener)
        try:
            output: outcome.Outcome = await p.wait()
        except Exception:  # cancellations or timeouts
            self.remove_listener_early(event_name, listener=listener)
            raise

        result = output.unwrap()

        # unwrap tuples, if applicable
        if len(result) == 1:
            return result[0]
        return result
github RazerM / sqlalchemy_aio / sqlalchemy_aio / trio.py View on Github external
def thread_fn(self):
        while True:
            try:
                request = self._portal.run(self._receive_from_trio.receive)
            except (Cancelled, RunFinishedError):
                break
            except trio.EndOfChannel:
                with suppress(Cancelled, RunFinishedError):
                    self._portal.run(self._send_to_trio.aclose)
                break

            response = outcome.capture(request)
            self._portal.run(self._send_to_trio.send, response)
github RazerM / sqlalchemy_aio / sqlalchemy_aio / asyncio.py View on Github external
def thread_fn(self):
        while True:
            fut = asyncio.run_coroutine_threadsafe(
                self._request_queue.get(), self._loop)
            try:
                request = fut.result()
            except CancelledError:
                continue

            if request is not _STOP:
                response = outcome.capture(request)
                fut = asyncio.run_coroutine_threadsafe(
                    self._response_queue.put(response), self._loop)
                fut.result()
            else:
                fut = asyncio.run_coroutine_threadsafe(
                    self._response_queue.put(None), self._loop)
                fut.result()
                break
github Fuyukai / curious / curious / core / event / manager.py View on Github external
async def listener(*args):
            # exit immediately if the predicate is none
            if predicate is None:
                await p.set(outcome.Value(None))
                raise ListenerExit

            try:
                res = predicate(*args)
                if inspect.isawaitable(res):
                    res = await res
            except ListenerExit:
                # ???
                await p.set(outcome.Value(args))
                raise
            except Exception as e:
                # something bad happened, set exception and exit
                logger.exception("Exception in wait_for predicate!")
                # signal that an error happened
                await p.set(outcome.Error(e))
                raise ListenerExit
github Fuyukai / curious / curious / core / event / manager.py View on Github external
if inspect.isawaitable(res):
                    res = await res
            except ListenerExit:
                # ???
                await p.set(outcome.Value(args))
                raise
            except Exception as e:
                # something bad happened, set exception and exit
                logger.exception("Exception in wait_for predicate!")
                # signal that an error happened
                await p.set(outcome.Error(e))
                raise ListenerExit
            else:
                # exit now if result is true
                if res is True:
                    await p.set(outcome.Value(args))
                    raise ListenerExit
github Fuyukai / curious / curious / core / event / manager.py View on Github external
async def listener(*args):
            # exit immediately if the predicate is none
            if predicate is None:
                await p.set(outcome.Value(None))
                raise ListenerExit

            try:
                res = predicate(*args)
                if inspect.isawaitable(res):
                    res = await res
            except ListenerExit:
                # ???
                await p.set(outcome.Value(args))
                raise
            except Exception as e:
                # something bad happened, set exception and exit
                logger.exception("Exception in wait_for predicate!")
                # signal that an error happened
                await p.set(outcome.Error(e))
                raise ListenerExit
            else:
                # exit now if result is true
                if res is True:
                    await p.set(outcome.Value(args))
                    raise ListenerExit
github Fuyukai / curious / curious / core / event / manager.py View on Github external
await p.set(outcome.Value(None))
                raise ListenerExit

            try:
                res = predicate(*args)
                if inspect.isawaitable(res):
                    res = await res
            except ListenerExit:
                # ???
                await p.set(outcome.Value(args))
                raise
            except Exception as e:
                # something bad happened, set exception and exit
                logger.exception("Exception in wait_for predicate!")
                # signal that an error happened
                await p.set(outcome.Error(e))
                raise ListenerExit
            else:
                # exit now if result is true
                if res is True:
                    await p.set(outcome.Value(args))
                    raise ListenerExit

outcome

Capture the outcome of Python function calls.

MIT OR Apache-2.0
Latest version published 6 months ago

Package Health Score

82 / 100
Full package analysis