import LivinGrimoire.PlayGround;
import java.util.Random;
public class Cron extends TrGEV3{
// triggers true, limit times, after initial time, and every minutes interval
// counter resets at initial time, assuming trigger method was run
int minutes; // minute interval between triggerings
private PlayGround pl = new PlayGround();
private TrgTime trgTime;
private String timeStamp = "";
private String initialTimeStamp = "";
private int limit;
private int counter = 0;
public Cron(String startTime, int minutes, int limit) {
this.minutes = minutes;
this.timeStamp = startTime;
this.initialTimeStamp = startTime;
trgTime = new TrgTime();
trgTime.setTime(startTime);
this.limit = limit;
if(limit<0){this.limit = 1;}
}
public int getLimit() {
return limit;
}
public void setLimit(int limit) {
if (limit>-1){
this.limit = limit;}
}
public int getCounter() {
return counter;
}
public void setMinutes(int minutes) {
if (minutes > -1) {
this.minutes = minutes;}
}
@Override
public Boolean trigger() {
// delete counter = 0 if you don't want the trigger to work the next day
if (counter == limit) {trgTime.setTime(initialTimeStamp);counter = 0;return false;}
if (trgTime.alarm()){
timeStamp = pl.getFutureInXMin(minutes);
trgTime.setTime(timeStamp);
counter++;
return true;
}
return false;
}
@Override
public void reset() {
// manual trigger reset
counter = 0;
}
public void setStartTime(String t1){
initialTimeStamp = t1;
timeStamp = t1;
trgTime.setTime(t1);
counter = 0;
}
}
class Cron(TrGEV3):
# triggers true, limit times, after initial time, and every minutes interval
# counter resets at initial time, assuming trigger method was run
def __init__(self, startTime: str, minutes: int, limit: int):
self._playGround: PlayGround = PlayGround()
self._minutes: int = minutes # minute interval between triggerings
self._timeStamp = startTime
self._initislTimeStamp = startTime
self._trgTime: TrgTime = TrgTime()
self._trgTime.setTime(startTime)
self._counter: int = 0
self._limit: int = limit
if limit < 1:
self._limit = 1
def setMinutes(self, minutes: int):
if minutes > -1:
self._minutes = minutes
def getLimit(self) -> int:
return self._limit
def setLimit(self, limit: int):
if limit > 0:
self._limit = limit
def getCounter(self) -> int:
return self._counter
def setMinutes(self, minutes: int):
if minutes > -1:
self._minutes = minutes
# override
def trigger(self) -> bool:
# delete counter = 0 if you don't want the trigger to work the next day
if self._counter == self._limit:
self._trgTime.setTime(self._initislTimeStamp)
self._counter = 0
return False
if self._trgTime.alarm():
self._timeStamp = self._playGround.getFutureInXMin(self._minutes)
self._trgTime.setTime(self._timeStamp)
self._counter += 1
return True
return False
# override
def reset(self):
# manual trigger reset
self._counter = 0
def setStartTime(self, t1: str):
self._initislTimeStamp = t1
self._timeStamp = t1
self._trgTime.setTime(t1)
self._counter = 0
class DiMisser(DiSkillV2):
def __init__(self):
self._pl: PlayGround = PlayGround()
self._cron: Cron = Cron("15:00",2,2)
self._responder: Responder = Responder("welcome", "i have missed you", "welcome back")
super().__init__()
# Override
def input(self, ear: str, skin: str, eye: str):
if ear == "i am home":
self._cron.setStartTime(self._pl.getCurrentTimeStamp())
self._outAlg = self._diSkillUtils.simpleVerbatimAlgorithm("dimisser", self._responder.getAResponse())
return
if self._cron.trigger():
n: int = self._cron.getCounter()
match n:
case _:
self._outAlg = self._diSkillUtils.simpleVerbatimAlgorithm("dimisser2", f'hmph {n}')
class DiMisser(DiSkillV2):
def __init__(self):
self._pl: PlayGround = PlayGround()
self._cron: Cron = Cron("15:00",50,2)
self._responder: Responder = Responder("welcome", "i have missed you", "welcome back")
super().__init__()
# Override
def input(self, ear: str, skin: str, eye: str):
if ear == "i am home":
self._cron.setStartTime(self._pl.getPastInXMin(10))
self._outAlg = self._diSkillUtils.simpleVerbatimAlgorithm("dimisser", self._responder.getAResponse())
return
if self._cron.trigger():
n: int = self._cron.getCounter()
match n:
case _:
self._outAlg = self._diSkillUtils.simpleVerbatimAlgorithm("dimisser2", f'hmph {n}')
class Cron:TrGEV3{
// triggers true, limit times, after initial time, and every minutes interval
// counter resets at initial time, assuming trigger method was run
private var minutes:Int // minute interval between triggerings
private let pl:PlayGround = PlayGround()
private var trgTime:TrgTime
private var timeStamp:String = ""
private var initialTimeStamp:String = ""
private var limit:Int
private var counter:Int = 0
init(startTime:String, minutes:Int, limit:Int) {
self.minutes = minutes
self.timeStamp = startTime
self.initialTimeStamp = startTime
trgTime = TrgTime()
trgTime.setTime(v1: startTime)
self.limit = limit
if limit<0{
self.limit = 1
}
}
func getIimit()->Int{
return limit
}
func setLimit(lim:Int){
if lim > -1{
limit = lim
}
}
func getCounter()->Int{
return self.counter
}
func setMinutes(minutes:Int){
// set interval between trigger times
if minutes > -1{
self.minutes = minutes
}
}
override func trigger() -> Bool {
// delete counter = 0 if you don't want the trigger to work the next day
if counter == limit{
trgTime.setTime(v1: initialTimeStamp)
counter = 0
return false
}
if trgTime.trigger() {
timeStamp = pl.getFutureInXMin(extra_minutes: minutes)
trgTime.setTime(v1: timeStamp)
counter += 1
return true
}
return false
}
override func reset() {
// manual trigger reset
counter = 0
}
func setStartTime(t1:String){
initialTimeStamp = t1
timeStamp = t1
trgTime.setTime(v1: t1)
counter = 0
}
}