Skip to content

Commit

Permalink
Merge pull request #1 from andresilveira/autoscaling
Browse files Browse the repository at this point in the history
Autoscaling
  • Loading branch information
andresilveirah committed Mar 9, 2012
2 parents 4ad5206 + 2256c52 commit 2c493cb
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 6 deletions.
25 changes: 24 additions & 1 deletion Rakefile
Expand Up @@ -7,7 +7,6 @@ namespace :db do
:database => "fireboard"
)
end

desc "Run all migrations at migrations path"
task :migrate => :configure_connection do
ActiveRecord::Migration.verbose = true
Expand All @@ -21,3 +20,27 @@ namespace :db do
end
end

namespace :reports do
task :configure_connection do
ActiveRecord::Base.establish_connection(
:adapter => "mysql2",
:database => "fireboard"
)
end
desc "Rollback all reports made today"
task :rollback => :configure_connection do
class Report < ActiveRecord::Base
end
system("rm -rf ./charts/#{Time.now.strftime("%Y%m%d")}")
deleted = 0
reports = Report.all
reports.each do |report|
if report.created_at.day == Time.now.day
report.delete
deleted += 1
end
end
p "#{deleted} entries was destroyed"
end
end

29 changes: 24 additions & 5 deletions firechart.rb
@@ -1,7 +1,25 @@
module FireChart

GRAPH_FACTOR = 5.5 # because of chart size limited (yet)
@@current_scale = 1

def auto_scale data
if data.max > 100
@@current_scale = (data.max / 100.0).round
end
return @@current_scale
end

def print_scale
%Q{
<rect x="830" y="625" width="150" height="25" fill="white" />
<text font-family="Verdana" font-size="15" fill="black" x="855" y="643">Escala: #{@@current_scale}x</text>
}
end

def generate_shape
%Q{
<rect x='0' y='0' width='980' height='600' fill='rgb(241,241,241)' style='stroke:rgb(241,241,241); stroke-width: 10'/>
<rect x='0' y='0' width='980' height='650' fill='rgb(241,241,241)' style='stroke:rgb(241,241,241); stroke-width: 10'/>
<rect x='50' y='50' width='930' height='550' fill='white' />
}
end
Expand Down Expand Up @@ -35,7 +53,7 @@ def generate_marks bugs
i = 0
dia = 50
while i < bugs.size
marks += "<circle cx='#{dia}' cy='#{600 - bugs[i] * 5.5}' r='4' fill='#2166AC' /> \n"
marks += "<circle cx='#{dia}' cy='#{600 - bugs[i] * (GRAPH_FACTOR/@@current_scale)}' r='4' fill='#2166AC' /> \n"
i += 1
dia += 30
end
Expand All @@ -50,7 +68,7 @@ def generate_data_line bugs
dia = 50

while i < bugs.size
data_line += "#{dia}, #{600 - bugs[i] * 5.5} \n"
data_line += "#{dia}, #{600 - bugs[i] * (GRAPH_FACTOR / @@current_scale)} \n"
i += 1
dia += 30
end
Expand All @@ -61,6 +79,8 @@ def generate_data_line bugs
end

def create_chart project_name, bug_occurrences, options = {}
auto_scale bug_occurrences

svg_string = %Q{<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'>
<?xml-stylesheet href='brushmetal.css' type='text/css'?>
Expand All @@ -74,6 +94,7 @@ def create_chart project_name, bug_occurrences, options = {}
<!-- / Marks -->
<!-- Data_Line -->
#{generate_data_line(bug_occurrences)}
#{print_scale}
<!-- / Data_Line -->
</svg>
}
Expand All @@ -89,5 +110,3 @@ def create_chart project_name, bug_occurrences, options = {}
end
end
end


0 comments on commit 2c493cb

Please sign in to comment.