Handle sparse results

This commit is contained in:
Roberto Alsina 2023-06-04 19:34:45 -03:00
parent 6a357fe776
commit 52007a4b5b
1 changed files with 9 additions and 6 deletions

View File

@ -97,14 +97,17 @@ class Handler
x = Array(Int32).new
y = Array(Int32).new
results = query(sql)
if results.nil? # No results, all 0s
if results.nil? # No results, all 0s
x = (1922..2015).to_a
y = x.map {|_| 0}
else # We got results
displayed = true
y = x.map { |_| 0 }
else # We got results
values = Hash(Int32, Int32).new(default_value: 0)
results.map { |r|
x << r[0].as_i
y << r[1].as_i
values[r[0].as_i] = r[1].as_i
}
(1922..2015).map { |year|
x << year
y << values[year] # Defaults to 0, so we have the whole set
}
end
plot(x, y, title: nombre.titleize, style: :lines, linewidth: 3)