👨‍💻 dev new alarm skill

development

owly

闇の伝説
Staff member
戦闘 コーダー
cron:
off method: counter = limit
triggerWithoutRenewal()

skill:
//set alarm

cron.trigger->beep
 

owly

闇の伝説
Staff member
戦闘 コーダー
cron:
off method: counter = limit
triggerWithoutRenewal()

skill:
turnOff; ret
//set alarm ; ret

cron.trigger->beep
 

owly

闇の伝説
Staff member
戦闘 コーダー
Java:
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;
    }
    public Boolean triggerWithoutRenewal() {
        // delete counter = 0 if you don't want the trigger to work the next day
        if (counter == limit) {trgTime.setTime(initialTimeStamp);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;
    }
    public void turnOff(){
        counter = limit;
    }
}
 

owly

闇の伝説
Staff member
戦闘 コーダー
Java:
public class DiAlarmer extends DiSkillV2 {
    private Responder off = new Responder("off","stop","shut up", "shut it","alarm off","cancel alarm");
    private RegexUtil regexUtil = new RegexUtil();
    private Cron cron = new Cron("", 3,3);

    public void setCron(Cron cron) {
        this.cron = cron;
    }

    @Override
    public void input(String ear, String skin, String eye) {
        // turn off alarm
        if (off.responsesContainsStr(ear)){
            cron.turnOff();
            setSimpleAlg("alarm is now off");
            return;
        }
        String temp = regexUtil.extractRegex("(?<=set alarm to\\s)([0-9]{1,2}:[0-9]{1,2})", ear);
        if (!temp.isEmpty()){
            cron.setStartTime(temp);
            setSimpleAlg("alarm set to "+ temp);
            return;
        }
        if(cron.triggerWithoutRenewal()){
            setSimpleAlg("beep");
        }
    }
}
 

owly

闇の伝説
Staff member
戦闘 コーダー
Python:
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

    # 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

    def triggerWithoutRenewal(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)
            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

    def turnOff(self):
        self._counter = self._limit
 

owly

闇の伝説
Staff member
戦闘 コーダー
Python:
class DiAlarmer(DiSkillV2):
    def __init__(self):
        super().__init__()
        self.off: Responder = Responder("off", "stop", "shut up", "shut it", "alarm off", "cancel alarm")
        self.regexUtil: RegexUtil = RegexUtil()
        self._cron: Cron = Cron("", 3, 3)

    def setCron(self, cron):
        self._cron = cron

    def input(self, ear, skin, eye):
        # Turn off alarm
        if self.off.responsesContainsStr(ear):
            self._cron.turnOff()
            self.setSimpleAlg("alarm is now off")
            return

        temp = self.regexUtil.extractRegex(r"(?<=set alarm to\s)([0-9]{1,2}:[0-9]{1,2})", ear)
        if not len(temp) == 0:
            self._cron.setStartTime(temp)
            self.setSimpleAlg(f"alarm set to {temp}")
            return

        if self._cron.triggerWithoutRenewal():
            self.setSimpleAlg("beep")

 
Top