1402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/*******************************************************************************
2402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Copyright (c) 2000, 2009 IBM Corporation and others.
3402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * All rights reserved. This program and the accompanying materials
4402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * are made available under the terms of the Eclipse Public License v1.0
5402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * which accompanies this distribution, and is available at
6402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * http://www.eclipse.org/legal/epl-v10.html
7402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *
8402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Contributors:
9402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *     IBM Corporation - initial API and implementation
10402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *******************************************************************************/
11402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpackage org.eclipse.test.internal.performance.results.db;
12402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
13402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport java.io.DataInputStream;
14402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport java.io.DataOutputStream;
15402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport java.io.IOException;
16402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport java.text.ParseException;
17402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport java.util.StringTokenizer;
18402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
19402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.test.internal.performance.InternalPerformanceMeter;
20402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.test.internal.performance.PerformanceTestPlugin;
21402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.test.internal.performance.data.Dim;
22402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollimport org.eclipse.test.internal.performance.results.utils.Util;
23402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
24402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/**
25402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Class providing numbers of a scenario running on a specific configuration
26402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * at a specific time (for example 'I20070615-1200').
27402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
28402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic class BuildResults extends AbstractResults {
29402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
30402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	private static final double IMPOSSIBLE_VALUE = -1E6;
31402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
32402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// Build information
33402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	String date;
34402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	String comment;
35402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	int summaryKind = -1;
36402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
37402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// Dimensions information
38402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	Dim[] dimensions;
39402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	double[] average, stddev;
40402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	long[] count;
41402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	double[][] values;
42402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	boolean hadValues = false;
43402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	private int defaultDimIndex = -1;
44402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
45402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// Comparison information
46402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	boolean baseline;
47402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	String failure;
48402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
49402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael MollBuildResults(AbstractResults parent) {
50402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	super(parent, -1);
51402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
52402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
53402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael MollBuildResults(AbstractResults parent, int id) {
54402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	super(parent, id);
55402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	this.name = DB_Results.getBuildName(id);
56402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	this.baseline = this.name.startsWith(DB_Results.getDbBaselinePrefix());
57402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
58402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
59402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/*
60402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Clean values when several measures has been done for the same build.
61402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
62402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollvoid cleanValues() {
63402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	int length = this.values.length;
64402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	for (int dim_id=0; dim_id<length; dim_id++) {
65402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		int vLength = this.values[dim_id].length;
66402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		/* Log clean operation
67402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		if (dim_id == 0) {
68402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			IStatus status = new Status(IStatus.WARNING, PerformanceTestPlugin.PLUGIN_ID, "Clean "+vLength+" values for "+this.parent+">"+this.name+" ("+this.count[dim_id]+" measures)...");    //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$ //$NON-NLS-5$
69402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			PerformanceTestPlugin.log(status);
70402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
71402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		*/
72402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		this.average[dim_id] = 0;
73402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		for (int i=0; i<vLength; i++) {
74402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			this.average[dim_id] += this.values[dim_id][i];
75402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
76402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		this.average[dim_id] /= vLength;
77402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		double squaredDeviations= 0;
78402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		for (int i=0; i<vLength; i++) {
79402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		    double deviation= this.average[dim_id] - this.values[dim_id][i];
80402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		    squaredDeviations += deviation * deviation;
81402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
82402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		this.stddev[dim_id] = Math.sqrt(squaredDeviations / (this.count[dim_id] - 1)); // unbiased sample stdev
83402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		this.values[dim_id] = null;
84402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
85402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	for (int i=0; i<length; i++) {
86402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		if (this.values[i] != null) {
87402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			return;
88402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
89402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
90402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	this.values = null;
91402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	this.hadValues = true;
92402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
93402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
94402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/**
95402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Compare build results using the date of the build.
96402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *
97402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * @see Comparable#compareTo(Object)
98402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
99402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic int compareTo(Object obj) {
100402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (obj instanceof BuildResults) {
101402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		BuildResults res = (BuildResults) obj;
102402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		return getDate().compareTo(res.getDate());
103402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
104402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	return -1;
105402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
106402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
107402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/**
108402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Returns the most recent baseline build results.
109402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *
110402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * @return The {@link BuildResults baseline build results}.
111402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * @see BuildResults
112402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
113402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic BuildResults getBaselineBuildResults() {
114402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	return ((ConfigResults)this.parent).getBaselineBuildResults();
115402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
116402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
117402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/**
118402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Returns the comment associated with the scenario for the current build.
119402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *
120402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * @return The comment associated with the scenario for the current build
121402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * 	or <code>null</code> if no comment was stored for it.
122402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
123402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic String getComment() {
124402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	return this.comment;
125402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
126402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
127402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/**
128402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Return the number of stored values for the default dimension
129402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *
130402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * @return the number of stored values for the default dimension
131402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
132402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic long getCount() {
133402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (this.defaultDimIndex < 0) {
134402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		this.defaultDimIndex = DB_Results.getDefaultDimensionIndex();
135402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
136402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	return this.count[this.defaultDimIndex];
137402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
138402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
139402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/**
140402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Return the number of stored values for the given dimension.
141402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *
142402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * @param dim_id The id of the dimension (see {@link Dim#getId()})
143402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * @return the number of stored values for the given dimension
144402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *
145402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
146402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic long getCount(int dim_id) {
147402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	return this.count[getDimIndex(dim_id)];
148402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
149402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
150402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/**
151402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Returns the date of the build which is a part of its name.
152402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *
153402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * @return The date of the build as yyyyMMddHHmm
154402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
155402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic String getDate() {
156402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (this.date == null) {
157402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		if (this.baseline) {
158402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			int length = this.name.length();
159402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			this.date = this.name.substring(length-12, length);
160402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		} else {
161402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			char first = this.name.charAt(0);
162402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			if (first == 'N' || first == 'I' || first == 'M') { // TODO (frederic) should be buildIdPrefixes...
163402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				if (this.name.length() == 14) {
164402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll					this.date = this.name.substring(1, 9)+this.name.substring(10, 14);
165402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				} else {
166402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll					this.date = this.name.substring(1);
167402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				}
168402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			} else {
169402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				int length = this.name.length() - 12 /* length of date */;
170402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				for (int i=0; i<=length; i++) {
171402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll					try {
172402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll						String substring = i == 0 ? this.name : this.name.substring(i);
173402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll						Util.DATE_FORMAT.parse(substring);
174402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll						this.date = substring; // if no exception is raised then the substring has a correct date format => store it
175402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll						break;
176402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll					} catch(ParseException ex) {
177402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll						// skip
178402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll					}
179402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				}
180402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			}
181402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
182402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
183402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	return this.date;
184402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
185402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
186402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/**
187402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Returns the standard deviation of the default dimension computed
188402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * while running the scenario for the current build.
189402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *
190402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * @return The value of the standard deviation
191402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
192402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic double getDeviation() {
193402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (this.defaultDimIndex < 0) {
194402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		this.defaultDimIndex = DB_Results.getDefaultDimensionIndex();
195402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
196402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	return this.stddev[this.defaultDimIndex];
197402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
198402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
199402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/**
200402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Returns the standard deviation of the given dimension computed
201402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * while running the scenario for the current build.
202402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *
203402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * @param dim_id The id of the dimension (see {@link Dim#getId()})
204402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * @return The value of the standard deviation
205402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
206402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic double getDeviation(int dim_id) {
207402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	final int dimIndex = getDimIndex(dim_id);
208402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	return dimIndex < 0 ? 0 : this.stddev[dimIndex];
209402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
210402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
211402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/**
212402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Returns the dimensions supported for the current build.
213402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *
214402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * @return An array of dimensions.
215402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
216402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic Dim[] getDimensions() {
217402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	return this.dimensions;
218402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
219402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
220402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/**
221402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Returns the kind of summary for the scenario of the current build.
222402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *
223402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * @return -1 if the scenario has no summary, 1 if it's a global summary, 0 otherwise.
224402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
225402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic int getSummaryKind() {
226402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	return this.summaryKind;
227402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
228402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
229402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/**
230402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Returns whether the current build had several values stored in database.
231402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *
232402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * @return <code>true</code> if the measure was committed several times,
233402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * <code>false</code> otherwise.
234402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
235402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic boolean hadValues() {
236402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	return this.hadValues;
237402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
238402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
239402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/*
240402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Return the index of the dimension corresponding to the given
241402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * dimension id (see {@link Dim#getId()})
242402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
243402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollint getDimIndex(int dim_id) {
244402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (this.dimensions == null) return -1;
245402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	int length = this.dimensions.length;
246402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	for (int i=0; i<length; i++) {
247402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		if (this.dimensions[i] == null) break;
248402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		if (this.dimensions[i].getId() == dim_id) {
249402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			return i;
250402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
251402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
252402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	return -1;
253402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
254402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
255402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/**
256402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Return the error computed while storing values for the default dimension
257402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *
258402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * @return the error of the measures stored for the default dimension
259402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
260402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic double getError() {
261402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	long n = getCount();
262402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (n == 1) return Double.NaN;
263402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	return getDeviation() / Math.sqrt(n);
264402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
265402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
266402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/**
267402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Return the error computed while storing values for the given dimension.
268402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *
269402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * @param dim_id The id of the dimension (see {@link Dim#getId()})
270402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * @return the error of the measures stored for the given dimension
271402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
272402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic double getError(int dim_id) {
273402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	long n = getCount(dim_id);
274402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (n == 1) return Double.NaN;
275402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	return getDeviation(dim_id) / Math.sqrt(n);
276402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
277402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
278402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/**
279402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Return the failure message which may happened on this scenario
280402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * while running the current build
281402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *
282402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * @return The failure message or <code>null</null> if the scenario passed.
283402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
284402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic String getFailure() {
285402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	return this.failure;
286402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
287402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
288402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/**
289402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Return the value of the performance result stored
290402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * for the given dimension of the current build.
291402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *
292402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * @param dim_id The id of the dimension (see {@link Dim#getId()})
293402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * @return The value of the performance result
294402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
295402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic double getValue(int dim_id) {
296402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	int idx = getDimIndex(dim_id);
297402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (idx < 0) return Double.NaN;
298402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	return this.average[idx];
299402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
300402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
301402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/**
302402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Return the value of the performance result stored
303402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * for the default dimension of the current build.
304402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *
305402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * @return The value of the performance result
306402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
307402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic double getValue() {
308402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (this.defaultDimIndex < 0) {
309402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		this.defaultDimIndex = DB_Results.getDefaultDimensionIndex();
310402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
311402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	return this.average[this.defaultDimIndex];
312402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
313402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
314402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/**
315402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Returns whether the build is a baseline build or not.
316402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *
317402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * @return <code>true</code> if the build name starts with the baseline prefix
318402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * 	(see {@link PerformanceResults#getBaselinePrefix()} or <code>false</code>
319402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * 	otherwise.
320402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
321402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic boolean isBaseline() {
322402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	return this.baseline;
323402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
324402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
325402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/**
326402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Returns whether the build has a summary or not. Note that the summary
327402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * may be global or not.
328402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *
329402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * @return <code>true</code> if the summary kind is equals to 0 or 1
330402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * 	<code>false</code> otherwise.
331402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
332402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic boolean hasSummary() {
333402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	return this.summaryKind >= 0;
334402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
335402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/**
336402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Returns whether the build has a global summary or not.
337402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll *
338402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * @return <code>true</code> if the summary kind is equals to 1
339402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * 	<code>false</code> otherwise.
340402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
341402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic boolean hasGlobalSummary() {
342402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	return this.summaryKind == 1;
343402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
344402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
345402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/*
346402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Returns a given pattern match the build name or not.
347402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
348402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollboolean match(String pattern) {
349402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (pattern.equals("*")) return true; //$NON-NLS-1$
350402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (pattern.indexOf('*') < 0 && pattern.indexOf('?') < 0) {
351402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		pattern += "*"; //$NON-NLS-1$
352402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
353402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	StringTokenizer tokenizer = new StringTokenizer(pattern, "*?", true); //$NON-NLS-1$
354402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	int start = 0;
355402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	String previous = ""; //$NON-NLS-1$
356402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	while (tokenizer.hasMoreTokens()) {
357402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		String token = tokenizer.nextToken();
358402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		if (!token.equals("*") && !token.equals("?")) { //$NON-NLS-1$ //$NON-NLS-2$
359402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			if (previous.equals("*")) { //$NON-NLS-1$
360402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				int idx = this.name.substring(start).indexOf(token);
361402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				if (idx < 0) return false;
362402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				start += idx;
363402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			} else {
364402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				if (previous.equals("?")) start++; //$NON-NLS-1$
365402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				if (!this.name.substring(start).startsWith(token)) return false;
366402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			}
367402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			start += token.length();
368402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
369402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		previous = token;
370402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
371402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (previous.equals("*")) { //$NON-NLS-1$
372402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		return true;
373402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	} else if (previous.equals("?")) { //$NON-NLS-1$
374402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		return this.name.length() == start;
375402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
376402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	return this.name.endsWith(previous);
377402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
378402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
379402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/*
380402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Read the build results data from the given stream.
381402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
382402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollvoid readData(DataInputStream stream) throws IOException {
383402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	long timeBuild = stream.readLong();
384402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	this.date = new Long(timeBuild).toString();
385402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	byte kind = stream.readByte();
386402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	this.baseline = kind == 0;
387402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (this.baseline) {
388402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		this.name = getPerformance().baselinePrefix + '_' + this.date;
389402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	} else {
390402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		String suffix = this.date.substring(0, 8) + '-' + this.date.substring(8);
391402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		switch (kind) {
392402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			case 1:
393402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				this.name = "N" + suffix; //$NON-NLS-1$
394402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				break;
395402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			case 2:
396402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				this.name = "I" + suffix; //$NON-NLS-1$
397402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				break;
398402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			case 3:
399402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				this.name = "M" + suffix; //$NON-NLS-1$
400402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				break;
401402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			default:
402402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				this.name = stream.readUTF();
403402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				break;
404402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
405402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
406402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	int length = stream.readInt();
407402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	this.dimensions = new Dim[length];
408402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	this.average = new double[length];
409402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	this.stddev = new double[length];
410402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	this.count = new long[length];
411402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	for (int i=0; i<length; i++) {
412402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		int dimId = stream.readInt();
413402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		DB_Results.storeDimension(dimId);
414402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		this.dimensions[i] = (Dim) PerformanceTestPlugin.getDimension(dimId);
415402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		this.average[i] = stream.readLong();
416402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		this.count[i] = stream.readLong();
417402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		this.stddev[i] = stream.readDouble();
418402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
419402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	this.id = DB_Results.getBuildId(this.name);
420402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
421402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// read summary
422402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	this.summaryKind = stream.readInt();
423402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
424402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// read comment
425402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	String str = stream.readUTF();
426402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (str.length() > 0) {
427402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		this.comment = str;
428402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
429402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
430402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
431402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/*
432402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Set the build summary and its associated comment.
433402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
434402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollvoid setComment(String comment) {
435402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (comment != null && this.comment == null) {
436402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		this.comment = comment;
437402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
438402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
439402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
440402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/*
441402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Set the build summary and its associated comment.
442402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
443402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollvoid setSummary(int kind, String comment) {
444402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	this.comment = comment;
445402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	this.summaryKind = kind;
446402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
447402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
448402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/*
449402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Set the build failure.
450402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
451402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollvoid setFailure(String failure) {
452402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	this.failure = failure;
453402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
454402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
455402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/*
456402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Set the build value from database information.
457402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
458402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollvoid setValue(int dim_id, int step, long value) {
459402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	int length = DB_Results.getDimensions().length;
460402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	Dim dimension = (Dim) PerformanceTestPlugin.getDimension(dim_id);
461402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	int idx = 0;
462402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (this.dimensions == null){
463402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		this.dimensions = new Dim[length];
464402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		this.average = new double[length];
465402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		this.stddev = new double[length];
466402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		this.count = new long[length];
467402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		this.dimensions[0] = dimension;
468402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		for (int i=0; i<length; i++) {
469402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			// init average numbers with an impossible value
470402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			// to clearly identify whether it's already set or not
471402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			// when several measures are made for the same build
472402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			this.average[i] = IMPOSSIBLE_VALUE;
473402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
474402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	} else {
475402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		length = this.dimensions.length;
476402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		for (int i=0; i<length; i++) {
477402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			if (this.dimensions[i] == null) {
478402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				this.dimensions[i] = dimension;
479402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				idx = i;
480402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				break;
481402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			}
482402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			if (this.dimensions[i].getId() == dim_id) {
483402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				idx = i;
484402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				break;
485402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			}
486402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
487402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
488402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	switch (step) {
489402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		case InternalPerformanceMeter.AVERAGE:
490402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			if (this.average[idx] != IMPOSSIBLE_VALUE) {
491402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				if (this.values == null) {
492402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll					this.values = new double[length][];
493402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll					this.values[idx] = new double[2];
494402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll					this.values[idx][0] = this.average[idx];
495402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll					this.values[idx][1] = value;
496402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll					this.average[idx] = IMPOSSIBLE_VALUE;
497402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				} else if (this.values[idx] == null) {
498402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll					this.values[idx] = new double[2];
499402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll					this.values[idx][0] = this.average[idx];
500402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll					this.values[idx][1] = value;
501402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll					this.average[idx] = IMPOSSIBLE_VALUE;
502402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				}
503402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			} else if (this.values != null && this.values[idx] != null) {
504402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				int vLength = this.values[idx].length;
505402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				System.arraycopy(this.values[idx], 0, this.values[idx] = new double[vLength+1], 0, vLength);
506402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				this.values[idx][vLength] = value;
507402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			} else {
508402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				this.average[idx] = value;
509402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			}
510402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			break;
511402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		case InternalPerformanceMeter.STDEV:
512402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			this.stddev[idx] += Double.longBitsToDouble(value);
513402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			break;
514402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		case InternalPerformanceMeter.SIZE:
515402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			this.count[idx] += value;
516402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			break;
517402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
518402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
519402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
520402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/* (non-Javadoc)
521402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * @see org.eclipse.test.internal.performance.results.AbstractResults#toString()
522402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
523402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollpublic String toString() {
524402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	StringBuffer buffer = new StringBuffer(this.name);
525402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	buffer.append(": "); //$NON-NLS-1$
526402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	int length = this.dimensions.length;
527402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	for (int i=0; i<length; i++) {
528402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		if (i>0)	buffer.append(", "); //$NON-NLS-1$
529402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		buffer.append('[');
530402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		buffer.append(this.dimensions[i].getId());
531402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		buffer.append("]="); //$NON-NLS-1$
532402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		buffer.append(this.average[i]);
533402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		buffer.append('/');
534402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		buffer.append(this.count[i]);
535402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		buffer.append('/');
536402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		buffer.append(Math.round(this.stddev[i]*1000)/1000.0);
537402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
538402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	return buffer.toString();
539402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
540402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
541402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll/*
542402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll * Write the build results data in the given stream.
543402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll */
544402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Mollvoid write(DataOutputStream stream) throws IOException {
545402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	long timeBuild = -1;
546402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    try {
547402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	    timeBuild = Long.parseLong(getDate());
548402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    } catch (NumberFormatException nfe) {
549402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	    // do nothing
550402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    	nfe.printStackTrace();
551402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll    }
552402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	stream.writeLong(timeBuild);
553402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	byte kind = 0; // baseline
554402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (!this.baseline) {
555402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		switch (this.name.charAt(0)) {
556402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			case 'N':
557402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				kind = 1;
558402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				break;
559402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			case 'I':
560402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				kind = 2;
561402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				break;
562402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			case 'M':
563402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				kind = 3;
564402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				break;
565402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll			default:
566402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				kind = 4;
567402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll				break;
568402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		}
569402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
570402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	stream.writeByte(kind);
571402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	if (kind == 4) {
572402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		stream.writeUTF(this.name);
573402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
574402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	int length = this.dimensions == null ? 0 : this.dimensions.length;
575402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	stream.writeInt(length);
576402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	for (int i=0; i<length; i++) {
577402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		stream.writeInt(this.dimensions[i].getId());
578402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		stream.writeLong((long)this.average[i]) ;
579402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		stream.writeLong(this.count[i]);
580402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll		stream.writeDouble(this.stddev[i]);
581402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	}
582402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
583402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	// Write extra infos (summary, failure and comment)
584402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	stream.writeInt(this.summaryKind);
585402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll	stream.writeUTF(this.comment == null ? "" : this.comment) ; //$NON-NLS-1$
586402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
587402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll
588402794e73aed8611d62eb4b01cd155e2d76fcb87Raphael Moll}
589