special-cell-usage.scm
(module special-cell-usage mzscheme
        (require "hwikireq.scm")
        (require "users.scm")
        (require "page.scm")
        (require "template.scm")
        (require "config.scm")
        (require "hwiki-manager.scm")
        (provide special:cell-usage)

        (def-class
         (this (special:cell-usage context))
         (supers (page-base))
         (private
          (define _template (template 'context context 'name "admin"))
          (define _users    (users context))
          )
         (public
          (define (get-template)  _template)
          (define (css)           (-> _template css))
          (define (title)         (_ "HWiki Cell Usage (memory)"))

          (define (create-html)
            (lambda (url)
              (let ((manager (hwiki-current-manager)))
                (make-response/xhtml
                 `(html
                   ,(-> supers create-header context)
                   (body
                    (div ((class "cellusage"))
                         (h1 ,(_ "HWiki Cell Usage"))
                         (p (a ((href ,(let ((paths (cfile context)))
                                         (-> paths htmllink 'page (-> context from-where)))))
                               ,(_ "Return to previous page")))
                         ,(let ((cells (sort (hwiki-cell-usage manager) (lambda (a b) (> (cadr a) (cadr b))))))
                            `(p (format "Number of cells: ~a" (length cells)))
                            (append
                             `(table ((class "cellusage")) )
                             `((tr (th ((class "id"))            ,(_ "cell id"))
                                   (th ((class "begintime"))     ,(_ "begin time"))
                                   (th ((class "timeout"))       ,(_ "timeout"))
                                   (th ((class "tdiff"))         ,(_ "duration"))
                                   (th ((class "continuations")) ,(_ "#continuations"))))
                             (map
                              (lambda (cell)
                                (apply (lambda (id begin-time timeout continuations)
                                         `(tr (td ((class "id")) ,(number->string id))
                                              (td ((class "begintime")) ,(date->string (time-utc->date (make-time time-utc 0 begin-time)) "~5"))
                                              (td ((class "timeout"))   ,(number->string timeout))
                                              (td ((class "tdiff"))     ,(number->string (- (current-seconds) begin-time)))
                                              (td ((class "continuations")) ,(number->string continuations))))
                                       cell))
                              cells))))))))))
          )
         (constructor
          (-> supers special!)
          )
         )


        (register-page "special:cellusage" special:cell-usage)

        )