Ejemplo n.º 1
0
Archivo: avg.py Proyecto: M-o-a-T/moat
	def list(self):
		yield super(DecayTimeAvg,self)
		yield ("weight",self.p)
		yield ("time base",humandelta(self.p_base))
		yield ("weight/hour",1-(1-self.p)**(3600/self.p_base))
		yield ("weight/minute",1-(1-self.p)**(60/self.p_base))
		yield ("weight/second",1-(1-self.p)**(1/self.p_base))
Ejemplo n.º 2
0
 def list(self):
     yield super(DecayTimeAvg, self)
     yield ("weight", self.p)
     yield ("time base", humandelta(self.p_base))
     yield ("weight/hour", 1 - (1 - self.p)**(3600 / self.p_base))
     yield ("weight/minute", 1 - (1 - self.p)**(60 / self.p_base))
     yield ("weight/second", 1 - (1 - self.p)**(1 / self.p_base))
Ejemplo n.º 3
0
	def list(self):
		n=now()
		yield super(CommonPM,self)
		yield ("type",self.type)
		if self.state is not None:
			yield ("state",self.names[self.state])
		if self._value is not None:
			yield ("current",self._value)
		if self.last is not None:
			yield ("last",self.last)
		if self.next is not None:
			yield ("next",self.next)
		if self.t_off is not None:
			yield ("t_off",humandelta(self.t_off))
		if self.t_on is not None:
			yield ("t_on",humandelta(self.t_on))
Ejemplo n.º 4
0
def add_human(d):
	"""add human-readable tags"""
	for k in "interval max_age".split():
		v = d.get(k,None)
		if v is not None:
			d.setdefault('human',{})[k] = humandelta(v)
	m = d.get('method',None)
	if m is not None:
		d.setdefault('human',{})['method'] = modes[m]
Ejemplo n.º 5
0
Archivo: cmd.py Proyecto: M-o-a-T/moat
def add_human(d):
	"""add human-readable tags"""
	for k in "interval max_age".split():
		v = d.get(k,None)
		if v is not None:
			d.setdefault('human',{})[k] = humandelta(v)
	m = d.get('method',None)
	if m is not None:
		d.setdefault('human',{})['method'] = modes[m]
Ejemplo n.º 6
0
Archivo: data.py Proyecto: M-o-a-T/moat
		def out_one(c):
			for p,t in flatten((c,)):
				if isinstance(t,datetime):
					if TESTING and t.year != 2003:
						t = "%s" % (humandelta(t-now(t.year != 2003)),)
					else:
						t = "%s (%s)" % (humandelta(t-now(t.year != 2003)),t)
					if TESTING:
						lim = 3
					else:
						lim = 4
					ti = t.rfind('.')
					if ti>0 and len(t)-ti>lim and len(t)-ti<lim+6: # limit to msec
						t = t[:ti+lim]+")"

				elif isinstance(t,float):
					ft=float("%.4f"%t)
					if abs(ft-t)<0.00000001:
						t=ft
				print(p+u": "+six.text_type(t), file=self.ctx.out)
Ejemplo n.º 7
0
	def report(self, verbose=False):
		if self.name:
			yield "WORK: "+self.name
		if self.id:
			yield "id: "+str(self.id)
		yield "call count: "+str(self.call_count)
		if self.last_call:
			yield "last call: %s (%s)" % (humandelta(now()-self.last_call),self.last_call)
		if self.last_args:
			for a,b in self.last_args.items():
				yield "last %s: %s" % (a,b)
Ejemplo n.º 8
0
 def report(self, verbose=False):
     if self.name:
         yield "WORK: " + self.name
     if self.id:
         yield "id: " + str(self.id)
     yield "call count: " + str(self.call_count)
     if self.last_call:
         yield "last call: %s (%s)" % (humandelta(now() - self.last_call),
                                       self.last_call)
     if self.last_args:
         for a, b in self.last_args.items():
             yield "last %s: %s" % (a, b)
Ejemplo n.º 9
0
	def time_name(self):
		if self.started_at is None:
			return "never"
		if not self.running.is_set():
			delta = now() - self.started_at
		elif self.job:
			delta = self.started_at - now()
		else:
			delta = now() - self.started_at
		delta = unixdelta(delta)
		res = humandelta(delta)

		return u"‹"+res+"›"
Ejemplo n.º 10
0
        def out_one(c):
            for p, t in flatten((c, )):
                if isinstance(t, datetime):
                    if TESTING and t.year != 2003:
                        t = "%s" % (humandelta(t - now(t.year != 2003)), )
                    else:
                        t = "%s (%s)" % (humandelta(t - now(t.year != 2003)),
                                         t)
                    if TESTING:
                        lim = 3
                    else:
                        lim = 4
                    ti = t.rfind('.')
                    if ti > 0 and len(t) - ti > lim and len(
                            t) - ti < lim + 6:  # limit to msec
                        t = t[:ti + lim] + ")"

                elif isinstance(t, float):
                    ft = float("%.4f" % t)
                    if abs(ft - t) < 0.00000001:
                        t = ft
                print(p + u": " + six.text_type(t), file=self.ctx.out)
Ejemplo n.º 11
0
	def list(self):
		def _simul(x):
			yield ("interval",x[1])
			yield ("current",x[0])
			yield ("value",x[3])
		yield super(OWFSpoller,self)
		yield ("bus",self.bus)
		yield ("path",self.path)
		yield ("interval",humandelta(self.freq))
		if self.time_start:
			yield ("last start",humandelta(now()-self.time_start))
		if self.time_len:
			yield ("last duration",humandelta(self.time_len))
		for id in self.seen:
			dev = devices.get(id,id)
			yield ("alarm",dev)
		for id in self.seen_new:
			yield ("alarm new",id)
		if self.last_error:
			yield ("last error",self.last_error)
		for x in self.simul:
			yield ("simultaneous",x[2],_simul(x))
Ejemplo n.º 12
0
    def list(self):
        def _simul(x):
            yield ("interval", x[1])
            yield ("current", x[0])
            yield ("value", x[3])

        yield super(OWFSpoller, self)
        yield ("bus", self.bus)
        yield ("path", self.path)
        yield ("interval", humandelta(self.freq))
        if self.time_start:
            yield ("last start", humandelta(now() - self.time_start))
        if self.time_len:
            yield ("last duration", humandelta(self.time_len))
        for id in self.seen:
            dev = devices.get(id, id)
            yield ("alarm", dev)
        for id in self.seen_new:
            yield ("alarm new", id)
        if self.last_error:
            yield ("last error", self.last_error)
        for x in self.simul:
            yield ("simultaneous", x[2], _simul(x))
Ejemplo n.º 13
0
Archivo: wait.py Proyecto: smurfix/MoaT
	def list(self):
		yield super(Waiter,self)
		yield("start",self.start)
		if self._plinger:
			end=now()+dt.timedelta(0,self.value)
			yield("end",end)
			yield("total", humandelta(end-self.start))
		w = self
		if self.soft is None:
			yield("abort","on cancelation")
		elif self.soft:
			yield("abort","never")
		else:
			yield("abort","on timeout")
		while True:
			w = getattr(w,"parent",None)
			if w is None: break
			n = getattr(w,"displayname",None)
			if n is not None:
				if not isinstance(n,six.string_types):
					n = " ".join(six.text_type(x) for x in n)
			else:
				try:
					if w.args:
						n = six.text_type(w.args)
				except AttributeError:
					pass
				if n is None:
					try:
						if isinstance(w.name,six.string_types):
							n = w.name
						else:
							n = " ".join(six.text_type(x) for x in w.name)
					except AttributeError:
						n = w.__class__.__name__
			if n is not None:
				yield("in",n)
Ejemplo n.º 14
0
 def list(self):
     yield super(Waiter, self)
     yield ("start", self.start)
     if self._plinger:
         end = now() + dt.timedelta(0, self.value)
         yield ("end", end)
         yield ("total", humandelta(end - self.start))
     w = self
     if self.soft is None:
         yield ("abort", "on cancelation")
     elif self.soft:
         yield ("abort", "never")
     else:
         yield ("abort", "on timeout")
     while True:
         w = getattr(w, "parent", None)
         if w is None: break
         n = getattr(w, "displayname", None)
         if n is not None:
             if not isinstance(n, six.string_types):
                 n = " ".join(six.text_type(x) for x in n)
         else:
             try:
                 if w.args:
                     n = six.text_type(w.args)
             except AttributeError:
                 pass
             if n is None:
                 try:
                     if isinstance(w.name, six.string_types):
                         n = w.name
                     else:
                         n = " ".join(six.text_type(x) for x in w.name)
                 except AttributeError:
                     n = w.__class__.__name__
         if n is not None:
             yield ("in", n)
Ejemplo n.º 15
0
	def info(self):
		if self.last is not None:
			return "%s %d: %s" % (em_procs[self.group].em_name, self.code,
				humandelta(self.last-now()))
		else:
			return "%s %d: (never)" % (em_procs[self.group].em_name, self.code)
Ejemplo n.º 16
0
	def info(self):
		if self.last_sent_at is None:
			return "Never"
		return humandelta(now()-self.last_sent_at)
Ejemplo n.º 17
0
	def info(self):
		if self.last is not None:
			return "%s %d: %s" % (en_procs[self.group].en_name, self.code,
				humandelta(self.last-now()))
		else:
			return "%s %d: (never)" % (en_procs[self.group].en_name, self.code)
Ejemplo n.º 18
0
	def info(self):
		if self._value is None or self.t_on is None:
			return "(new)"
		return "%.3f %s / %s" % (self._value,humandelta(self.t_on),humandelta(self.t_off))
Ejemplo n.º 19
0
	def _run_schedule(self):
		if self.sched_job is not None:
			self.sched_job.kill()
			self.sched_job = None
		if self.locked:
			if self.v.verbose:
				print("SCHED LOCKED2 %s" % (self.v.name,), file=sys.stderr)
			return
		n = now()

		try:
			if self.sched is not None:
				self.sched.refresh()
				if self.sched.end <= n:
					if self.v.verbose:
						print("Turn off: %s+%s <= %s" % (self.sched.start,self.sched.duration,n), file=sys.stderr)
					self._off(2)
					self.sched = None
				else:
					self.sched_job = gevent.spawn_later((self.sched.end-n).total_seconds(),connwrap,self.run_sched_task,reason="_run_schedule 1")
					if self.v.verbose:
						print("SCHED LATER %s: %s" % (self.v.name,humandelta(self.sched.end-n)), file=sys.stderr)
					return
		except ObjectDoesNotExist:
			pass # somebody deleted it *shrug*
		sched = None

		if self.sched_ts is None:
			try:
				sched = self.v.schedules.filter(start__lt=n).order_by("-start")[0]
			except IndexError:
				self.sched_ts = n-timedelta(1,0)
			else:
				self.sched_ts = sched.end
				if sched.end > n: # still running
					if self.v.verbose:
						print("SCHED RUNNING %s: %s" % (self.v.name,humandelta(sched.end-n)), file=sys.stderr)
					try:
						self._on(1,sched, sched.end-n)
					except TooManyOn:
						self.log("Could not schedule: too many open valves")
					except NotConnected:
						self.log("Could not schedule: connection to MoaT failed")
					return

		try:
			sched = self.v.schedules.filter(start__gte=self.sched_ts).order_by("start")[0]
		except IndexError:
			if self.v.verbose:
				print("SCHED EMPTY %s: %s" % (self.v.name,str_tz(self.sched_ts)), file=sys.stderr)
			self._off(3)
			return

		if sched.end <= n:
			if self.v.verbose:
				print("SCHED %s: sched %d done for %s" % (self.v.name,sched.id,humandelta(n-sched.end)), file=sys.stderr)
			self.sched_ts = None
			return
		if sched.start > n:
			if self.v.verbose:
				print("SCHED %s: sched %d in %s" % (self.v.name,sched.id,humandelta(sched.start-n)), file=sys.stderr)
			self._off(4)
			self.sched_job = gevent.spawn_later((sched.start-n).total_seconds(),connwrap,self.run_sched_task,reason="_run_schedule 2")
			return
		try:
			self._on(2,sched)
		except TooManyOn:
			self.log("Could not schedule: too many open valves")
		except NotConnected:
			self.log("Could not schedule: connection to MoaT failed")
Ejemplo n.º 20
0
    def _run_schedule(self):
        if self.sched_job is not None:
            self.sched_job.kill()
            self.sched_job = None
        if self.locked:
            if self.v.verbose:
                print("SCHED LOCKED2 %s" % (self.v.name, ), file=sys.stderr)
            return
        n = now()

        try:
            if self.sched is not None:
                self.sched.refresh()
                if self.sched.end <= n:
                    if self.v.verbose:
                        print("Turn off: %s+%s <= %s" %
                              (self.sched.start, self.sched.duration, n),
                              file=sys.stderr)
                    self._off(2)
                    self.sched = None
                else:
                    self.sched_job = gevent.spawn_later(
                        (self.sched.end - n).total_seconds(),
                        connwrap,
                        self.run_sched_task,
                        reason="_run_schedule 1")
                    if self.v.verbose:
                        print("SCHED LATER %s: %s" %
                              (self.v.name, humandelta(self.sched.end - n)),
                              file=sys.stderr)
                    return
        except ObjectDoesNotExist:
            pass  # somebody deleted it *shrug*
        sched = None

        if self.sched_ts is None:
            try:
                sched = self.v.schedules.filter(
                    start__lt=n).order_by("-start")[0]
            except IndexError:
                self.sched_ts = n - timedelta(1, 0)
            else:
                self.sched_ts = sched.end
                if sched.end > n:  # still running
                    if self.v.verbose:
                        print("SCHED RUNNING %s: %s" %
                              (self.v.name, humandelta(sched.end - n)),
                              file=sys.stderr)
                    try:
                        self._on(1, sched, sched.end - n)
                    except TooManyOn:
                        self.log("Could not schedule: too many open valves")
                    except NotConnected:
                        self.log(
                            "Could not schedule: connection to MoaT failed")
                    return

        try:
            sched = self.v.schedules.filter(
                start__gte=self.sched_ts).order_by("start")[0]
        except IndexError:
            if self.v.verbose:
                print("SCHED EMPTY %s: %s" %
                      (self.v.name, str_tz(self.sched_ts)),
                      file=sys.stderr)
            self._off(3)
            return

        if sched.end <= n:
            if self.v.verbose:
                print("SCHED %s: sched %d done for %s" %
                      (self.v.name, sched.id, humandelta(n - sched.end)),
                      file=sys.stderr)
            self.sched_ts = None
            return
        if sched.start > n:
            if self.v.verbose:
                print("SCHED %s: sched %d in %s" %
                      (self.v.name, sched.id, humandelta(sched.start - n)),
                      file=sys.stderr)
            self._off(4)
            self.sched_job = gevent.spawn_later(
                (sched.start - n).total_seconds(),
                connwrap,
                self.run_sched_task,
                reason="_run_schedule 2")
            return
        try:
            self._on(2, sched)
        except TooManyOn:
            self.log("Could not schedule: too many open valves")
        except NotConnected:
            self.log("Could not schedule: connection to MoaT failed")
Ejemplo n.º 21
0
Archivo: wago.py Proyecto: smurfix/MoaT
	def __repr__(self):
		res = super(WAGOtimedOutputRun,self).__repr__()
		return u"‹%s tm=%s id=%s›" % (res[1:-1],humandelta(self.timer.end-now(True)),self.msgid)
Ejemplo n.º 22
0
	def info(self):
		if hasattr(self,"old_value"):
			return u"%s — %s " % (self.value,humandelta(now()-self.time))
		else:
			return six.text_type(self.value)
Ejemplo n.º 23
0
 def info(self):
     if hasattr(self, "old_value"):
         return u"%s — %s " % (self.value, humandelta(now() - self.time))
     else:
         return six.text_type(self.value)
Ejemplo n.º 24
0
 def __repr__(self):
     res = super(WAGOtimedOutputRun, self).__repr__()
     return u"‹%s tm=%s id=%s›" % (
         res[1:-1], humandelta(self.timer.end - now(True)), self.msgid)