build: function()

in Source/html-report/js/report_builder.js [436:528]


	build: function(stats, calls) {
		this.stats = stats;
		this.calls = calls;
		this.countTitle = $("<div>").addClass("graph-header").text("Calls Per Endpoint");
		this.callCountgraph = $("<div>").css({ "width": "780px", "height": "300px", "margin": "auto"});
		this._buildCountsGraph(this.stats);
		
		
		this.statDetails = $("<table>").addClass("stats-table");
		var header = $("<tr>");
		var endpoint = $("<td>").text("Endpoint").addClass("endpoint");
		var totalCalls = $("<td>").text("Total Calls").addClass("center-text");
		var avgTime = $("<td>").text("Average Time Between Calls");
		this.statDetails.append(header.append(endpoint, totalCalls, avgTime));
		var details = this.statDetails;
		$.each(this.stats, function(index, stat) {
			var endpointRow = $("<tr>");
			var endpointName = stat[API]? stat[API] : stat["Uri"];
			var endpoint = $("<td>").addClass("endpoint").html("<b>" + endpointName + "</b>");
			var totalCalls = $("<td>").addClass("center-text").text(stat["Call Count"]);
			var avgTime = $("<td>").text(Number(stat["Average Time Between Calls"] / 1000).toFixed(3) + " seconds");

			endpointRow.append(endpoint, totalCalls, avgTime);
			details.append(endpointRow);
		});	
		
		var callCountGraphData = this.callCountGraphData;
		
		$.each(stats, function(index, stat) {
			callCountGraphData.push([ stat["Call Count"],stat[API] ]);
		});
		
		this.timelineTitle = $("<div>").addClass("graph-header").text("Calls Per Second");
		this.timelineGraph = $("<div>").css({ "width": "780px", "height": "300px", "margin": "auto"});
		var timelineGraphData = this.timelineGraphData;
		var startTime = calls["Start Time"];
		var endTimeRel = Number((calls["End Time"] - startTime) / 1000).toFixed(0);
		var maxHeight = 0;
		
		$.each(this.calls["Call List"], function(index, endpoint) {
			var endpointData = {
				label: endpoint[API],
				data: [],
				endpoint: endpoint
			};
			var callsPerSecond = {};
			$.each(endpoint.Calls, function(index, call) {
				var relTime = ((call.ReqTime - startTime) / 1000).toFixed(0);
				if(callsPerSecond[relTime.toString()] === undefined)
				{
					callsPerSecond[relTime.toString()] = 0;
				}
				callsPerSecond[relTime.toString()]++;
			});
			
			if(callsPerSecond["0"] === undefined)
			{
				endpointData.data.push([0,0]);
			}
			
			for(second in callsPerSecond)
			{
				var secondNum = Number(second);
				
				if(callsPerSecond[(secondNum - 1).toString()] === undefined)
				{
					endpointData.data.push([ secondNum - 1, 0 ]);
				}
				
				endpointData.data.push([ secondNum, callsPerSecond[second] ]);
				
				if(callsPerSecond[second] > maxHeight) {
					maxHeight = callsPerSecond[second];
				}
				
				if(callsPerSecond[(secondNum + 1).toString()] === undefined)
				{
					endpointData.data.push([ secondNum + 1, 0 ]);
				}
			}
			
			timelineGraphData.push(endpointData)
		});
		
		this.timelineGraphOptions.xaxis.zoomRange = [5,endTimeRel];
		this.timelineGraphOptions.xaxis.panRange = [0,endTimeRel];
		this.timelineGraphOptions.xaxis.max = endTimeRel;
		
		this.timelineGraphOptions.yaxis.zoomRange = [5,maxHeight * 1.1];
		this.timelineGraphOptions.yaxis.panRange = [0,maxHeight * 1.1];
		this.timelineGraphOptions.yaxis.max = maxHeight * 1.1;

	},