def handle(self, *args, **options): q = Q() now = datetime.utcnow().replace(tzinfo=utc) if options['site']: q &= Q(controller__site__name=options['site']) if options['controller']: q &= Q(controller__name=options['controller']) duration = int(args[0]) valve = " ".join(args[1:]) valve = Valve.objects.get(q, var=valve) s=Schedule(valve=valve,start=now+timedelta(0,options["future"]),db_duration=duration) s.save()
def handle(self, *args, **options): q = Q() now = datetime.utcnow().replace(tzinfo=utc) if options['site']: q &= Q(controller__site__name=options['site']) if options['controller']: q &= Q(controller__name=options['controller']) duration = int(args[0]) valve = " ".join(args[1:]) valve = Valve.objects.get(q, var=valve) s = Schedule(valve=valve, start=now + timedelta(0, options["future"]), db_duration=duration) s.save()
def force_one_valve(self,v,options): for a,b in v.range(start=soon,forced=True): print "Forced",str_tz(a),str(b) if options['save']: sc=Schedule(valve=v,start=a,duration=b,forced=True) sc.save()
def one_valve(self,v,options): if v.feed.disabled: return if (v.level < v.stop_level) if v.priority else (v.level < v.start_level): print "Nothing to do",v,v.level,v.start_level if options['save'] and v.verbose: log(v,"Nothing to do (has %s, need %s)" % (v.level,v.start_level)) return level = v.level if level > v.max_level: level = v.max_level want = v.raw_watering_time(level) has = timedelta(0,0) last_end = None for s in v.schedules.filter(start__gte=soon-timedelta(1,0)).order_by('start'): last_end=s.end if s.end < n: continue # # This code is disabled because as more # if s.start > later and not s.seen and not s.forced: # if options['save']: # if v.verbose: # log(v,"Drop schedule at %s for %s" % (str_tz(s.start),str(s.duration))) # v.update(priority=True) # s.delete() # continue has += s.duration if last_end and v.min_delay: last_end += v.min_delay if has: if options['save']: v.update(priority=(want.total_seconds() > has.total_seconds()*1.2)) log(v,"Already something to do (has %s, need %s, want %s, does %s)" % (v.level,v.start_level,want,has)) return elif want.total_seconds() < 10: if options['save']: v.update(priority=False) log(v,"Too little to do (has %s, need %s, want %s)" % (v.level,v.start_level,want)) return if options['verbose']: print "Plan",v,"for",want,"Level",v.level,v.start_level,v.stop_level,"P" if v.priority else "" for a,b in v.range(start=soon,days=options['age'], add=30): if a > soon: break # do it during the next run if last_end and last_end > a: if last_end >= a+b: continue if last_end>a: b-=(last_end-a) a=last_end last_end=None if b.total_seconds() < want.total_seconds()/5: if v.verbose: log(v,"slot too short at %s for %s (level %s; want %s)" % (str_tz(a),str(b),v.level,str(want))) continue if v.max_run and b > v.max_run: b=v.max_run if b < want: print "Partial",str_tz(a),str(b) if options['save']: sc=Schedule(valve=v,start=a,duration=b) sc.save() v.update(priority=True) if v.verbose: log(v,"Scheduled at %s for %s (level %s; want %s)" % (str_tz(a),str(b),v.level,str(want))) want -= b break # bail out makes sense, get others scheduled first / do more in the same slot if v.max_run is set else: print "Total",str_tz(a),str(want) if options['save']: sc=Schedule(valve=v,start=a,duration=want) sc.save() v.update(priority=False) if v.verbose: log(v,"Scheduled at %s for %s (level %s)" % (str_tz(a),str(want),v.level)) want = None break if want is not None: print "Missing",want
def force_one_valve(self,v,options): for a,b in v.range(start=soon,forced=True): print("Forced",str_tz(a),str(b)) if options['save']: sc=Schedule(valve=v,start=a,duration=b,forced=True) sc.save()
def one_valve(self,v,options): if v.feed.disabled: return if (v.level < v.stop_level) if v.priority else (v.level < v.start_level): if options['save'] and v.verbose: log(v,"Nothing to do (has %s, need %s)" % (v.level,v.start_level)) return level = v.level if level > v.max_level: level = v.max_level want = v.raw_watering_time(level) has = timedelta(0,0) last_end = None for s in v.schedules.filter(start__gte=soon-timedelta(1,0)).order_by('start'): last_end=s.end if s.end < n: continue # # This code is disabled because as more # if s.start > later and not s.seen and not s.forced: # if options['save']: # if v.verbose: # log(v,"Drop schedule at %s for %s" % (str_tz(s.start),str(s.duration))) # v.update(priority=True) # s.delete() # continue has += s.duration if last_end and v.min_delay: last_end += v.min_delay if has: if options['save']: v.update(priority=(want.total_seconds() > has.total_seconds()*1.2)) if v.verbose: log(v,"Already something to do (has %s, need %s, want %s, does %s)" % (v.level,v.start_level,want,has)) return elif want.total_seconds() < 10: if options['save']: v.update(priority=False) if v.verbose: log(v,"Too little to do (has %s, need %s, want %s)" % (v.level,v.start_level,want)) return if options['verbose']: print("Plan",v,"for",want,"Level",v.level,v.start_level,v.stop_level,"P" if v.priority else "") for a,b in v.range(start=soon,days=options['age'], add=30): if a > soon: if options['verbose']: print("NotYet",a,soon) break # do it during the next run if last_end and last_end > a: if last_end >= a+b: continue if last_end>a: b-=(last_end-a) a=last_end last_end=None if b.total_seconds() < want.total_seconds()/5: if v.verbose: log(v,"slot too short at %s for %s (level %s; want %s)" % (str_tz(a),str(b),v.level,str(want))) continue if v.max_run and b > v.max_run: b=v.max_run if b < want: log(v, "Partial %s %s %s" % (str_tz(a),str(b),str(want))) if options['save']: sc=Schedule(valve=v,start=a,duration=b) sc.save() v.update(priority=True) if v.verbose: log(v,"Scheduled at %s for %s (level %s; want %s)" % (str_tz(a),str(b),v.level,str(want))) want -= b break # bail out: get others scheduled first / do more in the same slot if v.max_run is set else: log(v,"Total %s %s" % (str_tz(a),str(want))) if options['save']: sc=Schedule(valve=v,start=a,duration=want) sc.save() v.update(priority=False) if v.verbose: log(v,"Scheduled at %s for %s (level %s)" % (str_tz(a),str(want),v.level)) want = None break else: if want: log(v, "Missing %s" % (str(want),))