<script>
	function show_load_operation_errors() {
		$.getScript("/builds/<%= @build.id %>/load-operation-errors");
	}
	
    function show_load_operation_history(load_test_result_id) {
	    $.getScript('/load/' + load_test_result_id + '/history');
    }
	
</script>

<div class="section_open">
  <div class="section_header" onclick="toggle_section(this.parentNode)">
     <%= I18n.t(:load_test_results) %>
  </div>	 
  <div class="section_content">
    <% @info = { "operation" => []}%>

    <div class="rspec-report">

        <div id="">
          <div class="row">
         			<div class="col-sm-3 col-md-2">
         				VUs:
         				<b><font color="blue"><%= @build_load_test_results.pluck("agent_name").uniq.count %></font></b>
         			</div>
         			<div class="col-sm-3 col-md-2">
         				Hits:  <b><font color="blue">
                  <%= @build_load_test_results.count %>
                </font></b>
         			</div>
         			<div class="col-sm-5 col-md-4">
         				Hits per second:  <b class="blue"><%= @build.load_hits_per_second%></b> 
                (Peak: <b class="brown"><%= @build.load_peak_hits_per_second %></b>)
              </b>
         			</div>
         			<div class="col-sm-4 col-md-3">
					      Errors: 
                <% error_count =  @build_load_test_results.where("success != ?", true).count %>
                <% if error_count > 0 %>
                  <% error_rate = error_count * 100.0 / @build_load_test_results.count %>
                   <b class="red"><%= number_to_percentage(error_rate,  precision: 2) %></b>
                  (<a href="javascript:void(0);" onclick='show_load_operation_errors();'><%= error_count %></a>)
                <% else %>
         				 <b class="green">0</b>
                <% end %>
         			</div>
          </div>
      		
      </div>
    </div>

    <!-- operation timing -->
    
    <div class="response-times-table" style="margin-top: 15px; margin-bottom: 15px;">
      <h6>Response times</h6>
      <table id="users" class="table table-striped table-condensed">
        <thead>
          <tr>
        		<th width="50%"><%= I18n.t(:operation)%></th>
        		<th style="text-align:right;">#</th>
        		<th style="text-align:right;"><%= I18n.t(:average)%> (ms)</th>
        		<th style="text-align:right;"><%= I18n.t(:fastest)%> (ms)</th>
        		<th style="text-align:right;"><%= I18n.t(:slowest)%> (ms)</th>
        		<th style="text-align:right;"><%= I18n.t(:error)%></th>
        	</tr>
        </thead>
        <tbody>	
          <% if @raw_operation_timings %>
		    <% idx = 0 %>
            <% @raw_operation_timings.each do |key, val| %>
              <% duration_array =  val.collect{|x| x.duration}  %>
	    		<tr>
					<td>
					<a href="javascript:void(0)" class="individual_operation_load_test_history" onclick="show_load_operation_history(<%= val[0].id %>);"><i class="fa fa-bar-chart"></i></a>
					<a href="javascript:void(0);" onclick="show_chart_series(<%= idx %>);"><%= key %></a>
					</td>
        			<td style="text-align:right;"><%=  val.size %></td>
					<td style="text-align:right;"><%= (duration_array.sum / val.count).round(3) %></td>
					<td style="text-align:right;"><%= duration_array.min %></td>
					<td style="text-align:right; padding-right: 15px;"><%= duration_array.max %></td>
          <td style="text-align:right; padding-right: 15px;">
            <% operation_error_count = @build_load_test_results.where("success != ? AND operation = ?", true, key).count %> 
            <% if operation_error_count > 0 %><%= operation_error_count %><% end %>
          </td>
				</tr>
				<% idx += 1 %>
  			<% end%>
          <% end %>
        </tbody>
      </table> 
    </div>
     
    <%= partial "/builds/load_test_operation_timings_completed".to_sym %>      
	 
     
  </div>
  
</div>


