Handle sparse results
This commit is contained in:
parent
6a357fe776
commit
52007a4b5b
@ -97,14 +97,17 @@ class Handler
|
|||||||
x = Array(Int32).new
|
x = Array(Int32).new
|
||||||
y = Array(Int32).new
|
y = Array(Int32).new
|
||||||
results = query(sql)
|
results = query(sql)
|
||||||
if results.nil? # No results, all 0s
|
if results.nil? # No results, all 0s
|
||||||
x = (1922..2015).to_a
|
x = (1922..2015).to_a
|
||||||
y = x.map {|_| 0}
|
y = x.map { |_| 0 }
|
||||||
else # We got results
|
else # We got results
|
||||||
displayed = true
|
values = Hash(Int32, Int32).new(default_value: 0)
|
||||||
results.map { |r|
|
results.map { |r|
|
||||||
x << r[0].as_i
|
values[r[0].as_i] = r[1].as_i
|
||||||
y << r[1].as_i
|
}
|
||||||
|
(1922..2015).map { |year|
|
||||||
|
x << year
|
||||||
|
y << values[year] # Defaults to 0, so we have the whole set
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
plot(x, y, title: nombre.titleize, style: :lines, linewidth: 3)
|
plot(x, y, title: nombre.titleize, style: :lines, linewidth: 3)
|
||||||
|
Loading…
Reference in New Issue
Block a user