incorporated --size-limit feature
[infrastructure.git] / scripts / plc-map.py
1 #!/usr/bin/env plcsh
2  
3 import Image, ImageDraw
4
5 def circle (image, percentX, percentY, radiusX, radiusY, colorIn, colorOut):
6
7     imageX, imageY = image.size
8     centerX = int(imageX*percentX)
9     centerY = int(imageY*percentY)
10     x = max (0, min (centerX,imageX))
11     y = max (0, min (centerY,imageY))
12
13     x1 = x - radiusX
14     x2 = x + radiusX
15     y1 = y - radiusY
16     y2 = y + radiusY
17
18     draw = ImageDraw.Draw (image)
19     draw.chord((x1,y1,x2,y2), 0, 360, fill=colorIn, outline=colorOut )
20     del draw
21
22 latitude={'top':65.,
23           'bottom': 35.5}
24 longitude={'left':-11.,
25            'right':58.}
26     
27 def render_site (site, image, sx, sy, cIn, cOut):
28     if site['longitude'] is not None and site['latitude'] is not None:
29         px=float(longitude['left']-site['longitude'])/float(longitude['left']-longitude['right'])
30         py=float(latitude['top']-site['latitude'])/float(latitude['top']-latitude['bottom'])
31         if (px<0 or py<0 or px>1 or py>1):
32             return
33         
34         circle(image,px,py,sx,sy,cIn,cOut)
35     
36
37 def main ():
38
39     path = '/var/www/html/'
40     original = path + 'map.png'
41     live = path + 'livemap.png'
42
43     # map characteristics, in degrees.
44     # latitude : positive is north
45     # longitude : positive is east 
46
47     # circle radius in pixels
48     sxLocal,syLocal=7,7
49     # circle in and out colors
50     cInLocal , cOutLocal = '#566b8a','#bbbbbb'
51
52     # same for federating / foreign sites
53     sxForeign,syForeign=6,6
54     cInForeign , cOutForeign = '#acb3a4', '#444444'
55  
56     image = Image.open(original)
57
58     for site in GetSites({'~peer_id':None}):
59         render_site (site, image, sxForeign, syForeign, cInForeign , cOutForeign)
60     # local sites go last to be more visible
61     for site in GetSites({'peer_id':None}):
62         render_site (site, image, sxLocal, syLocal, cInLocal , cOutLocal)
63             
64     image.save (live)
65
66 if __name__ == '__main__':
67     main ()