contrib/benitlux: add year-month as column headers in graph
authorAlexis Laferrière <alexis.laf@xymus.net>
Wed, 12 Aug 2015 15:01:48 +0000 (11:01 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Thu, 13 Aug 2015 12:52:27 +0000 (08:52 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

contrib/benitlux/src/report.nit

index 68d26d8..084e935 100644 (file)
@@ -109,12 +109,45 @@ sorter = new BeerComparator(appearances, availability)
 sorter.sort beers
 
 # Display the batch graph
-print "\nBatches:"
+print "\nAvailability graph:"
 
 # Compute `column_width` days from all the known days
 var column_width = 70
 var days_sample = [for i in column_width.times do all_days[i*all_days.length/column_width]]
 
+# Gather columns headers for each month
+var headers = new Array[nullable String]
+var pre = ""
+for day in days_sample do
+       var new_pre = day.substring(0, 7)
+
+       if not day.has_prefix(pre) then
+               headers.add new_pre
+       else headers.add null
+
+       pre = new_pre
+end
+
+# Draw the headers from top to bottom so they look like:
+#
+# ~~~
+# 2
+# 0
+# 1
+# 5
+# -
+# 0
+# 1
+# ~~~
+for l in 7.times do
+       for header in headers do
+               if header != null then
+                       printn header[l]
+               else printn " "
+       end
+       print ""
+end
+
 for beer in beers do
        var days = beer2days[beer]