lodestone (owner)

Fork Of

Revisions

gist: 55211 Download_button fork
public
Public Clone URL: git://gist.github.com/55211.git
Embed All Files: show embed
Ruby #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
  def advisor
    @license = 'LTAM663SPJLO.945CWK-2XOI1X0-7L'
    advisor = Advisor.find(params[:id])
    category = params[:category]
    case category
    when 'fixed'
      chart_years = advisor.fixed_product_years.find_all_by_year(@year_num)
    when 'combined'
      chart_years = advisor.categorical_years.find_all_by_year(@year_num)
    else
      chart_years = advisor.categorical_years.find(:all, :conditions => ['categories.name = ? AND years.year = ?', category, @year_num])
    end
    chart = Ziya::Charts::Mixed.new(LICENSE, "company_runrate")
    chart.add( :axis_category_text, [''] + MONTHS )
    chart.add :theme , "statusroom"
    if chart_years.blank?
      chart.add(:series, [0]*13)
    else
      if category.name == 'combined'
        chart.add :chart_types, %w[area area area area area line line line line line line column]
        chart.add(:series, PERFORMANCE_METRIC_4[:label], [PERFORMANCE_METRIC_4[:label] *13])
        chart.add(:series, PERFORMANCE_METRIC_3[:label], [PERFORMANCE_METRIC_3[:label] *13])
        chart.add(:series, PERFORMANCE_METRIC_2[:label], [PERFORMANCE_METRIC_2[:label] *13])
        chart.add(:series, PERFORMANCE_METRIC_1[:label], [PERFORMANCE_METRIC_2[:label] *13])
        chart.add(:series, PERFORMANCE_METRIC_0[:label], [PERFORMANCE_METRIC_0[:label] *13])
      else
        chart.add :chart_types, %w[line line line line line line line]
      end
      chart_data = Chart.new(chart_years)
      chart.add(:series, 'Min Target', [chart_data.report[:'Annual Minimum' ].first] * 13)
      chart.add(:series, 'Min Target Cum.', [0] + chart_data.report[:'Minimum Target Cum.'])
      chart.add(:series, 'Annual Target', [chart_data.report[:'Annual Target'].first] * 13)
      chart.add(:series, 'Target Cum.', [0] + chart_data.report[:'Target Cumulative'])
      chart.add(:series, 'Fixed Products', [0] + chart_data.report[:'Actual'])
      chart.add(:series, 'Runrate', [0] + chart_data.report[:'Run Rate'])
      chart.add(:series, 'Actual Cum.', [0] + chart_data.report[:'Actual Cumulative'])
    end
    respond_to do |wants|
      wants.xml { render :text => chart.to_xml and return }
    end
  end