support for federation : local and foreign sites shown with various attributes
authorbuild <build@41d37cc5-eb28-0410-a9bf-d37491348ade>
Mon, 12 Mar 2007 10:42:27 +0000 (10:42 +0000)
committerbuild <build@41d37cc5-eb28-0410-a9bf-d37491348ade>
Mon, 12 Mar 2007 10:42:27 +0000 (10:42 +0000)
scripts/plc-map.py

index 6ce7492..693c75b 100755 (executable)
@@ -19,6 +19,21 @@ def circle (image, percentX, percentY, radiusX, radiusY, colorIn, colorOut):
     draw.chord((x1,y1,x2,y2), 0, 360, fill=colorIn, outline=colorOut )
     del draw
 
+latitude={'top':65.,
+          'bottom': 35.5}
+longitude={'left':-11.,
+           'right':58.}
+    
+def render_site (site, image, sx, sy, cIn, cOut):
+    if site['longitude'] is not None and site['latitude'] is not None:
+        px=float(longitude['left']-site['longitude'])/float(longitude['left']-longitude['right'])
+        py=float(latitude['top']-site['latitude'])/float(latitude['top']-latitude['bottom'])
+        if (px<0 or py<0 or px>1 or py>1):
+            return
+        
+        circle(image,px,py,sx,sy,cIn,cOut)
+    
+
 def main ():
 
     path = '/var/www/html/'
@@ -28,27 +43,24 @@ def main ():
     # map characteristics, in degrees.
     # latitude : positive is north
     # longitude : positive is east 
-    latitude={'top':65.,
-              'bottom': 35.5}
-    longitude={'left':-11.,
-               'right':58.}
-    
+
     # circle radius in pixels
-    sx,sy=6,6
+    sxLocal,syLocal=7,7
     # circle in and out colors
-    cIn,cOut='#566b8a','#bbbbbb'
+    cInLocal , cOutLocal = '#566b8a','#bbbbbb'
+
+    # same for federating / foreign sites
+    sxForeign,syForeign=6,6
+    cInForeign , cOutForeign = '#acb3a4', '#444444'
  
     image = Image.open(original)
 
-    for site in GetSites():
-        if site['longitude'] is not None and site['latitude'] is not None:
-            px=float(longitude['left']-site['longitude'])/float(longitude['left']-longitude['right'])
-            py=float(latitude['top']-site['latitude'])/float(latitude['top']-latitude['bottom'])
-            if (px<0 or py<0 or px>1 or py>1):
-                continue
+    for site in GetSites({'~peer_id':None}):
+        render_site (site, image, sxForeign, syForeign, cInForeign , cOutForeign)
+    # local sites go last to be more visible
+    for site in GetSites({'peer_id':None}):
+        render_site (site, image, sxLocal, syLocal, cInLocal , cOutLocal)
             
-            circle(image,px,py,sx,sy,cIn,cOut)
-
     image.save (live)
 
 if __name__ == '__main__':