creation - updated after v4 deployment
[infrastructure.git] / tunings-myplc / plc-map.py
diff --git a/tunings-myplc/plc-map.py b/tunings-myplc/plc-map.py
new file mode 100755 (executable)
index 0000000..0ea737a
--- /dev/null
@@ -0,0 +1,52 @@
+#!/usr/bin/env plcsh
+import Image, ImageDraw
+
+def circle (image, percentX, percentY, radiusX, radiusY, colorIn, colorOut):
+
+    imageX, imageY = image.size
+    centerX = int(imageX*percentX)
+    centerY = int(imageY*percentY)
+    x = max (0, min (centerX,imageX))
+    y = max (0, min (centerY,imageY))
+
+    x1 = x - radiusX
+    x2 = x + radiusX
+    y1 = y - radiusY
+    y2 = y + radiusY
+
+    draw = ImageDraw.Draw (image)
+    draw.chord((x1,y1,x2,y2), 0, 360, fill=colorIn, outline=colorOut )
+    del draw
+
+def main ():
+
+    path = '/var/www/html/'
+    original = path + 'map.png'
+    live = path + 'livemap.png'
+
+    # 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
+    # circle in and out colors
+    cIn,cOut='#566b8a','#bbbbbb'
+    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'])
+            circle(image,px,py,sx,sy,cIn,cOut)
+
+    image.save (live)
+
+if __name__ == '__main__':
+    main ()