creation - updated after v4 deployment
[infrastructure.git] / tunings-myplc / 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 def main ():
23
24     path = '/var/www/html/'
25     original = path + 'map.png'
26     live = path + 'livemap.png'
27
28     # map characteristics, in degrees.
29     # latitude : positive is north
30     # longitude : positive is east 
31     latitude={'top':65.,
32               'bottom': 35.5}
33     longitude={'left':-11.,
34                'right':58.}
35     
36     # circle radius in pixels
37     sx,sy=6,6
38     # circle in and out colors
39     cIn,cOut='#566b8a','#bbbbbb'
40  
41     image = Image.open(original)
42
43     for site in GetSites():
44         if site['longitude'] is not None and site['latitude'] is not None:
45             px=float(longitude['left']-site['longitude'])/float(longitude['left']-longitude['right'])
46             py=float(latitude['top']-site['latitude'])/float(latitude['top']-latitude['bottom'])
47             circle(image,px,py,sx,sy,cIn,cOut)
48
49     image.save (live)
50
51 if __name__ == '__main__':
52     main ()