Module Analytics::UrlBreakup
In: lib/graph_controller_extensions/url_breakup_analytics.rb

Methods

Public Instance methods

This method renders the pie graph and time consumption details for a specific url listed in the select box.

[Source]

     # File lib/graph_controller_extensions/url_breakup_analytics.rb, line 119
119:     def get_url_breakdown
120:       app_id = params[:id]
121:       start_time = params[:start_time]
122:       end_time = params[:end_time]
123:       url = params[:url_name]
124:       if params[:urls]
125:         @url_rank = params[:urls].rindex(url) + 1
126:         @suffix = get_suffix(@url_rank)
127:       end
128:       @data_x, @data_y, @url_breakup_graph, @data_actual_time = get_url_breakup_graph_data(start_time, end_time, app_id, Array[url])
129:       render :partial => 'pie'
130:     end

This method render the pie graphs and its percentage time consumption table for the first url in the list of url for current day.

[Source]

     # File lib/graph_controller_extensions/url_breakup_analytics.rb, line 100
100:     def get_url_breakup_data(app_id)
101:       @app_id = app_id
102:       check_and_set_query_period()
103:       @start_time = session[:from_date].strftime("%Y/%m/%d")
104:       start_time = session[:from_date]
105:       @end_time = session[:to_date].strftime("%Y/%m/%d")
106:       end_time = session[:to_date]      
107:       @urls = UrlTimeSample.get_urls(start_time, end_time, app_id)
108:       if @urls.size > 0
109:         @url_rank = 1
110:         @suffix = get_suffix(@url_rank)
111:         @data_x, @data_y, @url_breakup_graph, @data_actual_time = get_url_breakup_graph_data(@start_time, @end_time, @app_id, @urls)
112:       else
113:         flash[:notice] = NO_URL_HITS
114:       end
115:       render :partial => "url_breakup_graph"
116:     end

This method gives the details of url calls and there time spent by the url in different place i.e in database,rendering etc. and it also returns the pie graph data for the same.

[Source]

    # File lib/graph_controller_extensions/url_breakup_analytics.rb, line 25
25:     def get_url_breakup_graph_data(start_time, end_time, app_id, urls)
26:       url = urls[0]
27:       data_1, url_name, data_x, data_y, data_actual_time = pie_data(app_id,"#{url}-#{start_time}-#{end_time}")
28:       data_x = data_x
29:       data_y = data_y
30:       url_breakup_graph = plot_graph("graph/pie/#{app_id}?url=#{url}-#{start_time}-#{end_time}", 'pie')
31:       return data_x, data_y, url_breakup_graph, data_actual_time
32:     end

This method gives the percentage time taken by a url in different parts like database and rendering etc.

[Source]

    # File lib/graph_controller_extensions/url_breakup_analytics.rb, line 35
35:     def pie_data(app_id, url_data)
36:       data_str = url_data.split("-")
37:       url_name = data_str[0]
38:       date_str = data_str[1].split("/")
39:       start_time = Time.local(date_str[0],date_str[1],date_str[2])
40:       date_str = data_str[2].split("/")
41:       end_time = Time.local(date_str[0],date_str[1],date_str[2], '23', '59', '59')
42:       
43:       url_sample = UrlTimeSample.get_url_data(start_time, end_time, app_id, url_name)
44:       
45:       db_time = round((url_sample[0].db_time.to_f*100/url_sample[0].total_time.to_f).to_f)
46:       rendering_time = round(url_sample[0].rendering_time.to_f * 100 / url_sample[0].total_time.to_f)
47:       remaining_time = round(100 - db_time-rendering_time)
48:       data_x = Array.new
49:       data_y = Array.new
50:       data_actual_time = Array.new
51:       data_1 = Array.new
52:       if db_time > 0
53:         url_sample_ids = UrlTimeSample.get_url_id(start_time, end_time, url_name, app_id)
54:         url_id = Array.new
55:         url_sample_ids.each do |url_sample_id|
56:           url_id << url_sample_id.id
57:         end
58:         url_breakup_sample = UrlBreakupTimeSample.get_url_breakup_sample_data(url_id)
59:         url_breakup_sample.each do |url|
60:           time = (url.time_spent.to_f*100 / url_sample[0].total_time.to_f).to_f
61:           time = round(time)
62:           data_x << url.method_name
63:           data_y << time
64:           data_actual_time << round(url.time_spent.to_f / 1000)
65:           if time>2
66:             data_1 << OFC2::PieValue.new(time, url.method_name)
67:           else
68:             data_1 << OFC2::PieValue.new(time, " ")
69:           end
70:         end
71:         data_x << "Rendering Time"
72:         data_y << rendering_time
73:         data_actual_time << round(url_sample[0].rendering_time.to_f/1000)
74:         data_1 << OFC2::PieValue.new(rendering_time, 'Rendering Time')
75:         data_x << "Remaining Time"
76:         data_y << remaining_time
77:         data_actual_time << round((url_sample[0].total_time.to_f-url_sample[0].rendering_time.to_f-url_sample[0].db_time.to_f)/1000)
78:         data_1 << OFC2::PieValue.new(remaining_time, 'Remaining Time')
79:       else
80:         data_x << "Rendering Time"
81:         data_y << rendering_time
82:         data_actual_time << round(url_sample[0].rendering_time.to_f/1000)
83:         data_1 << OFC2::PieValue.new(rendering_time, 'Rendering Time')
84:         data_x << "Remaining Time"
85:         data_y << remaining_time
86:         data_actual_time << round((url_sample[0].total_time.to_f-url_sample[0].rendering_time.to_f-url_sample[0].db_time.to_f)/1000)
87:         data_1 << OFC2::PieValue.new(remaining_time, 'Remaining Time')
88:       end
89:       return data_1, url_name, data_x, data_y, data_actual_time
90:     end

This method is called when the refresh button is clicked from the url_breakdown graph.

[Source]

    # File lib/graph_controller_extensions/url_breakup_analytics.rb, line 93
93:     def refresh_pie_graph
94:       app_id = params[:app_id]
95:       get_url_breakdown_data(app_id)
96:     end

This function rounds of the float upto 2 decimal places

[Source]

     # File lib/graph_controller_extensions/url_breakup_analytics.rb, line 133
133:     def round(value)
134:       return sprintf("%0.2f",value).to_f
135:     end

[Validate]