contrib/benitlux: report shows beers available between sample days
authorAlexis Laferrière <alexis.laf@xymus.net>
Fri, 23 Oct 2015 15:45:59 +0000 (11:45 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Fri, 23 Oct 2015 18:17:13 +0000 (14:17 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

contrib/benitlux/src/report.nit

index 084e935..c7a5bcf 100644 (file)
@@ -113,12 +113,16 @@ 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]]
+var days_sample = [for i in [1..column_width[ do all_days[i*all_days.length/column_width]]
+var weeks_sample = new Array[Array[String]]
 
 # Gather columns headers for each month
 var headers = new Array[nullable String]
+var iter = all_days.iterator
+iter.start
 var pre = ""
 for day in days_sample do
+       # Prepare headers
        var new_pre = day.substring(0, 7)
 
        if not day.has_prefix(pre) then
@@ -126,6 +130,16 @@ for day in days_sample do
        else headers.add null
 
        pre = new_pre
+
+       # Fill weeks
+       var week = new Array[String]
+       weeks_sample.add week
+       while iter.is_ok do
+               var item = iter.item
+               if item == day then break
+               week.add item
+               iter.next
+       end
 end
 
 # Draw the headers from top to bottom so they look like:
@@ -154,9 +168,17 @@ for beer in beers do
        # Skip never-available beers, usually name errors
        if days.is_empty then continue
 
-       # Print a line looking like: "  ############ ######    -----########-: Beer"
-       for s in days_sample do printn if days.has(s) then "#" else s.date_to_back
-       print ": {beer.name}"
+       # Print a line looking like: "  ############ ######    -----########- Beer"
+       var last = null
+       #var iter = days.iterator
+       for week in weeks_sample do
+               printn if days.has_all(week) then
+                          "#"
+                      else if days.has_any(week) then
+                          ":"
+                      else week.first.date_to_back
+       end
+       print " {beer.name}"
 end
 
 db.close