package org.spbu.benchmark;

import java.util.List;

public class DefaultBenchmarkResult implements BenchmarkResult {
	private List<ScenarioResult> scenarioResults;
	private int s, f;
	private long time;
	private long max, min, avg;
	private float t;
	public DefaultBenchmarkResult( List<ScenarioResult> scenarioResults, int successful, int failed){
		this.scenarioResults = scenarioResults;
		this.s = successful;
		this.f = failed;
		this.time = 0;
		this.max = 0;
		this.min = -1;
		float totalRequests = 0;
		for(ScenarioResult result : scenarioResults){
			this.time+=result.getTime();
			if(this.max<result.getTime()) this.max = result.getTime();
			if((this.min>result.getTime())||(this.min==-1)) this.min = result.getTime();
			totalRequests += result.getActionResults().size();
		}

		if(scenarioResults.size()>0)this.avg = time / scenarioResults.size(); else this.avg = 0;
		if (avg!=0) this.t = totalRequests / ((float)avg/1000); else this.t = 0 ;
	}
	@Override
	public float avgResponse() {
		return avg;
	}

	@Override
	public int failed() {
		return f;
	}

	@Override
	public List<ScenarioResult> getScenarioResults() {
		return scenarioResults;
	}

	@Override
	public long getTime() {
		return time;
	}

	@Override
	public float maxResponse() {
		return max;
	}

	@Override
	public float minResponse() {
		return min;
	}

	@Override
	public int succeeded() {
		return s;
	}

	@Override
	public float throughput() {
		return t;
	}

}
