Permalink
Browse files

Merge pull request #11 from marutosi/export-csv

add exporting csv feature
  • Loading branch information...
2 parents 1bd153b + 144486a commit 576b18da817b8b683a0eb82fe86bc72f889168d4 @gamafranco gamafranco committed Jan 4, 2013
View
@@ -1,32 +1,3 @@
-/.project
-/.loadpath
-/config/additional_environment.rb
-/config/email.yml
-/config/initializers/session_store.rb
-/coverage
-/db/*.db
-/db/*.sqlite3
-/db/schema.rb
-/files/*
-/lib/redmine/scm/adapters/mercurial/redminehelper.pyc
-/lib/redmine/scm/adapters/mercurial/redminehelper.pyo
-/log/*.log*
-/log/mongrel_debug
-/public/dispatch.*
-/public/plugin_assets
-/tmp/*
-/tmp/cache/*
-/tmp/sessions/*
-/tmp/sockets/*
-/tmp/test/*
-/vendor/cache
-/vendor/rails
-*.rbc
-*.*~
-*~
-
-/.bundle
-/Gemfile.local
/.idea
.svn
.hg
View
@@ -0,0 +1,3 @@
+syntax: glob
+
+.git
@@ -2,9 +2,29 @@ class RatiosController < ApplicationController
unloadable
include IndicatorsLogic
+ helper :ratios
+ include RatiosHelper
+
def index
- @project = Project.find(params[:id])
- @proj_or_vers_data = IndicatorsLogic::retrive_data(@project)
- @proj_or_vers_indicators = IndicatorsLogic::calc_indicators(@project, @proj_or_vers_data[0], @proj_or_vers_data[1])
+ project = Project.find(params[:id])
+ data = IndicatorsLogic::retrive_data(project)
+ @evms = []
+ @evms << {
+ :name => project.name,
+ :indicators => IndicatorsLogic::calc_indicators(project, data[0], data[1])
+ }
+ project.versions.where(:status=>"open").each do |my_version|
+ data = IndicatorsLogic::retrive_data(my_version)
+ @evms << {
+ :name => my_version.name,
+ :indicators => IndicatorsLogic::calc_indicators(my_version, data[0], data[1])
+ }
+ end
+ respond_to do |format|
+ format.html { render :action => 'index' }
+ format.csv {
+ send_data(evm_csv(@evms), :type => 'text/csv; header=present', :filename => 'evm.csv')
+ }
+ end
end
end
@@ -1,2 +1,26 @@
module RatiosHelper
+ def evm_csv(evms)
+ decimal_separator = l(:general_csv_decimal_separator)
+ export = FCSV.generate(:col_sep => l(:general_csv_separator)) do |csv|
+ evms.each do |evm|
+ fields = ["", "cpi", "spi"]
+ csv << fields.collect {|c| Redmine::CodesetUtil.from_utf8(
+ c,
+ l(:general_csv_encoding) ) }
+ fields = []
+ fields << evm[:name]
+ fields << evm[:indicators][1].to_s.gsub('.', decimal_separator)
+ fields << evm[:indicators][2].to_s.gsub('.', decimal_separator)
+ csv << fields.collect {|c| Redmine::CodesetUtil.from_utf8(
+ c,
+ l(:general_csv_encoding) ) }
+ evm[:indicators][0].each do |ent|
+ csv << ent.collect {|c| Redmine::CodesetUtil.from_utf8(
+ c.to_s.gsub('.', decimal_separator),
+ l(:general_csv_encoding) ) }
+ end
+ end
+ end
+ export
+ end
end
@@ -1,30 +1,30 @@
-<div id="chart <%= name %>" class="goocharts"></div>
-<div id="gauge_cpi <%= name %>" class="googauges"></div>
-<div id="gauge_spi <%= name %>" class="googauges"></div>
+<div id="chart <%= evm[:name] %>" class="goocharts"></div>
+<div id="gauge_cpi <%= evm[:name] %>" class="googauges"></div>
+<div id="gauge_spi <%= evm[:name] %>" class="googauges"></div>
<div style="clear:both;"></div>
-<script type="text/javascript">
+<%= javascript_tag do %>
drawChart();
drawCpi();
drawSpi();
function drawChart() {
- var data = new google.visualization.arrayToDataTable(<%=raw @proj_or_vers_indicators[0].to_json %>);
+ var data = new google.visualization.arrayToDataTable(<%= raw evm[:indicators][0].to_json %>);
var options = {
- title: 'EVM Indicators - <%= name %>',
+ title: 'EVM Indicators - <%= evm[:name] %>',
series: {0:{color: 'red'},
1:{color: 'blue'},
2:{color: 'green'}},
vAxis: {title: 'Hours', titleTextStyle: {color: 'red'}}
};
- var chart = new google.visualization.LineChart(document.getElementById("chart <%= name %>"));
+ var chart = new google.visualization.LineChart(document.getElementById("chart <%= evm[:name] %>"));
chart.draw(data, options);
}
function drawCpi() {
// Create and populate the data table.
var data_gauge = new google.visualization.arrayToDataTable([
['Label', 'Value'],
- ['CPI', <%= (@proj_or_vers_indicators[1] * 1000).round / 1000.0 %>]
+ ['CPI', <%= evm[:indicators][1] %>]
]);
var options_g = {
redFrom: 0, redTo: 0.85,
@@ -34,15 +34,15 @@
min:0, max:2
};
// Create and draw the visualization.
- var gauge= new google.visualization.Gauge(document.getElementById("gauge_cpi <%= name %>"));
+ var gauge= new google.visualization.Gauge(document.getElementById("gauge_cpi <%= evm[:name] %>"));
gauge.draw(data_gauge, options_g);
}
function drawSpi() {
// Create and populate the data table.
var data_gauges = new google.visualization.arrayToDataTable([
['Label', 'Value'],
- ['SPI', <%= (@proj_or_vers_indicators[2] * 1000).round / 1000.0 %>]
+ ['SPI', <%= evm[:indicators][2] %>]
]);
var options_gs = {
redFrom: 0, redTo: 0.85,
@@ -52,7 +52,7 @@
min:0, max:2
};
// Create and draw the visualization.
- var gauge= new google.visualization.Gauge(document.getElementById("gauge_spi <%= name %>"));
+ var gauge= new google.visualization.Gauge(document.getElementById("gauge_spi <%= evm[:name] %>"));
gauge.draw(data_gauges, options_gs);
}
-</script>
+<% end %>
@@ -1,6 +1,5 @@
-<script type="text/javascript" src="https://www.google.com/jsapi"></script>
-<script type="text/javascript">
+<%= javascript_include_tag "https://www.google.com/jsapi" %>
+<%= javascript_tag do %>
google.load("visualization", "1", {packages:["corechart"]});
google.load('visualization', '1', {packages: ['gauge']});
-</script>
-
+<% end %>
@@ -6,15 +6,11 @@
<%= stylesheet_link_tag 'ratios', :plugin => 'redmine_evm' %>
<% end %>
-<!--- Load javascript functions --->
-<%= render :partial=>"ratios/bottom_js", :locals=>{:name=>@project.name}%>
-
-<!--- Iterate through versions and render indicators --->
-<% @project.versions.where(:status=>"open").each do |my_version|%>
+<% @evms.each do |evm| %>
<%= render "ratios/head_js" %>
-<% proj_or_vers_data=IndicatorsLogic::retrive_data(my_version) %>
-<% @proj_or_vers_indicators=IndicatorsLogic::calc_indicators(my_version, proj_or_vers_data[0], proj_or_vers_data[1]) %>
-<%= render :partial=>"ratios/bottom_js", :locals=>{:name=>my_version.name}%>
+ <%= render :partial=>"ratios/bottom_js", :locals => {:evm => evm} %>
<% end %>
-
+<% other_formats_links do |f| %>
+ <%= f.link_to 'CSV', :url => params %>
+<% end %>
View
@@ -71,7 +71,7 @@ def self.calc_indicators(my_project_or_version, ary_reported_time_week_year, ary
end
@cpi = hash_weeks_years.values.last[0].zero? ? 0 : hash_weeks_years.values.last[2]/hash_weeks_years.values.last[0]
@spi = hash_weeks_years.values.last[1].zero? ? 0 : hash_weeks_years.values.last[2]/hash_weeks_years.values.last[1]
- return [@ary_data_week_years, @cpi, @spi]
+ return [@ary_data_week_years, (@cpi * 1000).round / 1000.0, (@spi * 1000).round / 1000.0]
end
def self.included(base)

0 comments on commit 576b18d

Please sign in to comment.