Changeset 3488

Show
Ignore:
Timestamp:
07/17/08 15:06:23 (4 months ago)
Author:
ksprotte
Message:

country-stats-handler now uses queries from contract-stats

Files:

Legend:

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

    r3486 r3488  
    592592  (sold-m2s 0) 
    593593  (paying-sponsors 0) 
    594   (country-sponsors (make-hash-table :test #'equal)) 
     594  (country-sponsors (make-hash-table)) 
    595595  (last-contracts (make-list +last-contracts-cache-size+))) 
    596596 
     
    604604         (sponsor (contract-sponsor contract)) 
    605605         (new-sponsor-p (alexandria:length= 1 (sponsor-contracts sponsor))) 
    606          (%country (sponsor-country sponsor)) 
    607          (country (and %country (string-upcase %country)))) 
     606         (country (sponsor-country sponsor))) 
    608607    (with-slots (sold-m2s paying-sponsors country-sponsors last-contracts) 
    609608        *contract-stats* 
     
    632631 
    633632(defun contract-stats-for-country (country) 
     633  (assert (keywordp country)) 
    634634  (let ((stat (gethash country (contract-stats-country-sponsors *contract-stats*)))) 
    635635    (if stat 
     
    644644             (contract-stats-last-contracts *contract-stats*))) 
    645645 
    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) 
     646(defun invoke-with-countries (function) 
     647  (alexandria:maphash-keys function (contract-stats-country-sponsors *contract-stats*))) 
     648 
     649(defmacro do-sponsor-countries ((country) &body body) 
    654650  (check-type country symbol) 
    655   `(invoke-with-countries (lambda (,country) ,@body) ,as-keyword)) 
     651  `(invoke-with-countries (lambda (,country) ,@body))) 
    656652 
    657653(register-store-transient-init-function 'initialize-contract-stats) 
  • trunk/projects/bos/m2/packages.lisp

    r3486 r3488  
    171171           #:contract-stats-for-country 
    172172           #:last-paid-contracts 
    173            #:do-countries 
     173           #:do-sponsor-countries 
    174174                            
    175175           #:make-m2-javascript 
  • trunk/projects/bos/web/kml-handlers.lisp

    r3467 r3488  
    155155              (with-element "Icon" 
    156156                ;; (with-element "href" (text "http://maps.google.com/mapfiles/kml/pal3/icon23.png")) 
    157                 (with-element "href" (text (format nil "http://~a/static/Orang_weiss.png" (website-host)))))))           
    158           (dolist (country-contracts (sort (group-on (remove-if-not #'contract-paidp contracts) 
    159                                                      :test #'equal 
    160                                                      :key (lambda (contract) 
    161                                                             (string-upcase (sponsor-country (contract-sponsor contract))))) 
    162                                            #'> :key (lambda (entry) (length (cdr entry))))) 
    163             (let ((coords (cdr (assoc (make-keyword-from-string (car country-contracts)) *country-coords*)))) 
     157                (with-element "href" (text (format nil "http://~a/static/Orang_weiss.png" (website-host)))))))                     
     158          (do-sponsor-countries (country) 
     159            (let ((coords (cdr (assoc country *country-coords*)))) 
    164160              (when coords 
    165161                (destructuring-bind (lon lat) 
    166162                    coords 
    167                   (let* ((contracts (cdr country-contracts)
    168                          (number-contracts (length contracts))
     163                  (multiple-value-bind (number-of-paying-sponsors number-of-sold-m2s
     164                      (contract-stats-for-country country
    169165                    (with-element "Placemark" 
    170166                      ;; (with-element "name" (text (format nil "~a ~a" (car country-contracts) (length (cdr country-contracts))))) 
     
    175171                                      (dictionary-entry "BOS says thank you to all sponsors!" lang) 
    176172                                      (dictionary-entry 
    177                                        (second (assoc (make-keyword-from-string (car country-contracts)) *country-english-names*)) lang) 
    178                                       number-contract
    179                                       (if (= 1 number-contracts) 
     173                                       (second (assoc country *country-english-names*)) lang) 
     174                                      number-of-paying-sponsor
     175                                      (if (= 1 number-of-paying-sponsors) 
    180176                                          (dictionary-entry "sponsor" lang) 
    181177                                          (dictionary-entry "sponsors" lang)) 
    182178                                      (dictionary-entry "total contribution" lang) 
    183                                       (reduce #'+ contracts :key #'contract-area)))) 
     179                                      number-of-sold-m2s))) 
    184180                      (with-element "Point" 
    185181                        (with-element "coordinates"