示例#1
0
def event_based(job_id, units, containers, params):
    """
    Celery task for the event based risk calculator.

    :param job_id: the id of the current
        :class:`openquake.engine.db.models.OqJob`
    :param dict units:
      A list of :class:`openquake.risklib.workflows.CalculationUnit` instances
    :param containers:
      An instance of :class:`..writers.OutputDict` containing
      output container instances (e.g. a LossCurve)
    :param params:
      An instance of :class:`..base.CalcParams` used to compute
      derived outputs
    """

    def profile(name):
        return EnginePerformanceMonitor(
            name, job_id, event_based, tracing=True)

    # Do the job in other functions, such that they can be unit tested
    # without the celery machinery
    event_loss_tables = dict()

    with db.transaction.commit_on_success(using='reslt_writer'):
        for unit in units:
            event_loss_tables[unit.loss_type] = do_event_based(
                unit,
                containers.with_args(loss_type=unit.loss_type),
                params, profile)
    num_items = base.get_num_items(units)
    signal_task_complete(job_id=job_id,
                         num_items=num_items,
                         event_loss_tables=event_loss_tables)
示例#2
0
def scenario(job_id, units, containers, _params):
    """
    Celery task for the scenario risk calculator.

    :param int job_id:
      ID of the currently running job
    :param list units:
      A list of :class:`openquake.risklib.workflows.CalculationUnit` instances
    :param containers:
      An instance of :class:`..writers.OutputDict` containing
      output container instances (in this case only `LossMap`)
    :param params:
      An instance of :class:`..base.CalcParams` used to compute
      derived outputs
    """
    def profile(name):
        return EnginePerformanceMonitor(name, job_id, scenario, tracing=True)

    agg = dict()
    insured = dict()
    with db.transaction.commit_on_success(using='reslt_writer'):
        for unit in units:
            agg[unit.loss_type], insured[unit.loss_type] = do_scenario(
                unit,
                containers.with_args(
                    loss_type=unit.loss_type,
                    output_type="loss_map"),
                profile)
    num_items = base.get_num_items(units)
    signal_task_complete(
        job_id=job_id, num_items=num_items,
        aggregate_losses=agg, insured_losses=insured)
示例#3
0
def scenario_damage(job_id, units, containers, params):
    """
    Celery task for the scenario damage risk calculator.

    :param int job_id:
      ID of the currently running job
    :param list units:
    :param containers:
      An instance of :class:`..writers.OutputDict` containing
      output container instances (in this case only `LossMap`)
    :param params:
      An instance of :class:`..base.CalcParams` used to compute
      derived outputs
    """
    def profile(name):
        return EnginePerformanceMonitor(name,
                                        job_id,
                                        scenario_damage,
                                        tracing=True)

    # in scenario damage calculation we have only ONE calculation unit
    unit = units[0]

    # and NO containes
    assert len(containers) == 0

    with db.transaction.commit_on_success(using='reslt_writer'):
        fractions, taxonomy = do_scenario_damage(unit, params, profile)

    num_items = base.get_num_items(units)
    signal_task_complete(job_id=job_id,
                         num_items=num_items,
                         fractions=fractions,
                         taxonomy=taxonomy)
示例#4
0
def event_based(job_id, units, containers, params):
    """
    Celery task for the event based risk calculator.

    :param job_id: the id of the current
        :class:`openquake.engine.db.models.OqJob`
    :param dict units:
      A list of :class:`openquake.risklib.workflows.CalculationUnit` instances
    :param containers:
      An instance of :class:`..writers.OutputDict` containing
      output container instances (e.g. a LossCurve)
    :param params:
      An instance of :class:`..base.CalcParams` used to compute
      derived outputs
    """
    def profile(name):
        return EnginePerformanceMonitor(name,
                                        job_id,
                                        event_based,
                                        tracing=True)

    # Do the job in other functions, such that they can be unit tested
    # without the celery machinery
    event_loss_tables = dict()

    with db.transaction.commit_on_success(using='reslt_writer'):
        for unit in units:
            event_loss_tables[unit.loss_type] = do_event_based(
                unit, containers.with_args(loss_type=unit.loss_type), params,
                profile)
    num_items = base.get_num_items(units)
    signal_task_complete(job_id=job_id,
                         num_items=num_items,
                         event_loss_tables=event_loss_tables)
示例#5
0
def scenario(job_id, units, containers, _params):
    """
    Celery task for the scenario risk calculator.

    :param int job_id:
      ID of the currently running job
    :param list units:
      A list of :class:`openquake.risklib.workflows.CalculationUnit` instances
    :param containers:
      An instance of :class:`..writers.OutputDict` containing
      output container instances (in this case only `LossMap`)
    :param params:
      An instance of :class:`..base.CalcParams` used to compute
      derived outputs
    """
    def profile(name):
        return EnginePerformanceMonitor(name, job_id, scenario, tracing=True)

    agg = dict()
    insured = dict()
    with db.transaction.commit_on_success(using='reslt_writer'):
        for unit in units:
            agg[unit.loss_type], insured[unit.loss_type] = do_scenario(
                unit,
                containers.with_args(loss_type=unit.loss_type,
                                     output_type="loss_map"), profile)
    num_items = base.get_num_items(units)
    signal_task_complete(job_id=job_id,
                         num_items=num_items,
                         aggregate_losses=agg,
                         insured_losses=insured)
示例#6
0
def scenario(job_id, units, containers, params):
    """
    Celery task for the scenario risk calculator.

    :param int job_id:
      ID of the currently running job
    :param dict units:
      A dict of :class:`..base.CalculationUnit` instances keyed by
      loss type string
    :param containers:
      An instance of :class:`..writers.OutputDict` containing
      output container instances (in this case only `LossMap`)
    :param params:
      An instance of :class:`..base.CalcParams` used to compute
      derived outputs
    """
    def profile(name):
        return EnginePerformanceMonitor(name, job_id, scenario, tracing=True)

    agg = dict()
    insured = dict()
    with db.transaction.commit_on_success(using='reslt_writer'):
        for loss_type in units:
            # in scenario calculation we have only ONE calculation unit
            unit = units[loss_type][0]
            agg[loss_type], insured[loss_type] = do_scenario(
                loss_type, unit, containers, params, profile)
    num_items = base.get_num_items(units)
    signal_task_complete(
        job_id=job_id, num_items=num_items,
        aggregate_losses=agg, insured_losses=insured)
示例#7
0
def scenario_damage(job_id, units, containers, params):
    """
    Celery task for the scenario damage risk calculator.

    :param int job_id:
      ID of the currently running job
    :param list units:
    :param containers:
      An instance of :class:`..writers.OutputDict` containing
      output container instances (in this case only `LossMap`)
    :param params:
      An instance of :class:`..base.CalcParams` used to compute
      derived outputs
    """
    def profile(name):
        return EnginePerformanceMonitor(
            name, job_id, scenario_damage, tracing=True)

    # in scenario damage calculation we have only ONE calculation unit
    unit = units[0]

    # and NO containes
    assert len(containers) == 0

    with db.transaction.commit_on_success(using='reslt_writer'):
        fractions, taxonomy = do_scenario_damage(unit, params, profile)

    num_items = base.get_num_items(units)
    signal_task_complete(
        job_id=job_id, num_items=num_items,
        fractions=fractions, taxonomy=taxonomy)
示例#8
0
def event_based_bcr(job_id, units, containers, params):
    """
    Celery task for the BCR risk calculator based on the event based
    calculator.

    Instantiates risklib calculators, computes bcr
    and stores results to db in a single transaction.

    :param int job_id:
      ID of the currently running job
    :param dict units:
      A dict of :class:`..base.CalculationUnit` instances keyed by
      loss type string
    :param containers:
      An instance of :class:`..writers.OutputDict` containing
      output container instances (in this case only `BCRDistribution`)
    :param params:
      An instance of :class:`..base.CalcParams` used to compute
      derived outputs
    """

    def profile(name):
        return EnginePerformanceMonitor(name, job_id, event_based_bcr, tracing=True)

    # Do the job in other functions, such that it can be unit tested
    # without the celery machinery
    with transaction.commit_on_success(using="reslt_writer"):
        for loss_type in units:
            do_event_based_bcr(loss_type, units[loss_type], containers, params, profile)
    num_items = base.get_num_items(units)
    signal_task_complete(job_id=job_id, num_items=num_items)
示例#9
0
def classical(job_id, units, containers, params):
    """
    Celery task for the classical risk calculator.

    :param int job_id:
      ID of the currently running job
    :param dict units:
      A dict of :class:`..base.CalculationUnit` instances keyed by
      loss type string
    :param containers:
      An instance of :class:`..writers.OutputDict` containing
      output container instances (e.g. a LossCurve)
    :param params:
      An instance of :class:`..base.CalcParams` used to compute
      derived outputs
    """
    def profile(name):
        return EnginePerformanceMonitor(name, job_id, classical, tracing=True)

    # Do the job in other functions, such that they can be unit tested
    # without the celery machinery
    with transaction.commit_on_success(using='reslt_writer'):
        for loss_type in units:
            do_classical(
                loss_type, units[loss_type], containers, params, profile)
    num_items = base.get_num_items(units)
    signal_task_complete(job_id=job_id, num_items=num_items)