Skip to content

Instantly share code, notes, and snippets.

@c3mediagroup
Created June 18, 2009 16:42
Show Gist options
  • Save c3mediagroup/131992 to your computer and use it in GitHub Desktop.
Save c3mediagroup/131992 to your computer and use it in GitHub Desktop.
def advisor
advisor = User.advisor.find(params[:id])
category = params[:category]
case category
when 'fixed'
chart_years = advisor.fixed_product_years.find_all_by_year(@year_num)
chart_yaml = "advisor_runrate"
when 'combined'
chart_years = advisor.combined_product_years.find_all_by_year(@year_num)
chart_yaml = "advisor_runrate_combined"
when 'gdc'
chart_years = advisor.gdc_years.find_all_by_year(@year_num)
chart_yaml = "advisor_runrate"
else
chart_years = advisor.categorical_years.find(:all, :conditions => ['categories.name = ? AND years.year = ?', category, @year_num])
chart_yaml = "advisor_runrate"
end
chart = Ziya::Charts::Mixed.new(LICENSE, chart_yaml)
chart.add( :axis_category_text, [''] + MONTHS )
chart.add :theme , (params[:theme] || "statusroom")
if chart_years.blank?
chart.add(:series, [0]*13)
else
chart_data = Chart.new(chart_years)
perf_chart_types = []
series_explode = []
# APR, Leaders,
# club_colors = %w[777777 999999 aaaaaa cccccc eeeeee]
club_colors = %w[af9e56 bcae71 c8be8e d4cca9 e3deca]
# target cum, min cum, actual cum, min, target, runrate, actual
colors = %w[6ba139 c13b2b 306787 c13b2b 6ba139 306787 f0cd2d]
# colors = ['ff0000']*12 #ff0000 #bbffbb #ccffcc #ddffdd #eeffee]
if category == 'combined'
metrics = [PERFORMANCE_METRIC_0, PERFORMANCE_METRIC_1, PERFORMANCE_METRIC_2, PERFORMANCE_METRIC_3, PERFORMANCE_METRIC_4]
max_total = Year.calculate(:max, :total, :conditions => {:id => chart_years.map(&:id)})
# Grab the metrics less than
advisor_metrics = metrics.collect{|m| m if max_total > m[:metric] }.compact
# Grab the first metric greater than
advisor_metrics << metrics.detect {|m| m[:metric] > max_total }
advisor_metrics.each do |metric|
chart.add(:series, metric[:label], [metric[:metric]] * 13)
perf_chart_types << "area"
series_explode << 100
end
chart.add :chart_types, (perf_chart_types + %w[line line line line line line line])
else
chart.add :chart_types, %w[line line line line line line line]
end
series_explode = params[:small_lines] ? [20, 20, 20, 20, 20, 20, 20] : [50, 50, 50, 100, 100, 100, 75]
chart.add(:series, 'Target Cumulative', [0] + chart_data.report[:'Target Cumulative'])
chart.add(:series, 'Minimum Target Cum.', [0] + chart_data.report[:'Minimum Target Cum.'])
chart.add(:series, 'Actual Cumulative', [0] + chart_data.report[:'Actual Cumulative'])
chart.add(:series, 'Annual Minimum', [chart_data.report[:'Annual Minimum' ].first] * 13)
chart.add(:series, 'Annual Target', [chart_data.report[:'Annual Target'].first] * 13)
chart.add(:series, 'Run Rate', [0] + chart_data.report[:'Run Rate'])
chart.add(:series, 'Actual', [0] + chart_data.report[:'Actual'])
chart.add :user_data, :series_explode, series_explode
chart.add :user_data, :colors, (club_colors[0..perf_chart_types.length-1]+colors).join(',')
end
respond_to do |wants|
wants.xml { render :text => chart.to_xml and return }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment