3002839fe33de2e530c91871c99da4fec0065873
[rrq/hourglass.git] / manager / history.lsp
1 (load "expand-string.lsp")
2
3 # Make a plot file with 0-24 vertically, days horizontally
4 # Relative now...
5
6 (setf
7  NOW (now)
8  TZ (NOW -2)
9  TZTODAY (- (date-value (0 3 NOW)) (* TZ 60))
10  DAYSEC (* 24 3600)
11  )
12
13 (define (plotpoint x)
14   (when x
15     (letn ((n (div (- x TZTODAY) DAYSEC))
16            (d (if (< n) (- (int n) 1) (int n)))
17            (s (mul 24 (if (< n) (sub n d) (sub n d)))))
18       (list d s))
19     ))
20
21 (define (usage x)
22   (and (regex "([0-9]+) ([0-9]+)" x 0)
23        (> (int $2 0 10) 1000)
24        (plotpoint (int $1 0 10))))
25
26 (define (usage-file dat)
27   (clean null?
28          (map usage
29               (parse (read-file (format "../activity/%s" dat)) "\n"))))
30
31 (setf
32  USAGE (sort (flat (map usage-file (directory "../activity" "^[^.]")) 1) <)
33  MAP '()
34  )
35
36 (dolist (u USAGE)
37   (unless (assoc (u 0) MAP) (push (list (u 0)) MAP))
38   (push (u 1) (assoc (u 0) MAP) -1))
39
40 (define (mkmap x)
41   (let ((s (dup "." (* 24 4))))
42     (dolist (e x) (setf (s (int (mul e 4))) "X"))
43     s))
44
45 (setf MAP (map (fn (x) (list (x 0) (mkmap (1 x)))) MAP))
46
47 (println (expand-file "tmpl/history-page.html"))
48 (exit 0)
49 (load
50