Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

add exporting csv feature #11

Merged
merged 7 commits into from

2 participants

@marutosi
Collaborator

No description provided.

@gamafranco gamafranco merged commit 576b18d into imaginary-cloud:master
@gamafranco
Owner

@marutosi thanks for this set of commits. They're very good.

@gamafranco
Owner

@marutosi, I gave you push access to the repo. It will make your contributions easier to merge (in case you make any).

@gamafranco
Owner

For some reason, the main menu disappeared on the EVM view with this commit. Just made a git bisect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
View
29 .gitignore
@@ -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
3  .hgignore
@@ -0,0 +1,3 @@
+syntax: glob
+
+.git
View
26 app/controllers/ratios_controller.rb
@@ -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
View
24 app/helpers/ratios_helper.rb
@@ -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
View
24 app/views/ratios/_bottom_js.html.erb
@@ -1,22 +1,22 @@
-<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);
}
@@ -24,7 +24,7 @@
// 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,7 +34,7 @@
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);
}
@@ -42,7 +42,7 @@
// 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 %>
View
7 app/views/ratios/_head_js.html.erb
@@ -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 %>
View
14 app/views/ratios/index.html.erb
@@ -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
2  lib/indicators_logic.rb
@@ -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)
Something went wrong with that request. Please try again.