-
Notifications
You must be signed in to change notification settings - Fork 0
/
uptime.lsp
66 lines (59 loc) · 2.07 KB
/
uptime.lsp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
;;
;; Copyright 1337 (c) by Kirill Miazine <km@krot.org>
;;
;;; sla
(define (get-path-sla)
(float (replace "," (slice (or (env "PATH_INFO") "/") 1) ".")))
(define (get-form-sla)
(float (replace "," (or (Web:post "sla") (Web:get "sla") "") ".")))
(define (get-sla)
(let
(sla (or (get-form-sla) (get-path-sla) 99.9))
(cond
((< sla 0.0) 0.0)
((> sla 100.0) 100.0)
(true sla))))
(define (format-sla sla)
(trim (trim (format "%f" sla) "0") "."))
;;; durations
(setq seconds-day (mul 3600 24))
(setq hours-day 24)
(setq days-week 7)
(setq days-year 365.2425) ; pick one at http://en.wikipedia.org/wiki/Year#Summary
(setq months-year 12)
(setq weeks-year (div days-year days-week))
(setq hours-year (mul hours-day days-year))
(setq days-month (div days-year months-year))
(setq seconds-year (mul seconds-day days-year))
(setq weeks-month (div days-month days-week))
(setq hours-month (mul hours-day days-month))
(setq seconds-month (mul seconds-day days-month))
(setq hours-week (mul hours-day days-week))
(setq seconds-week (mul seconds-day days-week))
;;; quick and ugly multilanguage format monster
;;; needs a rewrite...
(define (fmt-secs sec lang skip-days)
(let
(htag (if (= lang "no") "t" "h")) ; lang is not used anymore, but anyway
(cond
((< sec 60)
(format "%.1fs" (float sec)))
((< sec 3600)
(letn
(mins (/ sec 60)
secs (sub sec (* mins 60)))
(format "%dm %.1fs" mins (float secs))))
((or (< sec 86400) skip-days)
(letn
(hours (/ sec 3600)
mins (/ (sub sec (* hours 3600)) 60)
secs (sub sec (* hours 3600) (* mins 60)))
(format "%d%s %dm %.1fs" hours htag mins (float secs))))
(true
(letn
(days (/ sec 86400)
hours (/ (sub sec (* days 86400)) 3600)
mins (/ (sub sec (* days 86400) (* hours 3600)) 60)
secs (sub sec (* days 86400) (* hours 3600) (* mins 60)))
(format "%dd %d%s %dm %.1fs" days hours htag mins (float secs)))))))
; vim: set tw=76 ts=2 encoding=utf8 fileencoding=utf8 ft=lisp et: