1 ;; Copyright (C) 2009 Kyle Spaans
2 ;; this program is distributed under the GPL v2 or (at your option)
5 ;; Calculate a bunch of user statistics:
7 ;; - Post counts of users
8 ;; - Average number of posts
10 ;; - new users versus time...
19 ;; User Statistics Struct
20 ;; String - usename in the form of an email address, possibility of duplicates
21 ;; int - total number of posts in newsgroup
22 ;; date - SRFI-19 date struct, date of first post to group
23 ;; date - " " ", date of last post to struct
24 ;; int - number of days in range from first post day to past post day
25 ;; real - number of posts / number of days
26 (define-struct ustats (user nump firstp lastp days avgppd))
28 ;; Collect stats in the form of '(USERNAME ustats)
29 (define users (make-hash))
31 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
33 ;; print-stats: void -> void
34 ;; Pretty print the contents of the user statistics table to stdout
36 (printf "Total number of users: ~a~n~n" (hash-count users))
40 (printf "User: ~a~nCount: ~a~nFirst: ~a~nLast: ~a~nAvgPPD: ~a~n~n"
47 ;; count-users: int int newsgroup -> void
48 ;; build a hash table with each user from the group collecting stats:
51 ;; So if "last" post is empty, then user has only 1 post
52 (define (count-users first last newsd)
54 [(= first last) (print-stats)]
55 [else (letrec [(message (message-getter newsd first (list from-regexp date-regexp)))
56 (mesg-from (if (boolean? message) message (car message)))
57 (mesg-date (if (boolean? message) message (cadr message)))]
59 [(boolean? message) (void)]
61 (let [(result (hash-ref users mesg-from #f))]
64 ;(printf "First post ~a ::@:: ~a~n" mesg-from mesg-date)
65 (hash-set! users mesg-from (make-ustats mesg-from 1 (get-date mesg-date) '() 1 1))]
67 ;; Calculate the ordinal day of the year (1-365) of the given date
68 ;; then subtract. Alternatively date->time and time-difference
69 ;; functions can be used to calculate this
70 (let [(pdays (if (empty? (ustats-lastp result))
72 (+ 1 (- (date-year-day (ustats-lastp result))
73 (date-year-day (ustats-firstp result))))))
74 (new-nump (+ 1 (ustats-nump result)))]
75 (hash-set! users mesg-from (make-ustats
78 (ustats-firstp result)
81 (/ new-nump pdays))))]))]))
82 (count-users (+ first 1) last newsd)]))