Was hoping to get a bit of feedback on designing a rrule
. I'm wondering what the best way to create a minutely rule is but omit entire days. So for example get 5 minute intervals every weekday between some time but omit certain holidays. I thought of using something like
INTERVAL = 5
BUCKETS = int(60 / INTERVAL * 24)
WEEKDAYS = (MO, TU, WE, TH, FR)
nyd = rrule(MONTHLY, dtstart=datetime(2019, 1, 1, 0, 0), bymonth=1, byminute=range(0, 59, INTERVAL), byhour=range(0,24), bysetpos=range(1, BUCKETS + 1), byweekday=WEEKDAYS, count=300)
which works, but I'm wondering if this is some non recommended hackery. The reason I ask is because bysetpos
only supports values up until 366. For minutely and secondly data you could have situations where you want to use bysetpos
up to 1440 and 86400 respectively, so I'm wondering if bysetpos
is not intended for this use?
rruleset
with an exrule
.
INTERVAL = 5
BUCKETS = int(60 / INTERVAL * 24)
WEEKDAYS = (MO, TU, WE, TH, FR)
rrule_base = rrule(MINUTELY, dtstart=datetime(2019, 1, 1, 0, 0), count=300, byweekday=WEEKDAYS)
rrset = rruleset()
rrset.rrule(rrule_base)
for dt in holidays:
rrset.exrule(rrule_base.replace(dtstart=dt, until=(dt + timedelta(days=1)), count=None))
for dt in holidays:
for inst in rrule_base.between(dt, dt + timedelta(days=1)):
rrset.exdate(inst)
dateutil
a few times: https://ganssle.io/talks/#python-dateutil-talk
Following up on your comments about bysetpos
and the RFC, I don't see any mention of restricting this. My guess is that it was implemented with DAILY frequency in mind? The docstrings also don't mention anything
If given, it must be either an integer, or a sequence of integers,
positive or negative. Each given integer will specify an occurrence
number, corresponding to the nth occurrence of the rule inside the
frequency period. For example, a bysetpos of -1 if combined with a
MONTHLY frequency, and a byweekday of (MO, TU, WE, TH, FR), will
result in the last work day of every month.
list(rrule(MINUTELY, dtstart=datetime(2019, 1, 1, 0, 0), bysetpos=367, count=3, byweekday=MO))
In addition in playing around with this I think there may be an issue more broadly with bysetpos
when using MINUTELY
. This runs fine
In [11]: list(rrule(MINUTELY, dtstart=datetime(2019, 1, 1, 0, 0), bysetpos=1, count=1, byweekday=MO))
Out[11]: [datetime.datetime(2019, 1, 7, 0, 0)]
but this seems to run indefinitely
list(rrule(MINUTELY, dtstart=datetime(2019, 1, 1, 0, 0), bysetpos=2, count=1, byweekday=MO))
rrule._iter
yield
statement is never reached? Or else the algorithm is just taking a very long time, still haven't fully grokked how _iter
works
bysetpos
may be an exception here), I can transform the inputs the the rule to some canonicalization so that freq=MINUTELY, interval=60
and freq=HOURLY, interval=1
"compile down" to the same thing, which I can then optimize.
.whl
) for both dateutil and six, you shouldn't have to download anything to install them
pip download python-dateutil
should download all the files.