Changeset 3486

Show
Ignore:
Timestamp:
07/17/08 14:50:50 (4 months ago)
Author:
ksprotte
Message:

new macro do-countries and some bugfixes to contract-stats

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/projects/bos/m2/m2.lisp

    r3484 r3486  
    604604         (sponsor (contract-sponsor contract)) 
    605605         (new-sponsor-p (alexandria:length= 1 (sponsor-contracts sponsor))) 
    606          (country (string-upcase (sponsor-country sponsor)))) 
     606         (%country (sponsor-country sponsor)) 
     607         (country (and %country (string-upcase %country)))) 
    607608    (with-slots (sold-m2s paying-sponsors country-sponsors last-contracts) 
    608        *contract-stats* 
     609        *contract-stats* 
    609610      ;; sold-m2s 
    610611      (incf sold-m2s area) 
    611612      ;; paying-sponsors 
    612613      (when new-sponsor-p 
    613        (incf paying-sponsors)) 
     614        (incf paying-sponsors)) 
    614615      ;; country-sponsors 
    615       (let ((country-stat (gethash country country-sponsors))) 
    616         (unless country-stat 
    617           (setq country-stat (setf (gethash country country-sponsors) (make-country-stat)))) 
    618         (when new-sponsor-p 
    619           (incf (country-stat-paying-sponsors country-stat))) 
    620         (incf (country-stat-sold-m2s country-stat) area)) 
     616      (when country 
     617        (let ((country-stat (gethash country country-sponsors))) 
     618          (unless country-stat 
     619            (setq country-stat (setf (gethash country country-sponsors) (make-country-stat)))) 
     620          (when new-sponsor-p 
     621            (incf (country-stat-paying-sponsors country-stat))) 
     622          (incf (country-stat-sold-m2s country-stat) area))) 
    621623      ;; last-contracts 
    622624      (setf last-contracts (nbutlast last-contracts)) 
     
    641643                   (object-destroyed-p contract))) 
    642644             (contract-stats-last-contracts *contract-stats*))) 
     645 
     646(defun invoke-with-countries (function as-keyword) 
     647  (alexandria:maphash-keys 
     648   (if as-keyword 
     649       (lambda (country) (funcall function (make-keyword-from-string country))) 
     650       function) 
     651   (contract-stats-country-sponsors *contract-stats*))) 
     652 
     653(defmacro do-countries ((country &key as-keyword) &body body) 
     654  (check-type country symbol) 
     655  `(invoke-with-countries (lambda (,country) ,@body) ,as-keyword)) 
    643656 
    644657(register-store-transient-init-function 'initialize-contract-stats) 
  • trunk/projects/bos/m2/packages.lisp

    r3485 r3486  
    171171           #:contract-stats-for-country 
    172172           #:last-paid-contracts 
     173           #:do-countries 
    173174                            
    174175           #:make-m2-javascript