Browse Source

Better documentation + fix a color inversion in visu

Phyks (Lucas Verney) 2 years ago
parent
commit
d91c9f65f0
1 changed files with 27 additions and 6 deletions
  1. 27
    6
      visu.py

+ 27
- 6
visu.py View File

@@ -1,9 +1,23 @@
1 1
 #!/usr/bin/env python3
2 2
 # coding: utf-8
3 3
 """
4
-Visualisation of Velib data
5
-
6
-Note: This does not take into account the stations events.
4
+Visualisation of Velib data.
5
+
6
+The generated maps shows the number of available bikes for each stations,
7
+plotted on the map of Paris. We use a Voronoi diagram to draw tiles on top of
8
+Paris map (think of each tiles as the "area of influence" of a given Velib
9
+station). Green represents a large number of available bikes, red represents a
10
+low number of available bikes.
11
+
12
+This script requires a couple of arguments from the command-line:
13
+    * The path to the SQLite DB file to use.
14
+    * The path to the folder in which generated images should be put.
15
+    * [Optional] A timestamp to start from, to resume operation for instance.
16
+
17
+Note: This code does not take into account the stations events (change of
18
+station size, new stations, stations deletion). Hence, there might be small
19
+mistakes in the visualization, such as stations without data. This should be
20
+handled in an improved version.
7 21
 """
8 22
 from __future__ import division
9 23
 
@@ -28,23 +42,27 @@ def get_hue(percentage):
28 42
     Convert a percentage to a hue,
29 43
     to map a percentage to a color
30 44
     in the green - yellow - orange - red scale.
45
+
46
+    Red means 0%, green means 100%.
31 47
     """
32
-    value = percentage / 100.0
48
+    value = (100 - percentage) / 100.0
33 49
     hue = (1 - value) * 120
34 50
     return hue / 360.0
35 51
 
36 52
 
53
+# Handle arguments from command-line
37 54
 if len(sys.argv) < 3:
38 55
     sys.exit('Usage: %s db_file out_dir' % sys.argv[0])
39
-
40 56
 db_file = sys.argv[1]
41 57
 out_dir = sys.argv[2]
42 58
 
59
+# Handle optional first timestamp argument
43 60
 first_timestamp = None
44 61
 if len(sys.argv) > 3:
45 62
     first_timestamp = int(sys.argv[3])
46 63
 
47
-progressbar.streams.wrap_stderr()
64
+# Init progressbar and logging
65
+progressbar.streams.wrap_stderr()  # Required before logging.basicConfig
48 66
 logging.basicConfig(level=logging.INFO)
49 67
 
50 68
 # Ensure out folder exists
@@ -186,6 +204,9 @@ for t, in bar(time_data):
186 204
             region = vor_regions[station_data[0]]
187 205
             region["mpl_surface"].set_color(matplotlib.colors.hsv_to_rgb([get_hue(percentage), 1.0, 1.0]))
188 206
         except KeyError:
207
+            # This can happen for a station at the boundaries (we volontarily
208
+            # ignore them) or for station which disappeared at some point in
209
+            # the dataset (as we don't handle stations events by now).
189 210
             logging.debug('Unknown Voronoi region for station %d.', station_data[0])
190 211
 
191 212
     # Output frame if necessary