1 ;; Copyright (C) 2009 Kyle Spaans
2 ;; this program is distributed under the GPL v2 or (at your option)
5 ;; NNTP-TO-DOT - perform various analyses of a newsgroup, generate some
6 ;; DOT code for plotting with graphviz
8 ;; - Generate a graph depicting all interactions between users on the group
9 ;; - Count the number of posts made per day
15 (require "userrel.ss")
19 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
21 ;; Data structure to capture interactions on the newsgroup.
22 ;; Want to have FROM and TO fields. Ideally TO should be a list of
23 ;; people who the from has interacted with. Or perhaps use a hash table?
24 ;; Yes, want constant insert time for new users (read: node), and then
25 ;; value can be a list of other users that this user has interacted with.
26 ;; Should I differentiate between interactions in FROM and TO?
27 ;; ^^^^^^^^^ I don't think I can. Especailly since I can make it an
30 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
31 (define dotfile (open-output-file "data/cs136-trial.dot" #:exists 'truncate))
32 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
34 (define uwnews (connect-to-server "news.uwaterloo.ca"))
35 (define-values (total first last) (open-news-group uwnews "uw.cs.cs136"))
37 ;; read-all: int int newsgroup -> void
38 ;; recurse over all possible message "numbers" from the newsgroup
39 (define (read-all first last newsd)
41 [(= first last) (printf "^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n")]
42 [else (let [(message (message-getter uwnews first (list from-regexp subj-regexp mid-regexp ref-regexp)))]
44 [(boolean? message) (void)]
45 [else (for-each (lambda (header) (printf "~a~n" header))
48 (read-all (+ first 1) last newsd)]))
50 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
51 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
52 ;; nntp-map: operation newsgroup (listof header-regexp) -> void
53 ;; maps some operation across each newsgroup post
54 ;;;(define (nntp-map op newsd hregexps)
55 ;;; (let-values ([(total first-id last-id) (open-news-group newsd "uw.cs.cs136")])
57 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
58 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
60 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
61 ;;(read-all first (+ 100 first) uwnews)
62 ;;(userrel first (+ 800 first) uwnews dotfile)
65 ;; (hash-map users (lambda (x y) (printf "~a]]] ~a~n~n" x y)))
68 ;; (hash-map mids (lambda (x y) (printf "~a]]] ~a~n~n" x y)))
71 ;;(read-all first last uwnews)
72 ;;(read-all first (+ first 1000) uwnews)
74 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
75 ;; CODE TO EXECUTE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
76 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
77 (posts-per-day first last uwnews)
78 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
80 (close-output-port dotfile)
81 (disconnect-from-server uwnews)