doc updates

This commit is contained in:
vaclavt 2022-03-06 19:58:30 +01:00
parent 45fcabe4b4
commit c27395aca5
4 changed files with 139 additions and 17 deletions

View File

@ -66,17 +66,17 @@ utils/local_install.sh
### KNOWNN BUGS
- server/client problem in std::string TcpNet::read_from_socket(int sockfd) - reading dows not know lenght to read
- (read-url "https://api.nasdaq.com/api/calendar/dividends/") ; hangs in sslclient.cpp line 132
### TODO
- add test for >>> (range 1.5 (inc 5.5)) => (1.500000 2.500000 3.500000 4.500000 5.500000)
- unify -f and -run options
- add debug support, at least call stack
- multiline editing (see kilocpp editor)
- execute system command should capture stderr
- add mem stats to benchmark
- order of arguments in functions like member and filter - filter swap lambda and list
- better output of !e in repl (resp !e !ee)
- unify -f and -run options
- add debug support, at least call stack
- add mem stats to benchmark
- execute system command should capture stderr
- multiline editing (see kilocpp editor)
#### Doc
- add functions from stdlib into doc

121
debug_cron_wip.lsp Normal file
View File

@ -0,0 +1,121 @@
; TODO read jovs specification from filesystem
(include "/usr/local/var/mlisp/terminal.lsp")
(defn cron::sleep-to-next-minute ()
(* 1000 (- 60 (int (date-to-str (get-universal-time) "%S")))))
(defn cron::eval-time-spec (val time_spec)
(cond
((nil? time_spec)
#t) ; no time_spec -> it's true
((= time_spec "*")
#t)
((string-regex? time_spec "^[0-9]{1,4}$")
(= val (int time_spec)))
((string-regex? time_spec "^[0-9]{1,2}-[0-9]{1,2}$")
(def interval (string-split time_spec "-"))
(and (>= val (int (first interval))) (<= val (int (second interval)))))
(#t
nil) ; TODO exception
)
)
(defn cron::add-job (name time_spec job)
; TODO if already there replace it
(set! cron::entries (push cron::entries (list name time_spec job)))
)
(defn cron::time-to-run (now time_spec)
(do
; second, minute, hour, day, month, year, day-of-the-week
(def time (decode-universal-time (get-universal-time)))
(def time_minute (second time))
(def time_hour (third time))
(def time_day (fourth time))
(def time_month (fifth time))
(def time_year (sixth time))
(def time_weekday (seventh time))
(def bool (cron::eval-time-spec time_minute (find-val-in-list time_spec "minute")))
(set! bool (and bool (cron::eval-time-spec time_hour (find-val-in-list time_spec "hour"))))
(set! bool (and bool (cron::eval-time-spec time_weekday (find-val-in-list time_spec "weekday"))))
(set! bool (and bool (cron::eval-time-spec time_day (find-val-in-list time_spec "day"))))
(set! bool (and bool (cron::eval-time-spec time_month (find-val-in-list time_spec "month"))))
(set! bool (and bool (cron::eval-time-spec time_year (find-val-in-list time_spec "year"))))
; (print "time-to-run test" bool)
bool
))
(defn cron::run-job (name code)
(do
;(print "running job:" name "->" code)
(def run_code (+ "(thread-create " (display code) ")"))
(eval (parse run_code))
)
)
(defn cron::start ()
(do
(def wait_time (cron::sleep-to-next-minute))
(print "cron daemon started, waiting" wait_time "miliseconds for first run")
; (thread-sleep wait_time)
(while (not cron::stop)
(def now (get-universal-time))
(for e cron::entries
(def job_name (first e))
(def time_spec (second e))
(def job_code (third e))
; (print "\n\n")
(def is_for_run (cron::time-to-run now time_spec))
; (print "DEBUG" job_name "checked" is_for_run)
(if is_for_run
(cron::run-job job_name job_code)
; (print "not running" job_name)
)
)
(thread-sleep (cron::sleep-to-next-minute))
)
(threads-join)
))
(defn cron::stop ()
(set! cron::stop #t))
(def cron::entries '()) ; must be here
(def cron::stop nil) ; must be here
(cron::add-job "every_min_print"
'(("minute" "*"))
'(print "executing: every_min_print"))
; '(do (sleep 3) (print "executing: every_min_print")))
(cron::add-job "every_min_between_00_and_05"
'(("minute" "00-05"))
'(print "executing: every_min_between_00_and_05"))
(cron::add-job "13:20_working_day"
'(("weekday" "1-5")("hour" "13")("minute" "20"))
'(print "executing: 13:20_working_day"))
(cron::add-job "15:20_working_day"
'(("weekday" "1-5")("hour" "15")("minute" "20"))
'(print "executing: 15:20_working_day"))
(cron::start)

View File

@ -102,17 +102,17 @@
|`(date-to-str date format)`|Converts date to formated string. Format is strftime format (https://www.tutorialspoint.com/c_standard_library/c_function_strftime.htm)|`>>> (date-to-str (get-universal-time) "%Y-%m-%d %H:%M:%S") => "2021-03-13 19:53:01"`|Date and time|
|`(str-to-date string format)`|Converst string to time of secs since epoch. |`>>> (str-to-date "2021-03-13 19:53:01" "%Y-%m-%d %H:%M:%S") => 1615665181`|Date and time|
|`(date-add date amount unit)`|Add number of units to date. A unit is one of 'year', 'month', 'day', 'hour', 'minute' or 'second'|`>>> (date-to-str (date-add (str-to-date "2021-03-13 19:53:01" "%Y-%m-%d %H:%M:%S") 10 "day") "%Y-%m-%d %H:%M:%S") => "2021-03-23 20:53:01"`|Date and time|
|`start-of-day datetime`|Returns epoch time of start of a day|`>>> (start-of-day (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S")) => 1620864000`|Date and time|
|`end-of-day datetime`|Returns epoch time of end of day|`>>> (end-of-day (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S")) => 1620950399`|Date and time|
|`start-of-month datetime`|Returns epoch time of start of month|`>>> (start-of-month (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S")) => 1619827200`|Date and time|
|`start-of-next-month datetime`|Returns epoch time of start of following month|`>>> (start-of-next-month (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S")) => 1622505599`|Date and time|
|`end-of-next-month datetime`|Returns epoch time of end of following month|`>>> (end-of-next-month datetime (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S")) => 1622505600`|Date and time|
|`end-of-month datetime`|Returns epoch time of end of month|`>>> (end-of-month (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S")) => 1625097599`|Date and time|
|`start-of-prev-month datetime`|Returns epoch time of start of previous month|`>>> (start-of-prev-month (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S")) => 1617235200`|Date and time|
|`end-of-prev-month datetime`|Returns epoch time of end of previous month|`>>> (end-of-prev-month (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S")) => 1619827199`|Date and time|
|`start-of-year datetime`|Returns epoch time of start of year|`>>> (start-of-year (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S")) => 1609459200`|Date and time|
|`end-of-year datetime`|Returns epoch time of end of year|`>>> (end-of-year (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S")) => 1640995199`|Date and time|
|`decode-universal-time time`|Returns the decoded time represented by the given universal time. Returns list with (second, minute, hour, day, month, year, day-of-the-week)|`>>> (decode-universal-time 0) => (0 0 0 1 1 1970 4)`|Date and time|
|`(start-of-day datetime)`|Returns epoch time of start of a day|`>>> (start-of-day (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S")) => 1620864000`|Date and time|
|`(end-of-day datetime)`|Returns epoch time of end of day|`>>> (end-of-day (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S")) => 1620950399`|Date and time|
|`(start-of-month datetime)`|Returns epoch time of start of month|`>>> (start-of-month (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S")) => 1619827200`|Date and time|
|`(start-of-next-month datetime)`|Returns epoch time of start of following month|`>>> (start-of-next-month (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S")) => 1622505599`|Date and time|
|`(end-of-next-month datetime)`|Returns epoch time of end of following month|`>>> (end-of-next-month datetime (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S")) => 1622505600`|Date and time|
|`(end-of-month datetime)`|Returns epoch time of end of month|`>>> (end-of-month (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S")) => 1625097599`|Date and time|
|`(start-of-prev-month datetime)`|Returns epoch time of start of previous month|`>>> (start-of-prev-month (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S")) => 1617235200`|Date and time|
|`(end-of-prev-month datetime)`|Returns epoch time of end of previous month|`>>> (end-of-prev-month (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S")) => 1619827199`|Date and time|
|`(start-of-year datetime)`|Returns epoch time of start of year|`>>> (start-of-year (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S")) => 1609459200`|Date and time|
|`(end-of-year datetime)`|Returns epoch time of end of year|`>>> (end-of-year (str-to-date "2021-05-13 10:32:12" "%Y-%m-%d %H:%M:%S")) => 1640995199`|Date and time|
|`(decode-universal-time datetime)`|Returns the decoded time represented by the given universal time. Returns list with (second, minute, hour, day, month, year, day-of-the-week)|`>>> (decode-universal-time 0) => (0 0 0 1 1 1970 4)`|Date and time|
|`(debug ..)`|Returns string representation of passed params|`>>> (debug '(1 2 3)) => "(1 2 3)"`|IO|
|`(display ..)`|Displays passed parameters|`>>> (display '(1 2 3)) => "(1 2 3)"`|IO|
|`(string-replace source substr replacement)`|Replace a substring with a replacement string in a source string|`>>> (string-replace "abcdefg" "de" "DE") => "abcDEfg"`|String manipulation|

View File

@ -52,6 +52,7 @@
(ut::define-test "result of (make-list 3)" '(ut::assert-equal '(nil nil nil) (make-list 3)))
(ut::define-test "result of (make-list-of 3 999)" '(ut::assert-equal '(999 999 999) (make-list-of 3 999)))
(ut::define-test "result of (range 1.5 5.5)" '(ut::assert-equal '(1.500000 2.500000 3.500000 4.500000) (range 1.5 5.5)))
(ut::define-test "result of (fact 5)" '(ut::assert-equal 120 (fact 5)))
(ut::define-test "result of (scitej 1000)" '(ut::assert-equal 500500 (scitej 1000)))