Start work on parsing member files, outline month support functions.
This commit is contained in:
parent
affb30d9b6
commit
194615aa1d
1 changed files with 77 additions and 3 deletions
|
@ -24,6 +24,8 @@
|
|||
(chicken file)
|
||||
(chicken pathname)
|
||||
(chicken file posix)
|
||||
(chicken io)
|
||||
(chicken string)
|
||||
|
||||
(chicken process-context))
|
||||
|
||||
|
@ -108,8 +110,40 @@
|
|||
(print " ok."))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Members index
|
||||
;; Months support
|
||||
|
||||
(define (string->month s)
|
||||
(list 2023 1))
|
||||
|
||||
(define (month->string m)
|
||||
"2023-01")
|
||||
|
||||
(define (month=? m n)
|
||||
#f)
|
||||
|
||||
(define (month<? m n)
|
||||
#f)
|
||||
|
||||
(define (month-diff m n)
|
||||
; Inclusive?
|
||||
1)
|
||||
|
||||
(define (month-tests!)
|
||||
(display "[test] month ")
|
||||
;; Parsing
|
||||
;; Formatting
|
||||
;; Comparison less
|
||||
;; Comparison equal
|
||||
;; Comparison greater
|
||||
;; Difference - TODO: inclusive both ends?
|
||||
(print " ok."))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Members database
|
||||
|
||||
|
||||
;; Loads all symlinks from (*members-directory*) returning a list of
|
||||
;; pairs (name . destination)
|
||||
(define (load-members-raw-index)
|
||||
(let loop ((fns (directory (*members-directory*)))
|
||||
(rs '()))
|
||||
|
@ -123,7 +157,9 @@
|
|||
(cons (cons fn sl) rs)
|
||||
rs))))))
|
||||
|
||||
(define (members-expand-raw-index ri)
|
||||
;; Converts the raw members index to a list of dictionaries with keys
|
||||
;; 'id, 'name and 'file. File names are without directory element.
|
||||
(define (expand-members-raw-index ri)
|
||||
(let loop ((ri ri)
|
||||
(ds '()))
|
||||
(if (null? ri)
|
||||
|
@ -141,6 +177,41 @@
|
|||
(cons 'file dfn))
|
||||
ds))))))
|
||||
|
||||
;; Parses given key-value line. Key is up to first space, value is the
|
||||
;; rest of the line. If the line doesn't contain anything, returns #f.
|
||||
(define (parse-member-line l)
|
||||
;;(print 'pm)
|
||||
;;(print l)
|
||||
(let ((sp (string-split l " ")))
|
||||
(and sp
|
||||
(not (null? sp))
|
||||
(list (string->symbol (car sp))
|
||||
(string-intersperse (cdr sp))))))
|
||||
|
||||
;; TODO: student and suspend special handling - should create list of
|
||||
;; (start date) (stop date) which will be later sorted by date and
|
||||
;; computation performed
|
||||
(define (parse-member-lines ls)
|
||||
(let loop ((ls ls)
|
||||
(r (make-dict)))
|
||||
;;(print '---)
|
||||
;;(print r)
|
||||
(if (null? ls)
|
||||
r
|
||||
(let ((p (parse-member-line (car ls))))
|
||||
;;(print p)
|
||||
(loop (cdr ls)
|
||||
(if p
|
||||
(apply dict-set r p)
|
||||
r))))))
|
||||
|
||||
;; Loads lines from given file in (*members-directory*) and parses
|
||||
;; them.
|
||||
(define (load-member-file fn)
|
||||
(let* ((ffn (make-pathname (*members-directory*) fn))
|
||||
(f (open-input-file ffn))
|
||||
(ls (read-lines f)))
|
||||
(parse-member-lines ls)))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Run everything
|
||||
|
@ -152,8 +223,11 @@
|
|||
;; Run tests
|
||||
(print "Running self-tests:")
|
||||
(dict-tests!)
|
||||
(month-tests!)
|
||||
(print "All self-tests ok!")
|
||||
(newline)
|
||||
|
||||
;; Perform requested action
|
||||
(print (members-expand-raw-index (load-members-raw-index)))
|
||||
;(print (expand-members-raw-index (load-members-raw-index)))
|
||||
|
||||
(print (load-member-file "joe"))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue