* random weekly event
@ 2014-07-15 19:57 Ivan Kanis
2014-07-15 21:58 ` Thorsten Jolitz
0 siblings, 1 reply; 5+ messages in thread
From: Ivan Kanis @ 2014-07-15 19:57 UTC (permalink / raw)
To: org mode
Hi,
I need to have org agenda (and then appt) manage an event once a week.
The catch is that is should happen at a random day and hour.
My thinking is that populating programmatically a year entry is probably
the sanest way to go about it.
Has anyone else done it?
Ivan
--
Repeated reboots of the system failed to solve problem.
-- BOFH excuse #20
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: random weekly event
2014-07-15 19:57 random weekly event Ivan Kanis
@ 2014-07-15 21:58 ` Thorsten Jolitz
2014-07-15 22:13 ` Thorsten Jolitz
2014-07-16 18:42 ` Ivan Kanis
0 siblings, 2 replies; 5+ messages in thread
From: Thorsten Jolitz @ 2014-07-15 21:58 UTC (permalink / raw)
To: emacs-orgmode
Ivan Kanis <ivan@kanis.fr> writes:
> Hi,
>
> I need to have org agenda (and then appt) manage an event once a week.
> The catch is that is should happen at a random day and hour.
>
> My thinking is that populating programmatically a year entry is probably
> the sanest way to go about it.
>
> Has anyone else done it?
This is not an arcane scientific solution, but should give a random
timestamp for between tomorrow and the end of the current week. You
could write a function (using run-with-timer) that runs this sunday at
00:00h and inserts a todo item with the returned timestamp into an
agenda file:
#+begin_src emacs-lisp
(defun tj/return-random-timestamp-this-week ()
"Insert random timestamp for this week."
(interactive)
(let* ((cal-info (decode-time (current-time)))
(dow (nth 6 cal-info))
(year (nth 5 cal-info))
(month (nth 4 cal-info))
(day (nth 3 cal-info))
(hour (nth 2 cal-info))
(random-day (+ day (1+ (random (- 5 dow)))))
(random-hour (random 23))
(random-minute (random 59))
(random-second (random 59)))
(format-time-string "%D %R"
(encode-time random-second
random-minute
random-hour
random-day
month
year))))
#+end_src
#+results:
: tj/return-random-timestamp-this-week
#+begin_src emacs-lisp :results raw
(let (res)
(dotimes (i 10 res)
(setq res (concat
res
(format "%d: %s\n"
(1+ i)
(tj/return-random-timestamp-this-week))))))
#+end_src
#+results:
1: 07/17/14 17:39
2: 07/16/14 18:18
3: 07/18/14 19:21
4: 07/17/14 12:58
5: 07/16/14 15:30
6: 07/16/14 16:17
7: 07/16/14 04:10
8: 07/16/14 21:37
9: 07/17/14 19:22
10: 07/16/14 13:39
--
cheers,
Thorsten
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: random weekly event
2014-07-15 21:58 ` Thorsten Jolitz
@ 2014-07-15 22:13 ` Thorsten Jolitz
2014-07-15 22:24 ` Thorsten Jolitz
2014-07-16 18:42 ` Ivan Kanis
1 sibling, 1 reply; 5+ messages in thread
From: Thorsten Jolitz @ 2014-07-15 22:13 UTC (permalink / raw)
To: emacs-orgmode
Thorsten Jolitz <tjolitz@gmail.com> writes:
> Ivan Kanis <ivan@kanis.fr> writes:
>
> #+begin_src emacs-lisp
> (defun tj/return-random-timestamp-this-week ()
> "Insert random timestamp for this week."
> (interactive)
> (let* ((cal-info (decode-time (current-time)))
> (dow (nth 6 cal-info))
> (year (nth 5 cal-info))
> (month (nth 4 cal-info))
> (day (nth 3 cal-info))
> (hour (nth 2 cal-info))
> (random-day (+ day (1+ (random (- 5 dow)))))
> (random-hour (random 23))
> (random-minute (random 59))
> (random-second (random 59)))
> (format-time-string "%D %R"
> (encode-time random-second
> random-minute
> random-hour
> random-day
> month
> year))))
ups, should be probably rather this:
,----
| (random-day (+ day (1+ (random (- 7 dow)))))
`----
limit is not included, see
,----[ C-h f random RET ]
| random is a built-in function in `C source code'.
|
| (random &optional LIMIT)
|
| Return a pseudo-random number.
| All integers representable in Lisp, i.e. between `most-negative-fixnum'
| and `most-positive-fixnum', inclusive, are equally likely.
|
| With positive integer LIMIT, return random number in interval [0,LIMIT).
| With argument t, set the random number seed from the current time and pid.
| With a string argument, set the seed based on the string's contents.
| Other values of LIMIT are ignored.
|
| See Info node `(elisp)Random Numbers' for more details.
|
| [back]
`----
--
cheers,
Thorsten
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: random weekly event
2014-07-15 22:13 ` Thorsten Jolitz
@ 2014-07-15 22:24 ` Thorsten Jolitz
0 siblings, 0 replies; 5+ messages in thread
From: Thorsten Jolitz @ 2014-07-15 22:24 UTC (permalink / raw)
To: emacs-orgmode
Thorsten Jolitz <tjolitz@gmail.com> writes:
> ups, should be probably rather this:
>
> ,----
> | (random-day (+ day (1+ (random (- 7 dow)))))
> `----
grrr ... (- 6 dow) of course
--
cheers,
Thorsten
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: random weekly event
2014-07-15 21:58 ` Thorsten Jolitz
2014-07-15 22:13 ` Thorsten Jolitz
@ 2014-07-16 18:42 ` Ivan Kanis
1 sibling, 0 replies; 5+ messages in thread
From: Ivan Kanis @ 2014-07-16 18:42 UTC (permalink / raw)
To: Thorsten Jolitz; +Cc: emacs-orgmode
July, 15 at 23:58 Thorsten Jolitz wrote:
> Ivan Kanis <ivan@kanis.fr> writes:
>
>> I need to have org agenda (and then appt) manage an event once a week.
>> The catch is that is should happen at a random day and hour.
>>
>> My thinking is that populating programmatically a year entry is probably
>> the sanest way to go about it.
>>
>> Has anyone else done it?
>
> This is not an arcane scientific solution, but should give a random
> timestamp for between tomorrow and the end of the current week. You
> could write a function (using run-with-timer) that runs this sunday at
> 00:00h and inserts a todo item with the returned timestamp into an
> agenda file:
Hi Thorsten,
Thanks it will get me there when I will write it. I turn off emacs at
home and at work so the run-with-timer will not work.
Take care,
Ivan
--
Hard drive sleeping. Let it wake up on it's own...
-- BOFH excuse #43
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2014-07-16 18:42 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-15 19:57 random weekly event Ivan Kanis
2014-07-15 21:58 ` Thorsten Jolitz
2014-07-15 22:13 ` Thorsten Jolitz
2014-07-15 22:24 ` Thorsten Jolitz
2014-07-16 18:42 ` Ivan Kanis
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.