Exemplo n.º 1
0
def main(ns):
    validate_ns_or_sysexit(ns)
    configure_logging(True)
    if ns.sendstats:
        if ns.sendstats == 'webui':
            add_zmq_log_handler('ipc:///tmp/relaylog')
            start_webui()
        else:
            add_zmq_log_handler(ns.sendstats)
    log.info("Starting relay!",
             extra={k: str(v)
                    for k, v in ns.__dict__.items()})

    metric = ns.metric()
    target = ns.target()
    errhist = window(ns.lookback)
    ramp_index = 0

    while True:
        SP = next(target)  # set point
        PV = next(metric)  # process variable
        err = (SP - PV)
        log.debug('got metric value', extra=dict(PV=PV, SP=SP))
        if ramp_index < ns.ramp:
            if ramp_index == 0:
                plan = create_ramp_plan(err, ns.ramp)
            ramp_index += 1
            MV = next(plan)
            errdata = errhist.send(0)
        else:
            errdata = errhist.send(err)
            weight = calc_weight(errdata)
            MV = int(round(err - weight * sum(errdata) / len(errdata)))
            log.info(
                'data',
                extra=dict(data=[err, weight,
                                 sum(errdata) / len(errdata)]))

        if MV > 0:
            if ns.warmer:
                log.debug('adding heat', extra=dict(MV=MV, err=err))
                threading.Thread(target=ns.warmer, args=(MV, )).start()
            else:
                log.warn('too cold')
        elif MV < 0:
            if ns.cooler:
                log.debug('removing heat', extra=dict(MV=MV, err=err))
                threading.Thread(target=ns.cooler, args=(MV, )).start()
            else:
                log.warn('too hot')
        else:
            log.debug('stabilized PV at setpoint',
                      extra=dict(MV=MV, PV=PV, SP=SP))
        time.sleep(ns.delay)
        evaluate_stop_condition(list(errdata), ns.stop_condition)
Exemplo n.º 2
0
def main(ns):
    validate_ns_or_sysexit(ns)
    configure_logging(True)
    if ns.sendstats:
        if ns.sendstats == "webui":
            add_zmq_log_handler("ipc:///tmp/relaylog")
            start_webui()
        else:
            add_zmq_log_handler(ns.sendstats)
    log.info("Starting relay!", extra={k: str(v) for k, v in ns.__dict__.items()})

    metric = ns.metric()
    target = ns.target()
    errhist = window(ns.lookback)
    ramp_index = 0

    while True:
        SP = next(target)  # set point
        PV = next(metric)  # process variable
        err = SP - PV
        log.debug("got metric value", extra=dict(PV=PV, SP=SP))
        if ramp_index < ns.ramp:
            if ramp_index == 0:
                plan = create_ramp_plan(err, ns.ramp)
            ramp_index += 1
            MV = next(plan)
            errdata = errhist.send(0)
        else:
            errdata = errhist.send(err)
            weight = calc_weight(errdata)
            MV = int(round(err - weight * sum(errdata) / len(errdata)))
            log.info("data", extra=dict(data=[err, weight, sum(errdata) / len(errdata)]))

        if MV > 0:
            if ns.warmer:
                log.debug("adding heat", extra=dict(MV=MV, err=err))
                threading.Thread(target=ns.warmer, args=(MV,)).start()
            else:
                log.warn("too cold")
        elif MV < 0:
            if ns.cooler:
                log.debug("removing heat", extra=dict(MV=MV, err=err))
                threading.Thread(target=ns.cooler, args=(MV,)).start()
            else:
                log.warn("too hot")
        else:
            log.debug("stabilized PV at setpoint", extra=dict(MV=MV, PV=PV, SP=SP))
        time.sleep(ns.delay)
        evaluate_stop_condition(list(errdata), ns.stop_condition)
Exemplo n.º 3
0
import logging

log = logging.getLogger("relay.mesos")

# expose configure_logging to those who wish to develop relay
from relay import configure_logging

from relay import log as _relay_runner_log

_parent_log = logging.getLogger("relay")
_relay_runner_log.propagate = True
log.propagate = True
configure_logging(True, log=_parent_log)  # parent_log will not propagate

import pkg_resources as _pkg_resources

__version__ = _pkg_resources.get_distribution("relay.mesos").version
Exemplo n.º 4
0
import logging
log = logging.getLogger('relay.mesos')

# expose configure_logging to those who wish to develop relay
from relay import configure_logging

from relay import log as _relay_runner_log
_parent_log = logging.getLogger('relay')
_relay_runner_log.propagate = True
log.propagate = True
configure_logging(True, log=_parent_log)  # parent_log will not propagate

import pkg_resources as _pkg_resources
__version__ = _pkg_resources.get_distribution('relay.mesos').version