cron job java->python

owly

闇の伝説
Staff member
戦闘 コーダー
project progress at 100%
 
0% 100%



+responder1word
+timeaccumulator
+tryeverynminutes
+cron
 
Last edited by a moderator:

fukurou

the supreme coder
ADMIN
Python:
from __future__ import annotations
from LivinGrimoireCoreV2 import *


class TimeAccumulator:
    # accumulator ++ each tick minutes interval
    def __init__(self, tick: int):
        # accumulation ticker
        self._timeGate: TimeGate = TimeGate(tick)
        self._accumulator: int = 0
        self._timeGate.openForPauseMinutes()

    def setTick(self, tick: int):
        self._timeGate.setPause(tick)

    def getAccumulator(self) -> int:
        return self._accumulator

    def reset(self):
        self._accumulator = 0

    def tick(self):
        if self._timeGate.isClosed():
            self._timeGate.openForPauseMinutes()
            self._accumulator += 1
 

fukurou

the supreme coder
ADMIN
Java:
public class Responder1Word {
    // learns 1 word inputs
    // outputs learned recent words
    UniqueItemSizeLimitedPriorityQueue q= new UniqueItemSizeLimitedPriorityQueue();

    public Responder1Word() {
        q.add("chi");
        q.add("gaga");
        q.add("gugu");
        q.add("baby");
    }
    public void listen(String ear){
        if (!(ear.contains(" ") || ear.isEmpty())){
            q.add(ear);
        }
    }
    public String getAResponse(){
        return q.getRNDElement();
    }
    public Boolean contains(String ear){
        return q.contains(ear);
    }
}
 

fukurou

the supreme coder
ADMIN
Python:
class Responder1Word:
    # learns 1 word input
    # outputs learned recent words
    def __init__(self):
        self.q: UniqueItemSizeLimitedPriorityQueue = UniqueItemSizeLimitedPriorityQueue(5)
        self.q.insert("chi")
        self.q.insert("gaga")
        self.q.insert("gugu")
        self.q.insert("baby")

    def listen(self, ear: str):
        if not (ear.__contains__(" ") or ear == ""):
            self.q.insert(ear)

    def getAResponse(self) -> str:
        return self.q.getRNDElement()

    def contains(self, ear: str) -> bool:
        return self.q.contains(ear)
 

owly

闇の伝説
Staff member
戦闘 コーダー
Java:
public class TrgEveryNMinutes extends TrGEV3{
    // trigger returns true every minutes interval, post start time
    private PlayGround playGround = new PlayGround();
    int minutes; // minute interval between triggerings
    private PlayGround pl = new PlayGround();
    private TrgTime trgTime;
    private String timeStamp = "";

    public TrgEveryNMinutes(String startTime, int minutes) {
        this.minutes = minutes;
        this.timeStamp = startTime;
        trgTime = new TrgTime();
        trgTime.setTime(startTime);
    }

    public void setMinutes(int minutes) {
            if (minutes > -1) {
            this.minutes = minutes;}
    }

    @Override
    public Boolean trigger() {
        if (trgTime.alarm()){
            timeStamp = pl.getFutureInXMin(minutes);
            trgTime.setTime(timeStamp);
            return true;
        }
        return false;
    }

    @Override
    public void reset() {
        timeStamp = pl.getCurrentTimeStamp();
    }
}
 

fukurou

the supreme coder
ADMIN
python LGcore update:
Python:
    def getFutureInXMin(self, extra_minutes: int) -> str:
        '''This method returns the date in x minutes'''
        right_now = datetime.datetime.now()
        final_time = right_now + datetime.timedelta(minutes=extra_minutes)
        regex: RegexUtil = RegexUtil()
        s1: str = str(final_time)
        s1 = regex.extractEnumRegex(enumRegexGrimoire.simpleTimeStamp, s1)
        if s1[0] == '0':
            s1 = s1[1:]
        return s1

    def getPastInXMin(self, less_minutes: int) -> str:
        '''This method returns the date x minutes before'''
        right_now = datetime.datetime.now()
        final_time = right_now - datetime.timedelta(minutes=less_minutes)
        regex: RegexUtil = RegexUtil()
        s1: str = str(final_time)
        s1 = regex.extractEnumRegex(enumRegexGrimoire.simpleTimeStamp, s1)
        if s1[0] == '0':
            s1 = s1[1:]
        return s1
 

fukurou

the supreme coder
ADMIN
Python:
class TrgEveryNMinutes(TrGEV3):
    # trigger returns true every minutes interval, post start time
    def __init__(self, startTime: str, minutes: str):
        self._playGround: PlayGround = PlayGround()
        self._minutes = minutes  # minute interval between triggerings
        self._timeStamp = startTime
        self._trgTime: TrgTime = TrgTime()
        self._trgTime.setTime(startTime)

    def setMinutes(self, minutes: int):
        if minutes > -1:
            self._minutes = minutes

    # override
    def trigger(self) -> bool:
        if self._trgTime.alarm():
            self._timeStamp = self._playGround.getFutureInXMin(self._minutes)
            self._trgTime.setTime(self._timeStamp)
            return True
        return False

    # override
    def reset(self):
        self._timeStamp = self._playGround.getCurrentTimeStamp()
 

fukurou

the supreme coder
ADMIN
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
    private PlayGround playGround = new PlayGround();
    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;
    }
}
 

fukurou

the supreme coder
ADMIN
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

    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
 
Top