Skip to content

Instantly share code, notes, and snippets.

@elbertwang
Last active March 4, 2016 02:22
Show Gist options
  • Save elbertwang/c3c4647a381a2cd118a5 to your computer and use it in GitHub Desktop.
Save elbertwang/c3c4647a381a2cd118a5 to your computer and use it in GitHub Desktop.
function tab1_gen_report(){
var team = $('#ms_team_tab1').val(),
granularity = $('#ms_granularity_tab1').val();
gen_chart('stacked_column', 'get_case_volume_by_ttc', 'chart_case_volume_by_ttc', team, granularity, start_date, end_date);
gen_chart('stacked_column', 'get_case_volume_by_ttc_sev_5_1', 'chart_case_volume_by_ttc_sev_5_1', team, granularity, start_date, end_date);
gen_chart('stacked_column', 'get_case_volume_by_ttc_sev_2_3_4', 'chart_case_volume_by_ttc_sev_2_3_4', team, granularity, start_date, end_date);
gen_chart('spline', 'get_avg_ttc', 'chart_avg_ttc', team, granularity, start_date, end_date);
gen_chart('spline', 'get_avg_ttc_by_severity', 'chart_avg_ttc_by_severity', team, granularity, start_date, end_date);
}
function gen_chart(type, method, container, team, granularity, start_date, end_date){
$.ajax({
url: "/operation_metrics/get_chart_js",
type: 'POST',
data: {
"type": type,
"method": method,
"container": container,
"team": team,
"granularity": granularity,
"start_date": start_date,
"end_date": end_date
},
async: true,
success: function(data, textStatus, xhr) {
eval(data);
},
error: function() {
}
});
}
class Charts < ActiveRecord::Base
establish_connection 'mkdb'
self.table_name = 'o_communications_cn'
def self.get_avg_ttc(params)
team = params[:team]
granularity = params[:granularity]
startDate = params[:start_date]
endDate = params[:end_date]
granuText = MKUtils.get_granu_text(granularity, 'case_resolve_date_utc')
emailQueueText = MKUtils.get_email_queue_text(team)
self.find_by_sql("select 'avg_ttc' as name, #{granuText} period, ceil(avg(timestampdiff(day,CREATION_DATE_UTC,case_resolve_date_utc))) dt from d_case_details_cn where primary_email_id not like 'aws%@amazon.com' and case_resolve_date_utc >= str_to_date('#{startDate}','%Y%m%d') and case_resolve_date_utc < date_add(STR_TO_DATE('#{endDate}', '%Y%m%d'),interval 1 day) and case_status_name='resolved' #{emailQueueText} group by name, period")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment