From eff186cb4cdd993b4c98019ffb286decb82a6d5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pant=C5=AF=C4=8Dek?= Date: Thu, 26 Dec 2024 20:11:01 +0100 Subject: [PATCH 01/26] Start work on attendance sheet. --- src/Makefile | 11 ++++- src/export-sheet.scm | 97 ++++++++++++++++++++++++++++++++++++++++++++ src/hackerbase.scm | 10 ++++- 3 files changed, 115 insertions(+), 3 deletions(-) create mode 100644 src/export-sheet.scm diff --git a/src/Makefile b/src/Makefile index 010c646..624aa68 100644 --- a/src/Makefile +++ b/src/Makefile @@ -42,7 +42,8 @@ HACKERBASE-DEPS=hackerbase.scm cal-month.import.scm \ tests.import.scm notifications.import.scm logging.import.scm \ progress.import.scm cal-period.import.scm \ util-stdout.import.scm export-web-static.import.scm \ - dokuwiki.import.scm mailinglist.import.scm + dokuwiki.import.scm mailinglist.import.scm \ + export-sheet.import.scm HACKERBASE-OBJS=hackerbase.o testing.o listing.o cal-month.o \ cal-period.o ansi.o util-bst-ldict.o command-line.o mbase.o \ @@ -60,7 +61,7 @@ HACKERBASE-OBJS=hackerbase.o testing.o listing.o cal-month.o \ util-dir.o dokuwiki.o racket-kwargs.o duck.o util-bst.o \ util-bst-bdict.o util-bst-ldict.o util-bst-lset.o mailman2.o \ mailman-common.o mailman3.o mailman3-sql.o tiocgwinsz.o \ - mailinglist.o + mailinglist.o export-sheet.o GENDOC-SOURCES=gendoc.scm duck-extract.import.scm \ util-time.import.scm util-csv.import.scm util-git.import.scm \ @@ -559,3 +560,9 @@ MAILINGLIST-SOURCES=mailinglist.scm racket-kwargs.import.scm \ mailinglist.o: mailinglist.import.scm mailinglist.import.scm: $(MAILINGLIST-SOURCES) + +EXPORT-SHEET-SOURCES=export-sheet.scm mbase.import.scm \ + brmember.import.scm + +export-sheet.o: export-sheet.import.scm +export-sheet.import.scm: $(EXPORT-SHEET-SOURCES) diff --git a/src/export-sheet.scm b/src/export-sheet.scm new file mode 100644 index 0000000..5b4fd3c --- /dev/null +++ b/src/export-sheet.scm @@ -0,0 +1,97 @@ +;; +;; export-sheet.scm +;; +;; Export attendance sheet as MarkDown document. +;; +;; ISC License +;; +;; Copyright 2024 Brmlab, z.s. +;; Dominik Pantůček +;; +;; Permission to use, copy, modify, and/or distribute this software +;; for any purpose with or without fee is hereby granted, provided +;; that the above copyright notice and this permission notice appear +;; in all copies. +;; +;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL +;; WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED +;; WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE +;; AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR +;; CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS +;; OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, +;; NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN +;; CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +;; + +(declare (unit export-sheet)) + +(module + export-sheet + ( + print-attendance-sheet + ) + + (import scheme + (chicken base) + (chicken string) + (chicken format) + mbase + brmember + brmember-format + util-bst-ldict) + + (define (print-attendance-sheet MB) + (print "\\documentclass[11pt]{article}") + (print "\\usepackage[top=1cm,left=2cm,right=2cm,bottom=2cm]{geometry}") + (print "\\begin{document}") + (print "\\begin{center}") + (print + (format + "Prezenční listina ~A. Valné Hromady brmlab z.s. konané ~A v sídle spolku" + 666 + "1.2.3456")) + (newline) + (print "\\vskip1em") + (newline) + (define colnames + '((id) Nick Name Surname (Balance) (Active) Signature)) + (print + (format + "\\begin{tabular}{|~A|}" + (string-intersperse + (map + (lambda (x) + "l") + colnames) + "|"))) + (print + (string-intersperse + (map + (lambda (x) + (format + "\\textbf{~A}" + (if (symbol? x) + (symbol->string x) + (symbol->string (car x))))) + colnames) + "&") + "\\\\") + (print "\\hline") + (let loop ((mrs (find-members-by-predicate + MB (lambda (mr) + (brmember-active? mr))))) + (when (not (null? mrs)) + (let* ((mr (car mrs)) + (info (ldict-ref mr 'info)) + (name (ldict-ref info 'name "ERROR"))) + (print + (brmember-id mr) + " & " + "name" + " \\\\") + (loop (cdr mrs))))) + (print "\\end{tabular}") + (print "\\end{center}") + (print "\\end{document}")) + + ) diff --git a/src/hackerbase.scm b/src/hackerbase.scm index 0633a49..3e67d50 100644 --- a/src/hackerbase.scm +++ b/src/hackerbase.scm @@ -51,7 +51,8 @@ dokuwiki racket-kwargs util-string - mailinglist) + mailinglist + export-sheet) ;; Command-line options and configurable parameters (define -needs-bank- (make-parameter #f)) @@ -182,6 +183,10 @@ (-stats (file:gnuplot-data) "Get stats for all months" (-action- 'print-stats) (-fname- file:gnuplot-data)) + (-sheet (filename) "Generate attendance sheet" + (-needs-bank- #t) + (-action- 'gen-sheet)) + "" "Mailman Actions:" (-mlsync () "Synchronize internal ML" @@ -354,6 +359,9 @@ ((genweb) (log-info "Generating static web files") (gen-html-members MB (-web-dir-))) + ((gen-sheet) + (log-info "Generating attendance sheet") + (print-attendance-sheet MB)) ((edit) (if mr (let () From 9eb835fa723ab86aaf259895e11e55669634eed6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pant=C5=AF=C4=8Dek?= Date: Thu, 26 Dec 2024 20:26:41 +0100 Subject: [PATCH 02/26] Names cleanup, alignment and amount formatting. --- src/export-sheet.scm | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/src/export-sheet.scm b/src/export-sheet.scm index 5b4fd3c..d0dd141 100644 --- a/src/export-sheet.scm +++ b/src/export-sheet.scm @@ -38,7 +38,9 @@ mbase brmember brmember-format - util-bst-ldict) + util-bst-ldict + members-payments + util-format) (define (print-attendance-sheet MB) (print "\\documentclass[11pt]{article}") @@ -61,9 +63,11 @@ (string-intersperse (map (lambda (x) - "l") + (if (symbol? x) + "l" "r")) colnames) "|"))) + (print "\\hline") (print (string-intersperse (map @@ -83,12 +87,37 @@ (when (not (null? mrs)) (let* ((mr (car mrs)) (info (ldict-ref mr 'info)) - (name (ldict-ref info 'name "ERROR"))) + (name (ldict-ref info 'name "ERROR")) + (name* (string-translate* + name + '(("_" . " ")))) + (namel (string-split name*)) + (sname (car (reverse namel))) + (fname + (string-intersperse + (reverse + (cdr + (reverse namel))) + " "))) (print (brmember-id mr) " & " - "name" + (string-translate* + (brmember-nick mr) + '(("_" . "\\_"))) + " & " + fname + " & " + sname + " & " + (format-amount + (member-total-balance mr)) + " & " + "?" + " & " + "~ ~ ~ ~ ~" " \\\\") + (print "\\hline") (loop (cdr mrs))))) (print "\\end{tabular}") (print "\\end{center}") From fe42315cd9af3dc322bec89a6bd33e6d1ed6a96f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pant=C5=AF=C4=8Dek?= Date: Thu, 26 Dec 2024 20:58:14 +0100 Subject: [PATCH 03/26] Number of active months. --- src/export-sheet.scm | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/export-sheet.scm b/src/export-sheet.scm index d0dd141..b8e9804 100644 --- a/src/export-sheet.scm +++ b/src/export-sheet.scm @@ -40,7 +40,9 @@ brmember-format util-bst-ldict members-payments - util-format) + util-format + members-fees + srfi-1) (define (print-attendance-sheet MB) (print "\\documentclass[11pt]{article}") @@ -98,7 +100,19 @@ (reverse (cdr (reverse namel))) - " "))) + " ")) + (cal (member-calendar mr)) + (rcal (reverse cal)) + (rcal12 + (if (> (length rcal) 12) + (take rcal 12) + rcal)) + (acal12 (map cadr rcal12)) + (acal12* (map (lambda (f) (if (memq 'active f) 1 0)) acal12)) + (numactive (foldl + 0 acal12*)) + ) + (display acal12* (current-error-port)) + (newline (current-error-port)) (print (brmember-id mr) " & " @@ -113,7 +127,7 @@ (format-amount (member-total-balance mr)) " & " - "?" + numactive " & " "~ ~ ~ ~ ~" " \\\\") From 51a108ce64a3bd39858374a7d8f53819c57f571e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pant=C5=AF=C4=8Dek?= Date: Thu, 26 Dec 2024 21:08:28 +0100 Subject: [PATCH 04/26] Generate file based on command-line argument. --- src/Makefile | 7 +++++-- src/export-sheet.scm | 18 +++++++++++++----- src/hackerbase.scm | 4 +++- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/Makefile b/src/Makefile index 624aa68..8707242 100644 --- a/src/Makefile +++ b/src/Makefile @@ -561,8 +561,11 @@ MAILINGLIST-SOURCES=mailinglist.scm racket-kwargs.import.scm \ mailinglist.o: mailinglist.import.scm mailinglist.import.scm: $(MAILINGLIST-SOURCES) -EXPORT-SHEET-SOURCES=export-sheet.scm mbase.import.scm \ - brmember.import.scm +EXPORT-SHEET-SOURCES=export-sheet.scm mbase.import.scm \ + brmember.import.scm brmember-format.import.scm \ + util-bst-ldict.import.scm members-payments.import.scm \ + util-format.import.scm members-fees.import.scm \ + cal-period.import.scm export-sheet.o: export-sheet.import.scm export-sheet.import.scm: $(EXPORT-SHEET-SOURCES) diff --git a/src/export-sheet.scm b/src/export-sheet.scm index b8e9804..90ac1d9 100644 --- a/src/export-sheet.scm +++ b/src/export-sheet.scm @@ -35,6 +35,7 @@ (chicken base) (chicken string) (chicken format) + srfi-1 mbase brmember brmember-format @@ -42,10 +43,10 @@ members-payments util-format members-fees - srfi-1) + cal-period) (define (print-attendance-sheet MB) - (print "\\documentclass[11pt]{article}") + (print "\\documentclass[10pt]{article}") (print "\\usepackage[top=1cm,left=2cm,right=2cm,bottom=2cm]{geometry}") (print "\\begin{document}") (print "\\begin{center}") @@ -58,7 +59,7 @@ (print "\\vskip1em") (newline) (define colnames - '((id) Nick Name Surname (Balance) (Active) Signature)) + '((id) Nick Name Surname (Fee) (Balance) (Active) Signature)) (print (format "\\begin{tabular}{|~A|}" @@ -110,9 +111,14 @@ (acal12 (map cadr rcal12)) (acal12* (map (lambda (f) (if (memq 'active f) 1 0)) acal12)) (numactive (foldl + 0 acal12*)) + (spec-fee (brmember-spec-fee mr)) + (current-fee (if spec-fee + spec-fee + (member-calendar-entry->fee + (list (*current-month*) + (brmember-flags mr) + spec-fee)))) ) - (display acal12* (current-error-port)) - (newline (current-error-port)) (print (brmember-id mr) " & " @@ -124,6 +130,8 @@ " & " sname " & " + (format-amount current-fee) + " & " (format-amount (member-total-balance mr)) " & " diff --git a/src/hackerbase.scm b/src/hackerbase.scm index 3e67d50..9758e93 100644 --- a/src/hackerbase.scm +++ b/src/hackerbase.scm @@ -185,6 +185,7 @@ (-fname- file:gnuplot-data)) (-sheet (filename) "Generate attendance sheet" (-needs-bank- #t) + (-fname- filename) (-action- 'gen-sheet)) "" @@ -361,7 +362,8 @@ (gen-html-members MB (-web-dir-))) ((gen-sheet) (log-info "Generating attendance sheet") - (print-attendance-sheet MB)) + (parameterize ((current-output-port (open-output-file (-fname-)))) + (print-attendance-sheet MB))) ((edit) (if mr (let () From 53be61d3457609c55a9f8b14a0a89d64b7e2157e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pant=C5=AF=C4=8Dek?= Date: Thu, 26 Dec 2024 21:21:31 +0100 Subject: [PATCH 05/26] Generate date and GM number. --- src/export-sheet.scm | 14 +++++++++----- src/hackerbase.scm | 6 ++++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/export-sheet.scm b/src/export-sheet.scm index 90ac1d9..31c217f 100644 --- a/src/export-sheet.scm +++ b/src/export-sheet.scm @@ -43,18 +43,22 @@ members-payments util-format members-fees - cal-period) + cal-period + cal-day) - (define (print-attendance-sheet MB) + (define (print-attendance-sheet MB number) (print "\\documentclass[10pt]{article}") (print "\\usepackage[top=1cm,left=2cm,right=2cm,bottom=2cm]{geometry}") (print "\\begin{document}") (print "\\begin{center}") (print (format - "Prezenční listina ~A. Valné Hromady brmlab z.s. konané ~A v sídle spolku" - 666 - "1.2.3456")) + "Prezenční listina ~A. Valné Hromady brmlab z.s. konané ~A. ~A. ~A v sídle spolku" + number + (cal-day-day (*current-day*)) + (cal-day-month (*current-day*)) + (cal-day-year (*current-day*)) + )) (newline) (print "\\vskip1em") (newline) diff --git a/src/hackerbase.scm b/src/hackerbase.scm index 9758e93..7074d1e 100644 --- a/src/hackerbase.scm +++ b/src/hackerbase.scm @@ -67,6 +67,7 @@ (define -show-only-active- (make-parameter #f)) (define -notify-months- (make-parameter 1)) (define -send-emails- (make-parameter #f)) +(define -number- (make-parameter #f)) ;; Arguments parsing (command-line @@ -183,9 +184,10 @@ (-stats (file:gnuplot-data) "Get stats for all months" (-action- 'print-stats) (-fname- file:gnuplot-data)) - (-sheet (filename) "Generate attendance sheet" + (-sheet (filename gmnum) "Generate attendance sheet for given GM number" (-needs-bank- #t) (-fname- filename) + (-number- gmnum) (-action- 'gen-sheet)) "" @@ -363,7 +365,7 @@ ((gen-sheet) (log-info "Generating attendance sheet") (parameterize ((current-output-port (open-output-file (-fname-)))) - (print-attendance-sheet MB))) + (print-attendance-sheet MB (-number-)))) ((edit) (if mr (let () From e02853edc7638ee2207ce2a384afc8d04a57eb69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pant=C5=AF=C4=8Dek?= Date: Thu, 26 Dec 2024 22:20:17 +0100 Subject: [PATCH 06/26] Preliminary version of attendance sheet. --- src/export-sheet.scm | 44 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/src/export-sheet.scm b/src/export-sheet.scm index 31c217f..3dc9c29 100644 --- a/src/export-sheet.scm +++ b/src/export-sheet.scm @@ -48,7 +48,7 @@ (define (print-attendance-sheet MB number) (print "\\documentclass[10pt]{article}") - (print "\\usepackage[top=1cm,left=2cm,right=2cm,bottom=2cm]{geometry}") + (print "\\usepackage[top=1cm,left=1cm,right=2cm,bottom=2cm]{geometry}") (print "\\begin{document}") (print "\\begin{center}") (print @@ -63,7 +63,7 @@ (print "\\vskip1em") (newline) (define colnames - '((id) Nick Name Surname (Fee) (Balance) (Active) Signature)) + '((id) Nick Name Surname (Fee) (Balance) B (Active) A OK? Signature)) (print (format "\\begin{tabular}{|~A|}" @@ -88,6 +88,9 @@ "&") "\\\\") (print "\\hline") + (define valid-voters 0) + (define ok-balances 0) + (define ok-actives 0) (let loop ((mrs (find-members-by-predicate MB (lambda (mr) (brmember-active? mr))))) @@ -122,7 +125,17 @@ (list (*current-month*) (brmember-flags mr) spec-fee)))) + (balance-ok? (>= (member-total-balance mr) + (- current-fee))) + (active-ok? (>= numactive 9)) + (vote-ok? (and balance-ok? active-ok?)) ) + (when balance-ok? + (set! ok-balances (+ ok-balances 1))) + (when active-ok? + (set! ok-actives (+ ok-actives 1))) + (when vote-ok? + (set! valid-voters (+ valid-voters 1))) (print (brmember-id mr) " & " @@ -134,19 +147,40 @@ " & " sname " & " - (format-amount current-fee) + current-fee " & " - (format-amount + (format-amount-tex (member-total-balance mr)) " & " + (if balance-ok? + "Y" + "--") + " & " numactive " & " + (if active-ok? + "Y" + "--") + " & " + (if vote-ok? + "Y" + "--") + " & " "~ ~ ~ ~ ~" " \\\\") (print "\\hline") (loop (cdr mrs))))) (print "\\end{tabular}") (print "\\end{center}") - (print "\\end{document}")) + (print "\\end{document}") + (print "% valid-voters = " valid-voters) + (print "% valid-balances = " ok-balances) + (print "% valid-actives = " ok-actives) + ) + + (define (format-amount-tex amt) + (string-translate* + (format-amount amt) + '(("--" . "--{}--")))) ) From b25fbd407dc38a23cd2f7289410d76cb881fbba1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pant=C5=AF=C4=8Dek?= Date: Thu, 2 Jan 2025 15:06:32 +0100 Subject: [PATCH 07/26] Split out mbase-stats into separate query module. --- src/Makefile | 11 +++++- src/hackerbase.scm | 3 +- src/mbase-query.scm | 92 ++++++++++++++++++++++++++++++++++++++++++++ src/mbase.scm | 43 --------------------- src/members-fees.scm | 14 +++++++ 5 files changed, 117 insertions(+), 46 deletions(-) create mode 100644 src/mbase-query.scm diff --git a/src/Makefile b/src/Makefile index 8707242..cd59f87 100644 --- a/src/Makefile +++ b/src/Makefile @@ -43,7 +43,7 @@ HACKERBASE-DEPS=hackerbase.scm cal-month.import.scm \ progress.import.scm cal-period.import.scm \ util-stdout.import.scm export-web-static.import.scm \ dokuwiki.import.scm mailinglist.import.scm \ - export-sheet.import.scm + export-sheet.import.scm mbase-query.import.scm HACKERBASE-OBJS=hackerbase.o testing.o listing.o cal-month.o \ cal-period.o ansi.o util-bst-ldict.o command-line.o mbase.o \ @@ -61,7 +61,7 @@ HACKERBASE-OBJS=hackerbase.o testing.o listing.o cal-month.o \ util-dir.o dokuwiki.o racket-kwargs.o duck.o util-bst.o \ util-bst-bdict.o util-bst-ldict.o util-bst-lset.o mailman2.o \ mailman-common.o mailman3.o mailman3-sql.o tiocgwinsz.o \ - mailinglist.o export-sheet.o + mailinglist.o export-sheet.o mbase-query.o GENDOC-SOURCES=gendoc.scm duck-extract.import.scm \ util-time.import.scm util-csv.import.scm util-git.import.scm \ @@ -569,3 +569,10 @@ EXPORT-SHEET-SOURCES=export-sheet.scm mbase.import.scm \ export-sheet.o: export-sheet.import.scm export-sheet.import.scm: $(EXPORT-SHEET-SOURCES) + +MBASE-QUERY-SOURCES=mbase-query.scm mbase.import.scm \ + brmember.import.scm util-bst-ldict.scm primes.import.scm \ + cal-period.import.scm cal-month.import.scm + +mbase-query.o: mbase-query.import.scm +mbase-query.import.scm: $(MBASE-QUERY-SOURCES) diff --git a/src/hackerbase.scm b/src/hackerbase.scm index 7074d1e..ce6c781 100644 --- a/src/hackerbase.scm +++ b/src/hackerbase.scm @@ -52,7 +52,8 @@ racket-kwargs util-string mailinglist - export-sheet) + export-sheet + mbase-query) ;; Command-line options and configurable parameters (define -needs-bank- (make-parameter #f)) diff --git a/src/mbase-query.scm b/src/mbase-query.scm new file mode 100644 index 0000000..c9e3e4c --- /dev/null +++ b/src/mbase-query.scm @@ -0,0 +1,92 @@ +;; +;; mbase-query.scm +;; +;; Queries of various mbase derived attributes. +;; +;; ISC License +;; +;; Copyright 2023-2025 Brmlab, z.s. +;; Dominik Pantůček +;; +;; Permission to use, copy, modify, and/or distribute this software +;; for any purpose with or without fee is hereby granted, provided +;; that the above copyright notice and this permission notice appear +;; in all copies. +;; +;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL +;; WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED +;; WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE +;; AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR +;; CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS +;; OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, +;; NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN +;; CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +;; + +(declare (unit mbase-query)) + +(module + mbase-query + ( + mbase-info + mbase-stats + ) + + (import scheme + (chicken base) + srfi-1 + mbase + brmember + util-bst-ldict + primes + cal-period + cal-month) + + (define (members-base-oldest-month mb) + (make-cal-month 2015 1)) + + ;; Returns dictionary with statistics about the members base. + (define (mbase-info mb-arg) + (let* ((members (find-members-by-predicate mb-arg brmember-usable?)) + (di0 (make-ldict)) + (di1 (ldict-set di0 'invalid + (filter (compose not is-4digit-prime? brmember-id) members))) + (di2 (ldict-set di1 'active + (filter brmember-active? members))) + (di3 (ldict-set di2 'suspended + (filter brmember-suspended? members))) + (di4 (ldict-set di3 'students + (filter brmember-student? members))) + (di5 (ldict-set di4 'destroyed + (filter brmember-destroyed? members))) + (di6 (ldict-set di5 'month (*current-month*))) + (di7 (ldict-set di6 'total members)) + (di8 (ldict-set di7 'problems + (find-members-by-predicate mb-arg brmember-has-problems?))) + ;; add expected income + ;; add total balance of all members (including destroyed) + ;; add total balance of all active members (-only-active -like) + ;; add average age of active members + + ) + di8)) + + ;; Returns a list two lists: keys, data. + ;; Each data record contains values for all keys. + (define (mbase-stats mb) + (let ((keys '(month total active suspended students destroyed invalid))) + (let mloop ((data '()) + (month (members-base-oldest-month mb))) + (if (cal-month<=? month (*current-month*)) + (let ((bi (with-current-month month + (mbase-info mb)))) + (let kloop ((row (list (ldict-ref bi 'month))) + (keys (cdr keys))) + (if (null? keys) + (mloop (cons (reverse row) data) + (cal-month-add month 1)) + (kloop (cons (length (ldict-ref bi (car keys))) row) + (cdr keys))))) + (list keys (reverse data)))))) + + ) diff --git a/src/mbase.scm b/src/mbase.scm index 3412306..f2f12bb 100644 --- a/src/mbase.scm +++ b/src/mbase.scm @@ -50,8 +50,6 @@ mbase-update-by-id mbase-update - mbase-stats - mbase-add-unpaired mbase-unpaired @@ -207,47 +205,6 @@ (proc mr) mr))))) - ;; Returns dictionary with statistics about the members base. - (define (mbase-info mb-arg) - (let* ((members (find-members-by-predicate mb-arg brmember-usable?)) - (di0 (make-ldict)) - (di1 (ldict-set di0 'invalid - (filter (compose not is-4digit-prime? brmember-id) members))) - (di2 (ldict-set di1 'active - (filter brmember-active? members))) - (di3 (ldict-set di2 'suspended - (filter brmember-suspended? members))) - (di4 (ldict-set di3 'students - (filter brmember-student? members))) - (di5 (ldict-set di4 'destroyed - (filter brmember-destroyed? members))) - (di6 (ldict-set di5 'month (*current-month*))) - (di7 (ldict-set di6 'total members)) - (di8 (ldict-set di7 'problems - (find-members-by-predicate mb-arg brmember-has-problems?)))) - di8)) - - (define (members-base-oldest-month mb) - (make-cal-month 2015 1)) - - ;; Returns a list two lists: keys, data. - ;; Each data record contains values for all keys. - (define (mbase-stats mb) - (let ((keys '(month total active suspended students destroyed invalid))) - (let mloop ((data '()) - (month (members-base-oldest-month mb))) - (if (cal-month<=? month (*current-month*)) - (let ((bi (with-current-month month - (mbase-info mb)))) - (let kloop ((row (list (ldict-ref bi 'month))) - (keys (cdr keys))) - (if (null? keys) - (mloop (cons (reverse row) data) - (cal-month-add month 1)) - (kloop (cons (length (ldict-ref bi (car keys))) row) - (cdr keys))))) - (list keys (reverse data)))))) - ;; Adds unpaired transaction to given members-base (define (mbase-add-unpaired mb tr) (ldict-set mb 'unpaired diff --git a/src/members-fees.scm b/src/members-fees.scm index 5a3b0c3..7373497 100644 --- a/src/members-fees.scm +++ b/src/members-fees.scm @@ -41,6 +41,7 @@ member-calendar->table members-summary member-calendar-entry->fee + get-expected-income get-expected-income-string ) @@ -208,6 +209,19 @@ (cons 0 0) members))) + (define (get-expected-income mb) + (let* ((flst + (map (compose member-calendar-entry->fee make-member-calendar-entry) + (find-members-by-predicate mb brmember-active?))) + (amts (sort (delete-duplicates flst) <)) + (sums + (map + (lambda (amt) + (cons amt + (length (filter (lambda (v) (= v amt)) flst)))) + amts))) + (number->string (foldl + 0 (map (lambda (p) (* (car p) (cdr p))) sums))))) + (define (get-expected-income-string mb) (let* ((flst (map (compose member-calendar-entry->fee make-member-calendar-entry) From 0e9cfd546bb7ff327d1195933535c351cf0bdfd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pant=C5=AF=C4=8Dek?= Date: Thu, 2 Jan 2025 15:18:53 +0100 Subject: [PATCH 08/26] Add data for graph of expected income. --- src/Makefile | 3 ++- src/mbase-query.scm | 21 +++++++++++++++------ src/members-fees.scm | 2 +- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/Makefile b/src/Makefile index cd59f87..b8d623d 100644 --- a/src/Makefile +++ b/src/Makefile @@ -572,7 +572,8 @@ export-sheet.import.scm: $(EXPORT-SHEET-SOURCES) MBASE-QUERY-SOURCES=mbase-query.scm mbase.import.scm \ brmember.import.scm util-bst-ldict.scm primes.import.scm \ - cal-period.import.scm cal-month.import.scm + cal-period.import.scm cal-month.import.scm \ + members-fees.import.scm mbase-query.o: mbase-query.import.scm mbase-query.import.scm: $(MBASE-QUERY-SOURCES) diff --git a/src/mbase-query.scm b/src/mbase-query.scm index c9e3e4c..d54449e 100644 --- a/src/mbase-query.scm +++ b/src/mbase-query.scm @@ -40,7 +40,8 @@ util-bst-ldict primes cal-period - cal-month) + cal-month + members-fees) (define (members-base-oldest-month mb) (make-cal-month 2015 1)) @@ -63,18 +64,22 @@ (di7 (ldict-set di6 'total members)) (di8 (ldict-set di7 'problems (find-members-by-predicate mb-arg brmember-has-problems?))) - ;; add expected income + (di9 (ldict-set di8 'expected + (get-expected-income mb-arg))) ;; add total balance of all members (including destroyed) ;; add total balance of all active members (-only-active -like) ;; add average age of active members - ) - di8)) + di9)) ;; Returns a list two lists: keys, data. ;; Each data record contains values for all keys. (define (mbase-stats mb) - (let ((keys '(month total active suspended students destroyed invalid))) + (let ((keys + '(month + total active suspended students destroyed invalid + expected + ))) (let mloop ((data '()) (month (members-base-oldest-month mb))) (if (cal-month<=? month (*current-month*)) @@ -85,7 +90,11 @@ (if (null? keys) (mloop (cons (reverse row) data) (cal-month-add month 1)) - (kloop (cons (length (ldict-ref bi (car keys))) row) + (kloop (cons (let ((val (ldict-ref bi (car keys)))) + (if (list? val) + (length val) + val)) + row) (cdr keys))))) (list keys (reverse data)))))) diff --git a/src/members-fees.scm b/src/members-fees.scm index 7373497..1782f62 100644 --- a/src/members-fees.scm +++ b/src/members-fees.scm @@ -220,7 +220,7 @@ (cons amt (length (filter (lambda (v) (= v amt)) flst)))) amts))) - (number->string (foldl + 0 (map (lambda (p) (* (car p) (cdr p))) sums))))) + (foldl + 0 (map (lambda (p) (* (car p) (cdr p))) sums)))) (define (get-expected-income-string mb) (let* ((flst From 7dbdd3ea6e1a8e1298135180945d79c584268ebd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pant=C5=AF=C4=8Dek?= Date: Thu, 2 Jan 2025 16:10:00 +0100 Subject: [PATCH 09/26] Balance summaries for all members over time. --- src/Makefile | 2 +- src/hackerbase.scm | 1 + src/mbase-query.scm | 17 +++++++++++------ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Makefile b/src/Makefile index b8d623d..827b386 100644 --- a/src/Makefile +++ b/src/Makefile @@ -573,7 +573,7 @@ export-sheet.import.scm: $(EXPORT-SHEET-SOURCES) MBASE-QUERY-SOURCES=mbase-query.scm mbase.import.scm \ brmember.import.scm util-bst-ldict.scm primes.import.scm \ cal-period.import.scm cal-month.import.scm \ - members-fees.import.scm + members-fees.import.scm members-payments.import.scm mbase-query.o: mbase-query.import.scm mbase-query.import.scm: $(MBASE-QUERY-SOURCES) diff --git a/src/hackerbase.scm b/src/hackerbase.scm index ce6c781..9f29a94 100644 --- a/src/hackerbase.scm +++ b/src/hackerbase.scm @@ -184,6 +184,7 @@ (-action- 'genweb)) (-stats (file:gnuplot-data) "Get stats for all months" (-action- 'print-stats) + (-needs-bank- #t) (-fname- file:gnuplot-data)) (-sheet (filename gmnum) "Generate attendance sheet for given GM number" (-needs-bank- #t) diff --git a/src/mbase-query.scm b/src/mbase-query.scm index d54449e..d801a2f 100644 --- a/src/mbase-query.scm +++ b/src/mbase-query.scm @@ -41,7 +41,8 @@ primes cal-period cal-month - members-fees) + members-fees + members-payments) (define (members-base-oldest-month mb) (make-cal-month 2015 1)) @@ -52,8 +53,9 @@ (di0 (make-ldict)) (di1 (ldict-set di0 'invalid (filter (compose not is-4digit-prime? brmember-id) members))) + (active-members (filter brmember-active? members)) (di2 (ldict-set di1 'active - (filter brmember-active? members))) + active-members)) (di3 (ldict-set di2 'suspended (filter brmember-suspended? members))) (di4 (ldict-set di3 'students @@ -66,11 +68,14 @@ (find-members-by-predicate mb-arg brmember-has-problems?))) (di9 (ldict-set di8 'expected (get-expected-income mb-arg))) - ;; add total balance of all members (including destroyed) - ;; add total balance of all active members (-only-active -like) + (mbals (map member-total-balance active-members)) + (di10 (ldict-set di9 'balance + (foldl + 0 mbals))) + ;; advance payments + ;; debts of fees ;; add average age of active members ) - di9)) + di10)) ;; Returns a list two lists: keys, data. ;; Each data record contains values for all keys. @@ -78,7 +83,7 @@ (let ((keys '(month total active suspended students destroyed invalid - expected + expected balance ))) (let mloop ((data '()) (month (members-base-oldest-month mb))) From 227787597d5b48985913a7df995f0bca8d973992 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pant=C5=AF=C4=8Dek?= Date: Thu, 2 Jan 2025 16:22:37 +0100 Subject: [PATCH 10/26] Finish stats for debts. --- src/mbase-query.scm | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/mbase-query.scm b/src/mbase-query.scm index d801a2f..af7ed30 100644 --- a/src/mbase-query.scm +++ b/src/mbase-query.scm @@ -71,11 +71,20 @@ (mbals (map member-total-balance active-members)) (di10 (ldict-set di9 'balance (foldl + 0 mbals))) - ;; advance payments + (di11 (ldict-set di10 'advance + (foldl + 0 + (map (lambda (v) + (max 0 v)) + mbals)))) + (di12 (ldict-set di11 'debt + (foldl + 0 + (map (lambda (v) + (min 0 v)) + mbals)))) ;; debts of fees ;; add average age of active members ) - di10)) + di12)) ;; Returns a list two lists: keys, data. ;; Each data record contains values for all keys. @@ -83,7 +92,7 @@ (let ((keys '(month total active suspended students destroyed invalid - expected balance + expected balance advance debt ))) (let mloop ((data '()) (month (members-base-oldest-month mb))) From 6cfdf705c8d45e2b74a32dcdaf22e20251187742 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pant=C5=AF=C4=8Dek?= Date: Thu, 2 Jan 2025 16:58:41 +0100 Subject: [PATCH 11/26] Finish new stats. --- src/brmember.scm | 14 + src/cal-period.scm | 888 ++++++++++++++++++++++---------------------- src/mbase-query.scm | 14 +- 3 files changed, 471 insertions(+), 445 deletions(-) diff --git a/src/brmember.scm b/src/brmember.scm index 496dc96..cb065f4 100644 --- a/src/brmember.scm +++ b/src/brmember.scm @@ -87,6 +87,8 @@ brmember-spec-fee + brmember-age + brmember-tests! ) @@ -492,6 +494,18 @@ #f)) #f))) + (define (brmember-age mr) + (let ((born (brmember-info mr 'born #f))) + (if born + (let ((lst (string-split born "-"))) + (if (null? lst) + #f + (let ((y (string->number (car lst)))) + (if y + (- (current-year) y) + #f)))) + #f))) + ;; Self-tests (define (brmember-tests!) (run-tests diff --git a/src/cal-period.scm b/src/cal-period.scm index ea1cf3d..447f563 100644 --- a/src/cal-period.scm +++ b/src/cal-period.scm @@ -26,460 +26,464 @@ (declare (unit cal-period)) (module - cal-period - ( - *current-month* - *current-day* - - set-current-month! - set-current-day! - - with-current-month - with-current-day - - make-cal-period - - cal-period-since - cal-period-before - cal-period-scomment - cal-period-bcomment - - set-cal-period-scomment - - period-markers->cal-periods - - cal-periods-duration - - cal-month-in-period? - cal-month-in-periods? - - cal-month-find-period - - cal-day-in-period? - cal-day-in-periods? - - cal-periods->string - cal-periods-match - - make-cal-period-lookup-table - lookup-by-cal-period - - cal-ensure-month - cal-ensure-day - - cal-period-tests! - ) - - (import scheme - (chicken base) - (chicken sort) - (chicken time) - (chicken time posix) - (chicken format) - (chicken string) - cal-month - testing - util-tag - cal-day) - - ;; Type tag - (define TAG-CAL-PERIOD (make-tag CAL-PERIOD)) - - ;; Current month - if changed, we get the actual state for given month. - (define *current-month* - (make-parameter - (let ((d (seconds->local-time (current-seconds)))) - (make-cal-month (+ 1900 (vector-ref d 5)) - (+ (vector-ref d 4) 1))))) - - ;; Current month - if changed, we get the actual state for given month. - (define *current-day* - (make-parameter - (let ((d (seconds->local-time (current-seconds)))) - (make-cal-day (+ 1900 (vector-ref d 5)) - (+ (vector-ref d 4) 1) - (vector-ref d 3))))) - - ;; Changes both current-month and current-day based on given month - (define (set-current-month! m) - (*current-month* m) - (*current-day* (cal-ensure-day m))) - - ;; Changes both current-day and current-month based on given day - (define (set-current-day! d) - (*current-day* d) - (*current-month* (cal-ensure-month d))) - - ;; Parameterizes both current-month and current-day based on given - ;; month - (define-syntax with-current-month - (syntax-rules () - ((_ ms body ...) - (let ((m ms)) - (parameterize ((*current-month* m) - (*current-day* (cal-ensure-day m))) - body ...))))) - - ;; Parameterizes both current-day and current-month based on given - ;; day - (define-syntax with-current-day - (syntax-rules () - ((_ ds body ...) - (let ((d ds)) - (parameterize ((*current-day* d) - (*current-month* (cal-ensure-month d))) - body ...))))) - - ;; Creates a new period value with optional since and before - ;; comments. - (define (make-cal-period since before . args) - (let ((scomment (if (not (null? args)) (car args) #f)) - (bcomment (if (and (not (null? args)) - (not (null? (cdr args)))) - (cadr args) - #f))) - (list TAG-CAL-PERIOD since before scomment bcomment))) - - ;; Simple accessors - (define cal-period-since cadr) - (define cal-period-before caddr) - (define cal-period-scomment cadddr) - (define cal-period-bcomment (compose cadddr cdr)) - - ;; Direct updater - (define (set-cal-period-scomment p c) - (list TAG-CAL-PERIOD - (cal-period-since p) - (cal-period-before p) - c - (cal-period-bcomment p))) - - ;; Type predicate - (define (cal-period? p) - (and (pair? p) - (eq? (car p) - TAG-CAL-PERIOD))) - - ;; Month subtype predicate - (define (cal-period-month? p) - (and (cal-period? p) - (cal-month? (cal-period-since p)) - (cal-month? (cal-period-before p)))) - - ;; Day subtype predicate - (define (cal-period-day? p) - (and (cal-period? p) - (cal-day? (cal-period-since p)) - (cal-day? (cal-period-before p)))) - - ;; Validation - (define (cal-period-valid? p) - (and (pair? p) - (eq? (car p) - TAG-CAL-PERIOD) - (let ((since (cal-period-since p)) - (before (cal-period-before p))) - (or (and (cal-month? since) - (cal-month? before) - (cal-month<=? since before)) - (and (cal-day? since) - (cal-day? before) - (cal-day<=? since before)))))) - - ;; Sorts period markers (be it start or end) chronologically and - ;; returns the sorted list. - (define (sort-period-markers l) - (sort l - (lambda (a b) - (cal-day/monthcal-periods l) - (let loop ((l (sort-period-markers l)) - (ps '()) - (cb #f)) - (if (null? l) - (list #t - (if cb - (reverse (cons (make-cal-period (car cb) #f (cadr cb)) ps)) - (reverse ps)) - "" - -1) - (let* ((marker (car l)) - (rmt (if cb 'stop 'start)) - (mtype (car marker)) - (month (cadr marker)) - (line-number (if (null? (cddr marker)) - #f - (caddr marker))) - (comment (if (and line-number - (not (null? (cdddr marker)))) - (cadddr marker) - #f))) - (if (eq? mtype rmt) - (if cb - (loop (cdr l) - (cons (make-cal-period (car cb) month (cadr cb) comment) ps) - #f) - (loop (cdr l) - ps - (list month comment))) - (list #f - (reverse ps) - (sprintf "Invalid start/stop sequence marker ~A" marker) - line-number)))))) - - ;; Returns duration of period in months. Start is included, end is - ;; not. The period contains the month just before the specified end. - (define (cal-period->duration p) - (let* ((b (cal-period-since p)) - (e (cal-period-before p)) - (e- (if e e (*current-month*)))) - (cal-month-diff b e-))) - - ;; Returns sum of periods lengths. - (define (cal-periods-duration l) - (apply + (map cal-period->duration l))) - - ;; True if month belongs to given month period - start inclusive, end - ;; exclusive. - (define (cal-month-in-period? p . ml) - (let ((m (if (null? ml) - (*current-month*) - (cal-ensure-month (car ml)))) - (before (cal-ensure-month (cal-period-before p) #t)) - (since (cal-ensure-month (cal-period-since p)))) - (and (or (not before) - (cal-monthstring p) - (sprintf "~A..~A" - (cal-day/month->string (cal-period-since p)) - (cal-day/month->string (cal-period-before p)))) - - ;; Returns a string representing a list of periods. - (define (cal-periods->string ps) - (string-intersperse - (map cal-period->string ps) - ", ")) - - ;; Finds a period the month matches and returns it. If no period - ;; matches, it returns #f. - (define (cal-periods-match ps . ml) - (let ((m (if (null? ml) (*current-month*) (car ml)))) - (let loop ((ps ps)) - (if (null? ps) - #f - (if (cal-month-in-period? (car ps) m) - (car ps) - (loop (cdr ps))))))) - - ;; Creates lookup table from definition source - (define (make-cal-period-lookup-table source) - (let loop ((lst source) - (res '()) - (prev #f)) - (if (null? lst) - (reverse - (cons (cons (make-cal-period (apply make-cal-month (car prev)) #f) - (cdr prev)) - res)) - (loop (cdr lst) - (if prev - (cons (cons (make-cal-period (apply make-cal-month (car prev)) - (apply make-cal-month (caar lst))) - (cdr prev)) - res) - res) - (car lst))))) - - ;; Looks up current month and returns associated definitions - (define (lookup-by-cal-period table) - (let loop ((lst table)) - (if (null? lst) - #f - (if (cal-month-in-period? (caar lst)) - (cdar lst) - (loop (cdr lst)))))) - - ;; Wrapper that accepts either day or month and returns testable month - (define (cal-ensure-month v . stop?s) - (if v - (if (cal-month? v) - v - (if (cal-day? v) - (apply cal-day->month v stop?s) - #f)) - #f)) - - ;; Ensures day for checking the periods - (define (cal-ensure-day v) - (if v - (if (cal-day? v) - v - (if (cal-month? v) - (make-cal-day (cal-month-year v) - (cal-month-month v) - 1) - #f)) - #f)) - - ;; Performs self-tests of the period module. - (define (cal-period-tests!) - (run-tests cal-period - (test-equal? sort-period-markers - (sort-period-markers - `((start ,(make-cal-month 2023 1)) - (stop ,(make-cal-month 2022 10)) - (start ,(make-cal-month 2022 3)))) - `((start ,(make-cal-month 2022 3)) - (stop ,(make-cal-month 2022 10)) - (start ,(make-cal-month 2023 1)))) - (test-equal? period-markers->cal-periods - (period-markers->cal-periods + ( + current-year + *current-month* + *current-day* + + set-current-month! + set-current-day! + + with-current-month + with-current-day + + make-cal-period + + cal-period-since + cal-period-before + cal-period-scomment + cal-period-bcomment + + set-cal-period-scomment + + period-markers->cal-periods + + cal-periods-duration + + cal-month-in-period? + cal-month-in-periods? + + cal-month-find-period + + cal-day-in-period? + cal-day-in-periods? + + cal-periods->string + cal-periods-match + + make-cal-period-lookup-table + lookup-by-cal-period + + cal-ensure-month + cal-ensure-day + + cal-period-tests! + ) + + (import scheme + (chicken base) + (chicken sort) + (chicken time) + (chicken time posix) + (chicken format) + (chicken string) + cal-month + testing + util-tag + cal-day) + + ;; Type tag + (define TAG-CAL-PERIOD (make-tag CAL-PERIOD)) + + (define (current-year) + (cal-month-year (*current-month*))) + + ;; Current month - if changed, we get the actual state for given month. + (define *current-month* + (make-parameter + (let ((d (seconds->local-time (current-seconds)))) + (make-cal-month (+ 1900 (vector-ref d 5)) + (+ (vector-ref d 4) 1))))) + + ;; Current month - if changed, we get the actual state for given month. + (define *current-day* + (make-parameter + (let ((d (seconds->local-time (current-seconds)))) + (make-cal-day (+ 1900 (vector-ref d 5)) + (+ (vector-ref d 4) 1) + (vector-ref d 3))))) + + ;; Changes both current-month and current-day based on given month + (define (set-current-month! m) + (*current-month* m) + (*current-day* (cal-ensure-day m))) + + ;; Changes both current-day and current-month based on given day + (define (set-current-day! d) + (*current-day* d) + (*current-month* (cal-ensure-month d))) + + ;; Parameterizes both current-month and current-day based on given + ;; month + (define-syntax with-current-month + (syntax-rules () + ((_ ms body ...) + (let ((m ms)) + (parameterize ((*current-month* m) + (*current-day* (cal-ensure-day m))) + body ...))))) + + ;; Parameterizes both current-day and current-month based on given + ;; day + (define-syntax with-current-day + (syntax-rules () + ((_ ds body ...) + (let ((d ds)) + (parameterize ((*current-day* d) + (*current-month* (cal-ensure-month d))) + body ...))))) + + ;; Creates a new period value with optional since and before + ;; comments. + (define (make-cal-period since before . args) + (let ((scomment (if (not (null? args)) (car args) #f)) + (bcomment (if (and (not (null? args)) + (not (null? (cdr args)))) + (cadr args) + #f))) + (list TAG-CAL-PERIOD since before scomment bcomment))) + + ;; Simple accessors + (define cal-period-since cadr) + (define cal-period-before caddr) + (define cal-period-scomment cadddr) + (define cal-period-bcomment (compose cadddr cdr)) + + ;; Direct updater + (define (set-cal-period-scomment p c) + (list TAG-CAL-PERIOD + (cal-period-since p) + (cal-period-before p) + c + (cal-period-bcomment p))) + + ;; Type predicate + (define (cal-period? p) + (and (pair? p) + (eq? (car p) + TAG-CAL-PERIOD))) + + ;; Month subtype predicate + (define (cal-period-month? p) + (and (cal-period? p) + (cal-month? (cal-period-since p)) + (cal-month? (cal-period-before p)))) + + ;; Day subtype predicate + (define (cal-period-day? p) + (and (cal-period? p) + (cal-day? (cal-period-since p)) + (cal-day? (cal-period-before p)))) + + ;; Validation + (define (cal-period-valid? p) + (and (pair? p) + (eq? (car p) + TAG-CAL-PERIOD) + (let ((since (cal-period-since p)) + (before (cal-period-before p))) + (or (and (cal-month? since) + (cal-month? before) + (cal-month<=? since before)) + (and (cal-day? since) + (cal-day? before) + (cal-day<=? since before)))))) + + ;; Sorts period markers (be it start or end) chronologically and + ;; returns the sorted list. + (define (sort-period-markers l) + (sort l + (lambda (a b) + (cal-day/monthcal-periods l) + (let loop ((l (sort-period-markers l)) + (ps '()) + (cb #f)) + (if (null? l) + (list #t + (if cb + (reverse (cons (make-cal-period (car cb) #f (cadr cb)) ps)) + (reverse ps)) + "" + -1) + (let* ((marker (car l)) + (rmt (if cb 'stop 'start)) + (mtype (car marker)) + (month (cadr marker)) + (line-number (if (null? (cddr marker)) + #f + (caddr marker))) + (comment (if (and line-number + (not (null? (cdddr marker)))) + (cadddr marker) + #f))) + (if (eq? mtype rmt) + (if cb + (loop (cdr l) + (cons (make-cal-period (car cb) month (cadr cb) comment) ps) + #f) + (loop (cdr l) + ps + (list month comment))) + (list #f + (reverse ps) + (sprintf "Invalid start/stop sequence marker ~A" marker) + line-number)))))) + + ;; Returns duration of period in months. Start is included, end is + ;; not. The period contains the month just before the specified end. + (define (cal-period->duration p) + (let* ((b (cal-period-since p)) + (e (cal-period-before p)) + (e- (if e e (*current-month*)))) + (cal-month-diff b e-))) + + ;; Returns sum of periods lengths. + (define (cal-periods-duration l) + (apply + (map cal-period->duration l))) + + ;; True if month belongs to given month period - start inclusive, end + ;; exclusive. + (define (cal-month-in-period? p . ml) + (let ((m (if (null? ml) + (*current-month*) + (cal-ensure-month (car ml)))) + (before (cal-ensure-month (cal-period-before p) #t)) + (since (cal-ensure-month (cal-period-since p)))) + (and (or (not before) + (cal-monthstring p) + (sprintf "~A..~A" + (cal-day/month->string (cal-period-since p)) + (cal-day/month->string (cal-period-before p)))) + + ;; Returns a string representing a list of periods. + (define (cal-periods->string ps) + (string-intersperse + (map cal-period->string ps) + ", ")) + + ;; Finds a period the month matches and returns it. If no period + ;; matches, it returns #f. + (define (cal-periods-match ps . ml) + (let ((m (if (null? ml) (*current-month*) (car ml)))) + (let loop ((ps ps)) + (if (null? ps) + #f + (if (cal-month-in-period? (car ps) m) + (car ps) + (loop (cdr ps))))))) + + ;; Creates lookup table from definition source + (define (make-cal-period-lookup-table source) + (let loop ((lst source) + (res '()) + (prev #f)) + (if (null? lst) + (reverse + (cons (cons (make-cal-period (apply make-cal-month (car prev)) #f) + (cdr prev)) + res)) + (loop (cdr lst) + (if prev + (cons (cons (make-cal-period (apply make-cal-month (car prev)) + (apply make-cal-month (caar lst))) + (cdr prev)) + res) + res) + (car lst))))) + + ;; Looks up current month and returns associated definitions + (define (lookup-by-cal-period table) + (let loop ((lst table)) + (if (null? lst) + #f + (if (cal-month-in-period? (caar lst)) + (cdar lst) + (loop (cdr lst)))))) + + ;; Wrapper that accepts either day or month and returns testable month + (define (cal-ensure-month v . stop?s) + (if v + (if (cal-month? v) + v + (if (cal-day? v) + (apply cal-day->month v stop?s) + #f)) + #f)) + + ;; Ensures day for checking the periods + (define (cal-ensure-day v) + (if v + (if (cal-day? v) + v + (if (cal-month? v) + (make-cal-day (cal-month-year v) + (cal-month-month v) + 1) + #f)) + #f)) + + ;; Performs self-tests of the period module. + (define (cal-period-tests!) + (run-tests + cal-period + (test-equal? sort-period-markers + (sort-period-markers + `((start ,(make-cal-month 2023 1)) + (stop ,(make-cal-month 2022 10)) + (start ,(make-cal-month 2022 3)))) `((start ,(make-cal-month 2022 3)) (stop ,(make-cal-month 2022 10)) - (start ,(make-cal-month 2023 1)) - (stop ,(make-cal-month 2023 4)))) - `(#t - (,(make-cal-period (make-cal-month 2022 3) - (make-cal-month 2022 10) #f #f) - ,(make-cal-period (make-cal-month 2023 1) - (make-cal-month 2023 4) #f #f)) - "" - -1)) - (test-equal? period-markers->cal-periods-open - (period-markers->cal-periods - `((start ,(make-cal-month 2022 3)) - (stop ,(make-cal-month 2022 10)) - (start ,(make-cal-month 2023 1)) - (stop ,(make-cal-month 2023 4)) - (start ,(make-cal-month 2023 5)))) - `(#t - (,(make-cal-period (make-cal-month 2022 3) - (make-cal-month 2022 10) #f #f) - ,(make-cal-period (make-cal-month 2023 1) - (make-cal-month 2023 4) #f #f) - ,(make-cal-period (make-cal-month 2023 5) #f #f #f)) - "" - -1)) - (test-eq? cal-period->duration - (cal-period->duration (make-cal-period (make-cal-month 2023 1) - (make-cal-month 2023 4) #f #f)) - 3) - (parameterize ((*current-month* (make-cal-month 2023 4))) - (test-eq? cal-period->duration - (cal-period->duration (make-cal-period (make-cal-month 2023 1) #f #f #f)) - 3)) - (test-eq? cal-periods-duration - (cal-periods-duration `(,(make-cal-period (make-cal-month 2022 3) - (make-cal-month 2022 10) #f #f) - ,(make-cal-period (make-cal-month 2023 1) - (make-cal-month 2023 4) #f #f))) - 10) - (test-true cal-month-in-period? - (cal-month-in-period? (make-cal-period (make-cal-month 2022 1) - (make-cal-month 2022 4) #f #f) - (make-cal-month 2022 3))) - (test-false cal-month-in-period? + (start ,(make-cal-month 2023 1)))) + (test-equal? period-markers->cal-periods + (period-markers->cal-periods + `((start ,(make-cal-month 2022 3)) + (stop ,(make-cal-month 2022 10)) + (start ,(make-cal-month 2023 1)) + (stop ,(make-cal-month 2023 4)))) + `(#t + (,(make-cal-period (make-cal-month 2022 3) + (make-cal-month 2022 10) #f #f) + ,(make-cal-period (make-cal-month 2023 1) + (make-cal-month 2023 4) #f #f)) + "" + -1)) + (test-equal? period-markers->cal-periods-open + (period-markers->cal-periods + `((start ,(make-cal-month 2022 3)) + (stop ,(make-cal-month 2022 10)) + (start ,(make-cal-month 2023 1)) + (stop ,(make-cal-month 2023 4)) + (start ,(make-cal-month 2023 5)))) + `(#t + (,(make-cal-period (make-cal-month 2022 3) + (make-cal-month 2022 10) #f #f) + ,(make-cal-period (make-cal-month 2023 1) + (make-cal-month 2023 4) #f #f) + ,(make-cal-period (make-cal-month 2023 5) #f #f #f)) + "" + -1)) + (test-eq? cal-period->duration + (cal-period->duration (make-cal-period (make-cal-month 2023 1) + (make-cal-month 2023 4) #f #f)) + 3) + (parameterize ((*current-month* (make-cal-month 2023 4))) + (test-eq? cal-period->duration + (cal-period->duration (make-cal-period (make-cal-month 2023 1) #f #f #f)) + 3)) + (test-eq? cal-periods-duration + (cal-periods-duration `(,(make-cal-period (make-cal-month 2022 3) + (make-cal-month 2022 10) #f #f) + ,(make-cal-period (make-cal-month 2023 1) + (make-cal-month 2023 4) #f #f))) + 10) + (test-true cal-month-in-period? (cal-month-in-period? (make-cal-period (make-cal-month 2022 1) (make-cal-month 2022 4) #f #f) - (make-cal-month 2022 5))) - (test-true cal-month-in-periods? - (cal-month-in-periods? `(,(make-cal-period (make-cal-month 2022 1) - (make-cal-month 2022 4) #f #f) - ,(make-cal-period (make-cal-month 2023 5) - (make-cal-month 2023 10) #f #f)) (make-cal-month 2022 3))) - (test-true cal-month-in-periods? - (cal-month-in-periods? `(,(make-cal-period (make-cal-month 2022 1) - (make-cal-month 2022 4) #f #f) - ,(make-cal-period (make-cal-month 2023 5) - (make-cal-month 2023 10) #f #f)) - (make-cal-month 2023 7))) - (test-false cal-month-in-periods? + (test-false cal-month-in-period? + (cal-month-in-period? (make-cal-period (make-cal-month 2022 1) + (make-cal-month 2022 4) #f #f) + (make-cal-month 2022 5))) + (test-true cal-month-in-periods? (cal-month-in-periods? `(,(make-cal-period (make-cal-month 2022 1) (make-cal-month 2022 4) #f #f) ,(make-cal-period (make-cal-month 2023 5) (make-cal-month 2023 10) #f #f)) - (make-cal-month 2022 10))) - (test-equal? cal-period->string - (cal-period->string (make-cal-period (make-cal-month 2022 1) - (make-cal-month 2022 4) #f #f)) - "2022-01..2022-04") - (test-equal? cal-periods->string - (cal-periods->string `(,(make-cal-period (make-cal-month 2022 1) - (make-cal-month 2022 4) #f #f) - ,(make-cal-period (make-cal-month 2022 12) - (make-cal-month 2023 2) #f #f))) - "2022-01..2022-04, 2022-12..2023-02") - (test-false cal-periods-match - (cal-periods-match `(,(make-cal-period (make-cal-month 2022 1) - (make-cal-month 2022 4) #f #f) - ,(make-cal-period (make-cal-month 2022 12) - (make-cal-month 2023 2) #f #f)) - (make-cal-month 2022 5))) - (test-equal? cal-periods-match + (make-cal-month 2022 3))) + (test-true cal-month-in-periods? + (cal-month-in-periods? `(,(make-cal-period (make-cal-month 2022 1) + (make-cal-month 2022 4) #f #f) + ,(make-cal-period (make-cal-month 2023 5) + (make-cal-month 2023 10) #f #f)) + (make-cal-month 2023 7))) + (test-false cal-month-in-periods? + (cal-month-in-periods? `(,(make-cal-period (make-cal-month 2022 1) + (make-cal-month 2022 4) #f #f) + ,(make-cal-period (make-cal-month 2023 5) + (make-cal-month 2023 10) #f #f)) + (make-cal-month 2022 10))) + (test-equal? cal-period->string + (cal-period->string (make-cal-period (make-cal-month 2022 1) + (make-cal-month 2022 4) #f #f)) + "2022-01..2022-04") + (test-equal? cal-periods->string + (cal-periods->string `(,(make-cal-period (make-cal-month 2022 1) + (make-cal-month 2022 4) #f #f) + ,(make-cal-period (make-cal-month 2022 12) + (make-cal-month 2023 2) #f #f))) + "2022-01..2022-04, 2022-12..2023-02") + (test-false cal-periods-match (cal-periods-match `(,(make-cal-period (make-cal-month 2022 1) (make-cal-month 2022 4) #f #f) ,(make-cal-period (make-cal-month 2022 12) (make-cal-month 2023 2) #f #f)) - (make-cal-month 2022 2)) - (make-cal-period (make-cal-month 2022 1) - (make-cal-month 2022 4) #f #f)) - )) + (make-cal-month 2022 5))) + (test-equal? cal-periods-match + (cal-periods-match `(,(make-cal-period (make-cal-month 2022 1) + (make-cal-month 2022 4) #f #f) + ,(make-cal-period (make-cal-month 2022 12) + (make-cal-month 2023 2) #f #f)) + (make-cal-month 2022 2)) + (make-cal-period (make-cal-month 2022 1) + (make-cal-month 2022 4) #f #f)) + )) - ) + ) diff --git a/src/mbase-query.scm b/src/mbase-query.scm index af7ed30..df560af 100644 --- a/src/mbase-query.scm +++ b/src/mbase-query.scm @@ -47,6 +47,13 @@ (define (members-base-oldest-month mb) (make-cal-month 2015 1)) + (define (members-average-age mrs) + (let* ((ages (map brmember-age mrs)) + (valid (filter (lambda (x) x) ages)) + (num (length valid)) + (sum (foldl + 0 valid))) + (exact->inexact (/ sum num)))) + ;; Returns dictionary with statistics about the members base. (define (mbase-info mb-arg) (let* ((members (find-members-by-predicate mb-arg brmember-usable?)) @@ -81,10 +88,10 @@ (map (lambda (v) (min 0 v)) mbals)))) - ;; debts of fees - ;; add average age of active members + (di13 (ldict-set di12 'age + (members-average-age active-members))) ) - di12)) + di13)) ;; Returns a list two lists: keys, data. ;; Each data record contains values for all keys. @@ -93,6 +100,7 @@ '(month total active suspended students destroyed invalid expected balance advance debt + age ))) (let mloop ((data '()) (month (members-base-oldest-month mb))) From c8c71f84657d8f613e869eb9a9a8194eaacde666 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pant=C5=AF=C4=8Dek?= Date: Thu, 2 Jan 2025 17:42:13 +0100 Subject: [PATCH 12/26] Preliminary longtable version of attendance sheet. --- src/export-sheet.scm | 47 +++++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/src/export-sheet.scm b/src/export-sheet.scm index 3dc9c29..a88dd33 100644 --- a/src/export-sheet.scm +++ b/src/export-sheet.scm @@ -35,6 +35,7 @@ (chicken base) (chicken string) (chicken format) + (chicken sort) srfi-1 mbase brmember @@ -47,31 +48,42 @@ cal-day) (define (print-attendance-sheet MB number) - (print "\\documentclass[10pt]{article}") - (print "\\usepackage[top=1cm,left=1cm,right=2cm,bottom=2cm]{geometry}") - (print "\\begin{document}") - (print "\\begin{center}") + (print "\\documentclass{article}") + (print "\\usepackage{fancyhdr}") + (print "\\usepackage{longtable}") + (print "\\usepackage{lastpage}") + (print "\\usepackage[top=3cm,left=1cm,right=2cm,bottom=3cm]{geometry}") + (print "\\lhead{}") (print (format - "Prezenční listina ~A. Valné Hromady brmlab z.s. konané ~A. ~A. ~A v sídle spolku" + "\\chead{Prezenční listina ~A. Valné Hromady brmlab z.s. konané ~A. ~A. ~A v sídle spolku}" number (cal-day-day (*current-day*)) (cal-day-month (*current-day*)) (cal-day-year (*current-day*)) )) + (print "\\rhead{}") + (print "\\renewcommand{\\headrulewidth}{0pt}") + (print "\\lfoot{}") + (print "\\cfoot{Strana \\thepage{} ze \\pageref*{LastPage}}") + (print "\\rfoot{}") + (print "\\pagestyle{fancy}") + (print "\\begin{document}") + (print "\\begin{center}") (newline) (print "\\vskip1em") (newline) (define colnames - '((id) Nick Name Surname (Fee) (Balance) B (Active) A OK? Signature)) + '((id) Nick "Jméno" "Příjmení" (Fee) (Balance) B (Active) A OK? Signature)) + (print "\\renewcommand\\arraystretch{2.0}") (print (format - "\\begin{tabular}{|~A|}" + "\\begin{longtable}{|~A|}" (string-intersperse (map (lambda (x) - (if (symbol? x) - "l" "r")) + (if (list? x) + "r" "l")) colnames) "|"))) (print "\\hline") @@ -83,17 +95,24 @@ "\\textbf{~A}" (if (symbol? x) (symbol->string x) - (symbol->string (car x))))) + (if (string? x) + x + (symbol->string (car x)))))) colnames) "&") "\\\\") (print "\\hline") + (print "\\endhead") (define valid-voters 0) (define ok-balances 0) (define ok-actives 0) - (let loop ((mrs (find-members-by-predicate - MB (lambda (mr) - (brmember-active? mr))))) + (let loop ((mrs (sort + (find-members-by-predicate + MB (lambda (mr) + (brmember-active? mr))) + (lambda (a b) + (string Date: Thu, 2 Jan 2025 18:09:03 +0100 Subject: [PATCH 13/26] Typography improvements. --- src/export-sheet.scm | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/src/export-sheet.scm b/src/export-sheet.scm index a88dd33..5bc94cb 100644 --- a/src/export-sheet.scm +++ b/src/export-sheet.scm @@ -74,8 +74,8 @@ (print "\\vskip1em") (newline) (define colnames - '((id) Nick "Jméno" "Příjmení" (Fee) (Balance) B (Active) A OK? Signature)) - (print "\\renewcommand\\arraystretch{2.0}") + '((id) Nick "Jméno" "Příjmení" (Fee) (Bilance) ("\\begin{minipage}{15mm}\\begin{center}Aktivní\\\\Měsíce\\end{center}\\end{minipage}") OK? Podpis)) + (print "\\renewcommand\\arraystretch{2.1}") (print (format "\\begin{longtable}{|~A|}" @@ -97,7 +97,9 @@ (symbol->string x) (if (string? x) x - (symbol->string (car x)))))) + (if (string? (car x)) + (car x) + (symbol->string (car x))))))) colnames) "&") "\\\\") @@ -168,24 +170,36 @@ " & " current-fee " & " + "\\begin{minipage}{15mm}\\begin{flushright}" (format-amount-tex (member-total-balance mr)) - " & " + "\\\\" (if balance-ok? - "Y" - "--") - " & " - numactive + "Bez~dluhu" + "---~~~~~~") + "\\end{flushright}\\end{minipage}" " & " + ;(if balance-ok? + ; "Y" + ; "--") + ;" & " + "\\begin{minipage}{12mm}\\begin{center}" + numactive "/" 12 + "\\\\" (if active-ok? - "Y" - "--") + "Splněno" + "\\phantom{Sp}---\\phantom{Sp}") + "\\end{center}\\end{minipage}" " & " + ;(if active-ok? + ; "Y" + ; "--") + ;" & " (if vote-ok? "Y" "--") " & " - "~ ~ ~ ~ ~" + "~\\hskip24mm~" " \\\\") (print "\\hline") (loop (cdr mrs))))) From cebe6a6cf7e0befc47f070e17c5474298b936ff4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pant=C5=AF=C4=8Dek?= Date: Thu, 2 Jan 2025 19:34:13 +0100 Subject: [PATCH 14/26] Finish almost final version of attendance sheet. --- src/export-sheet.scm | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/export-sheet.scm b/src/export-sheet.scm index 5bc94cb..a907129 100644 --- a/src/export-sheet.scm +++ b/src/export-sheet.scm @@ -74,7 +74,9 @@ (print "\\vskip1em") (newline) (define colnames - '((id) Nick "Jméno" "Příjmení" (Fee) (Bilance) ("\\begin{minipage}{15mm}\\begin{center}Aktivní\\\\Měsíce\\end{center}\\end{minipage}") OK? Podpis)) + '((id) Nick "Jméno" "Příjmení" (Fee) (Bilance) + ("\\raisebox{2pt}{\\begin{minipage}{15mm}\\begin{center}Aktivní\\\\Měsíce\\end{center}\\end{minipage}}") + ((Hlas?)) Podpis)) (print "\\renewcommand\\arraystretch{2.1}") (print (format @@ -83,7 +85,10 @@ (map (lambda (x) (if (list? x) - "r" "l")) + (if (list? (car x)) + "c" + "r") + "l")) colnames) "|"))) (print "\\hline") @@ -99,7 +104,9 @@ x (if (string? (car x)) (car x) - (symbol->string (car x))))))) + (if (list? (car x)) + (symbol->string (caar x)) + (symbol->string (car x)))))))) colnames) "&") "\\\\") @@ -163,43 +170,43 @@ (string-translate* (brmember-nick mr) '(("_" . "\\_"))) - " & " + " & \\small " fname - " & " + " & \\small " sname " & " current-fee " & " - "\\begin{minipage}{15mm}\\begin{flushright}" + "\\raisebox{2pt}{\\begin{minipage}{15mm}\\begin{flushright}" (format-amount-tex (member-total-balance mr)) "\\\\" (if balance-ok? "Bez~dluhu" "---~~~~~~") - "\\end{flushright}\\end{minipage}" + "\\end{flushright}\\end{minipage}}" " & " ;(if balance-ok? ; "Y" ; "--") ;" & " - "\\begin{minipage}{12mm}\\begin{center}" + "\\raisebox{2pt}{\\begin{minipage}{12mm}\\begin{center}" numactive "/" 12 "\\\\" (if active-ok? "Splněno" "\\phantom{Sp}---\\phantom{Sp}") - "\\end{center}\\end{minipage}" + "\\end{center}\\end{minipage}}" " & " ;(if active-ok? ; "Y" ; "--") ;" & " (if vote-ok? - "Y" + "Ano" "--") " & " - "~\\hskip24mm~" + "~\\hskip28mm~" " \\\\") (print "\\hline") (loop (cdr mrs))))) From fa8466cfffa7f842599983fa61070d80ada1690d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pant=C5=AF=C4=8Dek?= Date: Thu, 2 Jan 2025 20:42:29 +0100 Subject: [PATCH 15/26] Fix typo prolems. --- src/members-print.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/members-print.scm b/src/members-print.scm index 4d5b2dd..e8b6720 100644 --- a/src/members-print.scm +++ b/src/members-print.scm @@ -380,7 +380,7 @@ (members-table-row (ansi #:magenta #:bold) "Expire Soon:" soon-expire-mrs "~N (~S)")) (members-pred-table-row mb - (ansi-string #:red #:bold "Prolems:") + (ansi-string #:red #:bold "Problems:") brmember-has-problems? "~N~E ~A") (if (null? debtor-mrs) From 5052a8d46f9af2e8ef19491ca1df5097a1a81c84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pant=C5=AF=C4=8Dek?= Date: Thu, 2 Jan 2025 20:45:33 +0100 Subject: [PATCH 16/26] Start work on changelog and banner for 1.18 version. --- CHANGELOG.md | 7 +++++++ src/texts.scm | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 32d0c05..5a45faf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ ChangeLog ========= +1.18 +---- + +* fix typo in members-print +* create LaTeX source of general meeting attendance sheet +* add expected income, cash flow and average age to stats + 1.17 - released 2024-10-01 -------------------------- diff --git a/src/texts.scm b/src/texts.scm index 6771016..53073dd 100644 --- a/src/texts.scm +++ b/src/texts.scm @@ -39,7 +39,7 @@ (chicken format)) ;; Short banner - (define banner-line "HackerBase 1.17 (c) 2023-2024 Brmlab, z.s.") + (define banner-line "HackerBase 1.18-dev (c) 2023-2024 Brmlab, z.s.") ;; Banner source with numbers for ANSI CSI SGR (define banner-source " From 826a5f1070202118717d977259dd52aea6a24922 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pant=C5=AF=C4=8Dek?= Date: Thu, 2 Jan 2025 20:50:50 +0100 Subject: [PATCH 17/26] Update copyright years. --- src/texts.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/texts.scm b/src/texts.scm index 53073dd..5e384b0 100644 --- a/src/texts.scm +++ b/src/texts.scm @@ -39,7 +39,7 @@ (chicken format)) ;; Short banner - (define banner-line "HackerBase 1.18-dev (c) 2023-2024 Brmlab, z.s.") + (define banner-line "HackerBase 1.18-dev (c) 2023-2025 Brmlab, z.s.") ;; Banner source with numbers for ANSI CSI SGR (define banner-source " From 306b9cb20e20f14dca56be1e0ae8338ae1a19a02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pant=C5=AF=C4=8Dek?= Date: Fri, 3 Jan 2025 11:00:44 +0100 Subject: [PATCH 18/26] Initial import of QR payment implementation. --- src/Makefile | 10 ++++-- src/qr-payment.scm | 76 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 src/qr-payment.scm diff --git a/src/Makefile b/src/Makefile index 827b386..5d5cae0 100644 --- a/src/Makefile +++ b/src/Makefile @@ -43,7 +43,8 @@ HACKERBASE-DEPS=hackerbase.scm cal-month.import.scm \ progress.import.scm cal-period.import.scm \ util-stdout.import.scm export-web-static.import.scm \ dokuwiki.import.scm mailinglist.import.scm \ - export-sheet.import.scm mbase-query.import.scm + export-sheet.import.scm mbase-query.import.scm \ + qr-payment.import.scm HACKERBASE-OBJS=hackerbase.o testing.o listing.o cal-month.o \ cal-period.o ansi.o util-bst-ldict.o command-line.o mbase.o \ @@ -61,7 +62,7 @@ HACKERBASE-OBJS=hackerbase.o testing.o listing.o cal-month.o \ util-dir.o dokuwiki.o racket-kwargs.o duck.o util-bst.o \ util-bst-bdict.o util-bst-ldict.o util-bst-lset.o mailman2.o \ mailman-common.o mailman3.o mailman3-sql.o tiocgwinsz.o \ - mailinglist.o export-sheet.o mbase-query.o + mailinglist.o export-sheet.o mbase-query.o qr-payment.o GENDOC-SOURCES=gendoc.scm duck-extract.import.scm \ util-time.import.scm util-csv.import.scm util-git.import.scm \ @@ -577,3 +578,8 @@ MBASE-QUERY-SOURCES=mbase-query.scm mbase.import.scm \ mbase-query.o: mbase-query.import.scm mbase-query.import.scm: $(MBASE-QUERY-SOURCES) + +QR-PAYMENT-SOURCES=qr-payment.scm + +qr-payment.o: qr-payment.import.scm +qr-payment.import.scm: $(QR-PAYMENT-SOURCES) diff --git a/src/qr-payment.scm b/src/qr-payment.scm new file mode 100644 index 0000000..ed59c4f --- /dev/null +++ b/src/qr-payment.scm @@ -0,0 +1,76 @@ +;; +;; qr-payment.scm +;; +;; QR payment generator. +;; +;; ISC License +;; +;; Copyright 2023-2025 Brmlab, z.s. +;; Dominik Pantůček +;; +;; Permission to use, copy, modify, and/or distribute this software +;; for any purpose with or without fee is hereby granted, provided +;; that the above copyright notice and this permission notice appear +;; in all copies. +;; +;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL +;; WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED +;; WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE +;; AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR +;; CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS +;; OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, +;; NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN +;; CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +;; + +(declare (unit qr-payment)) + +(module + qr-payment + ( + make-qrp + make-brmlab-qrp + ) + + (import scheme + (chicken format) + (chicken string) + (chicken base)) + + (define (make-empty-qrp . vs) + (let ((v (if (null? vs) "1.0" (car vs)))) + (list v "SPD"))) + + (define (add-field-to-qrp qrp key value) + (cons (format "~A:~A" key value) + qrp)) + + (define (serialize-qrp qrp) + (string-intersperse (reverse qrp) "*")) + + (define (ensure-amount-format amt) + (if (string? amt) + amt + amt)) + + (define (make-qrp iban amt cc vs msg) + (let loop ((keys '(ACC AM CC MSG X-CS)) + (vals (list iban (ensure-amount-format amt) cc msg vs)) + (qrp (make-empty-qrp))) + (if (null? keys) + (serialize-qrp qrp) + (loop (cdr keys) + (cdr vals) + (add-field-to-qrp qrp (car keys) (car vals)))))) + + (define (make-brmlab-qrp amt cc vs) + (let ((iban (if (equal? cc "CZK") + "CZ0520100000002500079551" + (if (equal? cc "EUR") + "CZ9320100000002100079552" + (error "Invalid currency!"))))) + (make-qrp iban amt cc vs "Brmlab"))) + + (print (make-brmlab-qrp 1000 "CZK" 1234)) + + ) From bbbc6527a0fec3330092a7f044009863913be29e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pant=C5=AF=C4=8Dek?= Date: Fri, 3 Jan 2025 11:34:18 +0100 Subject: [PATCH 19/26] Ensure proper amount format and prepare for generating QR code. --- src/qr-payment.scm | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/qr-payment.scm b/src/qr-payment.scm index ed59c4f..be79b50 100644 --- a/src/qr-payment.scm +++ b/src/qr-payment.scm @@ -30,6 +30,7 @@ ( make-qrp make-brmlab-qrp + make-brmlab-qrp-svg-string ) (import scheme @@ -49,9 +50,19 @@ (string-intersperse (reverse qrp) "*")) (define (ensure-amount-format amt) - (if (string? amt) - amt - amt)) + (let* ((n (if (string? amt) + (string->number amt) + amt)) + (s (number->string n)) + (f (string-split str ".")) + (i? (null? (cdr f)))) + (format "~A.~A" + (car f) + (if i? + ".00" + (substring + (string-append (cadr f) "0") + 0 2))))) (define (make-qrp iban amt cc vs msg) (let loop ((keys '(ACC AM CC MSG X-CS)) @@ -71,6 +82,12 @@ (error "Invalid currency!"))))) (make-qrp iban amt cc vs "Brmlab"))) - (print (make-brmlab-qrp 1000 "CZK" 1234)) + (define (qrp-create-svg-string qrps) + ;; qrencode -t svg -o - -l M + "TODO") + + (define (make-brmlab-qrp-svg-string amt cc vs) + (qrp-create-svg-string + (make-brmlab-qrp amt cc vs))) ) From 4d73afe3c5aee4c75c7eef286c7cc1cb8ce3cb17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pant=C5=AF=C4=8Dek?= Date: Fri, 3 Jan 2025 16:56:59 +0100 Subject: [PATCH 20/26] Preliminary QR code embedding. --- src/Makefile | 5 +++-- src/export-web-static.scm | 11 ++++++++++- src/qr-payment.scm | 21 ++++++++++++++++----- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/Makefile b/src/Makefile index 5d5cae0..6e6d80e 100644 --- a/src/Makefile +++ b/src/Makefile @@ -475,7 +475,8 @@ box-drawing.import.scm: $(BOX-DRAWING-SOURCES) EXPORT-WEB-STATIC-SOURCES=export-web-static.scm brmember.import.scm \ util-dir.import.scm mbase.import.scm \ members-payments.import.scm cal-day.import.scm \ - util-git.import.scm configuration.import.scm texts.import.scm + util-git.import.scm configuration.import.scm texts.import.scm \ + members-fees.import.scm qr-payment.import.scm export-web-static.o: export-web-static.import.scm export-web-static.import.scm: $(EXPORT-WEB-STATIC-SOURCES) @@ -579,7 +580,7 @@ MBASE-QUERY-SOURCES=mbase-query.scm mbase.import.scm \ mbase-query.o: mbase-query.import.scm mbase-query.import.scm: $(MBASE-QUERY-SOURCES) -QR-PAYMENT-SOURCES=qr-payment.scm +QR-PAYMENT-SOURCES=qr-payment.scm util-io.import.scm qr-payment.o: qr-payment.import.scm qr-payment.import.scm: $(QR-PAYMENT-SOURCES) diff --git a/src/export-web-static.scm b/src/export-web-static.scm index 4b0b15d..6ac3a3d 100644 --- a/src/export-web-static.scm +++ b/src/export-web-static.scm @@ -45,7 +45,9 @@ util-git configuration texts - logging) + logging + qr-payment + members-fees) ;; HTML entities (define (sanitize-html str) @@ -110,6 +112,13 @@ (print "") (print "") (print "
") + (let ((fee (member-calendar-entry->fee + (make-member-calendar-entry mr)))) + (print "Fee: " fee) + (print (make-brmlab-qrp-svg-string + fee "CZK" (brmember-id mr)))) + (print "
") + (print "
") (print "

Payments History

") (print "") (print "") diff --git a/src/qr-payment.scm b/src/qr-payment.scm index be79b50..0c28ac6 100644 --- a/src/qr-payment.scm +++ b/src/qr-payment.scm @@ -36,7 +36,8 @@ (import scheme (chicken format) (chicken string) - (chicken base)) + (chicken base) + util-io) (define (make-empty-qrp . vs) (let ((v (if (null? vs) "1.0" (car vs)))) @@ -54,7 +55,7 @@ (string->number amt) amt)) (s (number->string n)) - (f (string-split str ".")) + (f (string-split s ".")) (i? (null? (cdr f)))) (format "~A.~A" (car f) @@ -65,7 +66,7 @@ 0 2))))) (define (make-qrp iban amt cc vs msg) - (let loop ((keys '(ACC AM CC MSG X-CS)) + (let loop ((keys '(ACC AM CC MSG X-VS)) (vals (list iban (ensure-amount-format amt) cc msg vs)) (qrp (make-empty-qrp))) (if (null? keys) @@ -83,8 +84,18 @@ (make-qrp iban amt cc vs "Brmlab"))) (define (qrp-create-svg-string qrps) - ;; qrencode -t svg -o - -l M - "TODO") + (let-values + (((ec ol) + (get-process-exit+output-lines + "qrencode" + "-t" "svg" + "--inline" + "-o" "-" + "-l" "M" + qrps))) + (if (eq? ec 0) + (string-intersperse ol "\n") + #f))) (define (make-brmlab-qrp-svg-string amt cc vs) (qrp-create-svg-string From 17ce5cc1264115753332cebd3ab29d9c2ef3c995 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pant=C5=AF=C4=8Dek?= Date: Fri, 3 Jan 2025 17:08:16 +0100 Subject: [PATCH 21/26] Finish QR code integration. --- src/export-web-static.scm | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/export-web-static.scm b/src/export-web-static.scm index 6ac3a3d..6647104 100644 --- a/src/export-web-static.scm +++ b/src/export-web-static.scm @@ -90,6 +90,8 @@ (print "dd+dt,dd+dt+dd{border-top:1px solid #8cacbb}") (print "dd{grid-column:2/3;font-weight:bold;margin:0px;padding-left:16px}") (print "footer{background:#dee7ec;border-top:1px solid #8cacbb;padding:16px}") + (print ".qr svg{width:100%;height:auto;max-width:10cm}") + (print ".qr{text-align: center}") (print "") (print "") (print "") @@ -111,10 +113,10 @@ (print "
Account for Payments
(Účet pro platbu příspěvků)
CZK: 2500079551/2010
EUR: CZ93 2010 0000 0021 0007 9552
") (print "") (print "") - (print "
") + (print "
") (let ((fee (member-calendar-entry->fee (make-member-calendar-entry mr)))) - (print "Fee: " fee) + (print "

Payment of membership fee " fee " CZK
(Platba členského příspěvku)

") (print (make-brmlab-qrp-svg-string fee "CZK" (brmember-id mr)))) (print "
") From 1d523a0495827af2e641594fe54ffe8de5e14ee7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pant=C5=AF=C4=8Dek?= Date: Sat, 4 Jan 2025 17:45:16 +0100 Subject: [PATCH 22/26] Prepare release 1.18. --- CHANGELOG.md | 5 +++-- src/texts.scm | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a45faf..a5bfc54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,13 @@ ChangeLog ========= -1.18 ----- +1.18 - released 2025-01-06 +-------------------------- * fix typo in members-print * create LaTeX source of general meeting attendance sheet * add expected income, cash flow and average age to stats +* add QR code payment in CZK on members' payments pages' 1.17 - released 2024-10-01 -------------------------- diff --git a/src/texts.scm b/src/texts.scm index 5e384b0..2125a12 100644 --- a/src/texts.scm +++ b/src/texts.scm @@ -5,7 +5,7 @@ ;; ;; ISC License ;; -;; Copyright 2023 Brmlab, z.s. +;; Copyright 2023-2025 Brmlab, z.s. ;; Dominik Pantůček ;; ;; Permission to use, copy, modify, and/or distribute this software @@ -39,7 +39,7 @@ (chicken format)) ;; Short banner - (define banner-line "HackerBase 1.18-dev (c) 2023-2025 Brmlab, z.s.") + (define banner-line "HackerBase 1.18 (c) 2023-2025 Brmlab, z.s.") ;; Banner source with numbers for ANSI CSI SGR (define banner-source " From b324516514e9e3510f9ed35ed5d2bda6794cb08a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pant=C5=AF=C4=8Dek?= Date: Tue, 7 Jan 2025 11:42:21 +0100 Subject: [PATCH 23/26] Fix amount formatting for QR code for integer amounts. --- src/qr-payment.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qr-payment.scm b/src/qr-payment.scm index 0c28ac6..1550cdb 100644 --- a/src/qr-payment.scm +++ b/src/qr-payment.scm @@ -60,7 +60,7 @@ (format "~A.~A" (car f) (if i? - ".00" + "00" (substring (string-append (cadr f) "0") 0 2))))) From ac83dd9c72d32acc3b675a06dfaecaaa99f6075d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pant=C5=AF=C4=8Dek?= Date: Thu, 30 Jan 2025 21:39:51 +0100 Subject: [PATCH 24/26] Remove nonexistent option from manpage. --- doc/hackerbase.1 | 4 ---- 1 file changed, 4 deletions(-) diff --git a/doc/hackerbase.1 b/doc/hackerbase.1 index 27a71c2..531e4cb 100644 --- a/doc/hackerbase.1 +++ b/doc/hackerbase.1 @@ -273,10 +273,6 @@ Specify member by nickname. .B \-destroyed Show destroyed members in \fB-fees\fR action as well. -.TP -.B \-ml-all -Load all mailman list memberships to show them in members info. - .SH "FILES" All the information about members is stored in in members file in the From 9f5877d3f0199f8d8f8d22f7878ba0a8a535ca97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pant=C5=AF=C4=8Dek?= Date: Thu, 30 Jan 2025 21:42:28 +0100 Subject: [PATCH 25/26] Remove mailman2 support. --- src/Makefile | 16 ++------ src/mailman.scm | 18 +++----- src/mailman2.scm | 104 ----------------------------------------------- 3 files changed, 9 insertions(+), 129 deletions(-) delete mode 100644 src/mailman2.scm diff --git a/src/Makefile b/src/Makefile index 6e6d80e..8a9a50b 100644 --- a/src/Makefile +++ b/src/Makefile @@ -60,7 +60,7 @@ HACKERBASE-OBJS=hackerbase.o testing.o listing.o cal-month.o \ table-style.o sgr-state.o util-utf8.o sgr-cell.o \ template-list-expander.o box-drawing.o export-web-static.o \ util-dir.o dokuwiki.o racket-kwargs.o duck.o util-bst.o \ - util-bst-bdict.o util-bst-ldict.o util-bst-lset.o mailman2.o \ + util-bst-bdict.o util-bst-ldict.o util-bst-lset.o \ mailman-common.o mailman3.o mailman3-sql.o tiocgwinsz.o \ mailinglist.o export-sheet.o mbase-query.o qr-payment.o @@ -260,13 +260,6 @@ ENVIRONMENT-SOURCES=environment.scm ansi.import.scm environment.o: environment.import.scm environment.import.scm: $(ENVIRONMENT-SOURCES) -MAILMAN2-SOURCES=mailman2.scm util-bst-lset.import.scm \ - util-io.import.scm mailman-common.import.scm \ - configuration.import.scm - -mailman2.o: mailman2.import.scm -mailman2.import.scm: $(MAILMAN2-SOURCES) - UTIL-TIME-SOURCES=util-time.scm duck.import.scm util-time.o: util-time.import.scm @@ -527,10 +520,9 @@ UTIL-BST-LSET-SOURCES=util-bst-lset.scm util-bst.import.scm \ util-bst-lset.o: util-bst-lset.import.scm util-bst-lset.import.scm: $(UTIL-BST-LSET-SOURCES) -MAILMAN-SOURCES=mailman.scm mailman2.import.scm \ - mailman-common.import.scm util-bst-lset.import.scm \ - configuration.import.scm mailman3.import.scm \ - progress.import.scm +MAILMAN-SOURCES=mailman.scm mailman-common.import.scm \ + util-bst-lset.import.scm configuration.import.scm \ + mailman3.import.scm progress.import.scm mailman.o: mailman.import.scm mailman.import.scm: $(MAILMAN-SOURCES) diff --git a/src/mailman.scm b/src/mailman.scm index 29bd842..a8c9788 100644 --- a/src/mailman.scm +++ b/src/mailman.scm @@ -49,7 +49,6 @@ (import scheme (chicken base) (chicken module) - mailman2 mailman-common util-bst-lset configuration @@ -59,24 +58,17 @@ ;; Syntax for simplifying export of case-version procedures (define-syntax define-mailman-proc (syntax-rules () - ((_ name proc2) + ((_ name proc3) (begin (export name) (define (name . args) (case (*mailman-version*) - ((2) (apply proc2 args)))))) - ((_ name proc2 proc3) - (begin - (export name) - (define (name . args) - (case (*mailman-version*) - ((2) (apply proc2 args)) ((3) (apply proc3 args)))))))) (define-mailman-proc list-mailman-lists - list-mailman2-lists list-mailman3-lists) + list-mailman3-lists) (define-mailman-proc list-mailman-list-members - list-mailman2-list-members list-mailman3-list-members) + list-mailman3-list-members) ;; Loads a single mailman list as mailman structure, if ;; unsuccessfull, returns only a list with ML name and no member @@ -112,9 +104,9 @@ (assoc name lsts)) (define-mailman-proc add-email-to-mailman-list - add-email-to-mailman2-list add-email-to-mailman3-list) + add-email-to-mailman3-list) (define-mailman-proc remove-email-from-mailman-list - remove-email-from-mailman2-list remove-email-from-mailman3-list) + remove-email-from-mailman3-list) ;; Ensures given email is in given ML (define (mailman-ensure-member ml email) diff --git a/src/mailman2.scm b/src/mailman2.scm deleted file mode 100644 index 5825165..0000000 --- a/src/mailman2.scm +++ /dev/null @@ -1,104 +0,0 @@ -;; -;; mailman2.scm -;; -;; Mailman management interface - Mailman version 2.x support -;; -;; ISC License -;; -;; Copyright 2023 Brmlab, z.s. -;; Dominik Pantůček -;; -;; Permission to use, copy, modify, and/or distribute this software -;; for any purpose with or without fee is hereby granted, provided -;; that the above copyright notice and this permission notice appear -;; in all copies. -;; -;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL -;; WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED -;; WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE -;; AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR -;; CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS -;; OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, -;; NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN -;; CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -;; - -(declare (unit mailman2)) - -(module - mailman2 - ( - list-mailman2-lists - list-mailman2-list-members - - add-email-to-mailman2-list - remove-email-from-mailman2-list - ) - - (import scheme - (chicken base) - (chicken pathname) - (chicken string) - (chicken sort) - (chicken format) - srfi-1 - util-bst-lset - util-io - mailman-common - configuration) - - ;; Returns full path to given mailman binary - (define (mailman-bin bin) - (make-pathname (*mailman2-bin*) bin)) - - ;; Mailman-specific process output lines capture - (define (get-mailman-output-lines bin . args) - (apply - get-process-output-lines - (mailman-bin bin) - args)) - - ;; Sends all lines to the process - (define (mailman-send/recv bin args . lines) - (apply - process-send/recv - (mailman-bin bin) - args - lines)) - - ;; Returns the list of available lists - (define (list-mailman2-lists) - (get-mailman-output-lines "list_lists" "-b")) - - ;; Returns the list of members of given list - (define (list-mailman2-list-members lst) - (sort - (get-mailman-output-lines "list_members" lst) - string-ci Date: Thu, 30 Jan 2025 21:43:04 +0100 Subject: [PATCH 26/26] Bump version to 1.19-dev. --- src/texts.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/texts.scm b/src/texts.scm index 2125a12..a3383c6 100644 --- a/src/texts.scm +++ b/src/texts.scm @@ -39,7 +39,7 @@ (chicken format)) ;; Short banner - (define banner-line "HackerBase 1.18 (c) 2023-2025 Brmlab, z.s.") + (define banner-line "HackerBase 1.19-dev (c) 2023-2025 Brmlab, z.s.") ;; Banner source with numbers for ANSI CSI SGR (define banner-source "
DateTypeCommentAmountCurrencyAmount [CZK]Balance