;;; -*- mode: Lisp -*- ;;; ;;; $Header: /home/gene/library/website/docsrc/lh/RCS/mpg.lisp,v 395.1 2008/04/20 17:25:45 gene Exp $ ;;; (load "html.lisp") (use-package 'html) (defun one-row (date miles gallons price) "Return a row in an HTML table. Its columns are the date, miles, gallons, miles per gallon, price, & price per mile." (tr (td '((align . right)) date) (td '((align . right)) miles) (td '((align . right)) gallons) (td '((align . right)) (format nil "~,2F" (/ miles gallons))) (td '((align . right)) (format nil "~,2F" price)) (td '((align . right)) (format nil "~,2F" (/ price miles))))) (defun report (lst) "Generate a miles per gallon report. LST holds the data. Each element of LST is a list of four elements: date, gallons, price (for the entire purchase), & miles. LST must be sorted from earliest date to last. Returns a string that is the report." (html (head (title "Miles per Gallon")) (body (h1 '((align . center)) "Miles per Gallon") (apply #'table '((border . 1)) (cons (tr (th "date") (th '((align . right)) "miles") (th '((align . right)) "gallons") (th '((align . right)) "mpg") (th '((align . right)) "price") (th '((align . right)) "price per gallon")) (maplist #'(lambda (lst) (if (rest lst) (one-row (first (second lst)) (- (fourth (second lst)) (fourth (first lst))) (second (second lst)) (third (second lst))) "")) lst))) (p '((align . center)) "End.")))) (defun rf (pn lst) "Run REPORT on the data & write the results to the file named by PN. Returns the number of characters in the report." (length (with-open-file (strm pn :direction :output) (princ (report lst) strm)))) (defvar *gene* ;; date, gallons, price, odometer '(("19990521" 2.551 3.62 93) ("19990531" 5.234 7.27 233) ("19990606" 4.103 4.70 377) ("19990622" 6.990 9.99 661) ("19990715" 7.524 11.05 931) ("19990808" 6.955 10.43 1196) ("19990815" 4.854 7.28 1417) ("19990829" 7.090 10.63 1664) ("19990916" 7.844 11.76 1946) ("19991012" 7.796 11.45 2225) ("19991101" 8.561 12.40 2526) ("19991116" 8.407 15.96 2818) ("19991129" 7.337 10.26 3080) ("19991213" 8.127 11.53 3388) ("19991227" 7.161 10.30 3635) ("20000120" 8.500 12.57 3924) ("20000212" 8.778 13.07 4232) ("20000227" 6.137 9.20 4481) ("20000227" 7.102 11.00 4768) ("20000228" 7.497 12.44 5090) ("20000301" 8.296 15.09 5446) ("20000302" 5.811 10.22 5745) ("20000304" 8.145 13.02 6376) ("20000325" 8.862 15.45 6682) ("20000413" 8.675 14.74 7007) ("20000423" 6.923 11.76 7288) ("20000501" 8.234 14.32 7627) ("20000510" 7.994 13.58 7928) ("20000523" 8.214 13.96 8282) ("20000601" 7.654 12.77 8592) ("20000612" 7.236 12.08 8874) ("20000622" 8.536 14.25 9232) ("20000629" 8.291 13.67 9613) ("20000711" 8.018 13.86 9938) ("20000723" 8.486 14.67 10298) ("20000804" 8.369 14.47 10651) ("20000813" 5.677 9.82 10904) ("20000819" 7.19 12.36 11210) ("20000828" 8.386 15.00 11594) ("20000908" 8.031 14.69 11929) ("20000920" 7.920 14.25 12269) ("20001002" 7.530 13.55 12580) ("20001010" 7.609 13.69 12905) ("20001020" 8.428 15.16 13242) ("20001026" 4.847 8.09 13435) ("20001027" 6.695 12.25 13724) ("20001103" 7.730 13.67 14105) ("20001113" 8.755 15.14 14425) ("20001127" 8.4 18.98 14764.5) ("20001205" 8.224 14.22 15092) ("20001215" 8.217 14.21 15433) ("20010101" 8.400 13.43 15738.5) ("20010203" 8.537 13.91 16084) ("20010210" 3.874 5.65 16242) ("20010220" 8.301 13.52 16598) ("20010307" 8.414 13.71 16935) ("20010329" 8.692 14.16 17267.5) ("20010419" 8.783 14.31 17625) ("20010511" 8.254 13.45 17942) ("20010524" 8.751 14.26 18298) ("20010607" 8.192 13.75 18622.5) ("20010702" 8.948 15.20 18907) ("20010909" 8.248 14.43 19407) ("20011010" 8.742 15.73 19650) ("20011218" 8.178 10.46 20436) ("20020411" 9.065 13.23 21490) ("20020530" 8.365 12.37 21982) ("20020626" 8.867 13.65 22264.75) ("20020717" 8.985 13.47 22545.5) ("20020801" 9.041 14.00 22861) ("20020822" 9.213 13.99 23168) ("20020911" 9.013 13.69 23476) ("20021028" 9.116 13.12 24298) ("20021112" 8.828 13.23 24597) ("20021205" 8.845 13.26 24859) ("20021213" 5.246 7.71 25027) ("20030101" 8.624 11.89 25271) ("20030121" 9.231 12.54 25532) ("20030207" 7.602 12.08 25795) ("20030301" 8.837 16.43 26059) ("20030319" 8.857 16.82 26335) ("20030330" 4.097 7.74 26471) ("20030421" 8.920 15.60 26732) ("20030508" 9.329 15.29 27029) ("20030602" 8.313 12.71 27301) ("20030622" 8.994 13.75 27568) ("20030715" 9.237 14.68 27849.5) ("20030806" 9.128 14.60 28153))) ;;; --- end of file ---