Permalink
Browse files

Chart refactoring

  • Loading branch information...
1 parent ba7b917 commit 591a41f36270c068aa51369f0ffb9046d6f840f6 @iain committed Jan 19, 2012
Showing with 28 additions and 49 deletions.
  1. +28 −8 app/models/airbrake/chart.rb
  2. +0 −41 lib/charts/overview.rb
@@ -1,11 +1,16 @@
class Airbrake::Chart
def self.[](project)
- query = project.airbrake_errors.by_date
- series = { false => "Unresolved", true => "Resolved" }.map do |v, name|
- data = query.resolved(v).map { |x| [ js_timestamp(x[:date]), x[:count] ] }
- { :name => name, :data => data, :pointInterval => 24 * 3600 * 1000 }
- end
+ new(project).options
+ end
+
+ attr_reader :project
+
+ def initialize(project)
+ @project = project
+ end
+
+ def options
{
:chart => {
:renderTo => 'chart',
@@ -30,7 +35,7 @@ def self.[](project)
:lineWitdh => 1,
:max => js_timestamp(1.day.from_now),
:minorTickInterval => 'auto',
- :plotBands => plotbands(project)
+ :plotBands => plotbands
},
:yAxis => {
:title => { :text => "Amount" },
@@ -42,7 +47,22 @@ def self.[](project)
}
end
- def self.plotbands(project)
+ def series
+ @series ||= { false => "Unresolved", true => "Resolved" }.map do |v, name|
+ data = query.resolved(v).map { |x| [ js_timestamp(x[:date]), x[:count] ] }
+ { :name => name, :data => data, :pointInterval => 24 * 3600 * 1000 }
+ end
+ end
+
+ def query
+ @query ||= project.airbrake_errors.by_date
+ end
+
+ def plotbands
+ deploys
+ end
+
+ def deploys
project.airbrake_deploys.map do |deploy|
{
:from => js_timestamp(deploy.deployed_at - 5.hours),
@@ -52,7 +72,7 @@ def self.plotbands(project)
end
end
- def self.js_timestamp(time)
+ def js_timestamp(time)
time.to_time.to_i * 1000
end
View
@@ -1,41 +0,0 @@
-module Charts
-
- class Overview
-
- def self.[](project)
- series = [ "Coverage", "Errors", "Builds" ].map { |t|
- data = (1..28).map { |day|
- if rand < 0.5
- [ day.days.ago.to_i * 1000, rand(80) + 20.0 ]
- end
- }.compact
- { :name => t, :data => data }
- }
- {
- :chart => {
- :renderTo => 'chart',
- :type => 'spline',
- :zoomType => 'x'
- },
- :credits => {
- :enabled => false
- },
- :plotOptions => { :series => { :animation => { :duration => 100, :easing => :linear } } },
- :title => {
- :text => "Overview"
- },
- :xAxis => {
- :type => 'datetime',
- :maxZoom => 24 * 3600000
- },
- :yAxis => {
- :title => { :text => "Coverage" },
- :max => 100
- },
- :series => series
- }
- end
-
- end
-
-end

0 comments on commit 591a41f

Please sign in to comment.