<commit_before>/* 
* OpenSpeedMonitor (OSM)
* Copyright 2014 iteratec GmbH
* 
* Licensed under the Apache License, Version 2.0 (the "License"); 
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 
* 	http://www.apache.org/licenses/LICENSE-2.0
* 
* Unless required by applicable law or agreed to in writing, software 
* distributed under the License is distributed on an "AS IS" BASIS, 
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
* See the License for the specific language governing permissions and 
* limitations under the License.
*/

package de.iteratec.osm.result

import de.iteratec.osm.measurement.schedule.ConnectivityProfile
import de.iteratec.osm.measurement.schedule.Job
import de.iteratec.osm.result.detail.WebPerformanceWaterfall
import de.iteratec.osm.csi.OsmConfigCacheService
import de.iteratec.osm.csi.CsiValue


/**
 * The cache-setting a {@link EventResult result} is based on.
 * 
 * @author nkuhn
 */
public enum CachedView {
	/**
	 * A WPT repeated view result; could have used some data out of the 
	 * browsers cache.
	 */
	CACHED,
	
	/**
	 * A WPT first view result; the browsers cache have been cleared before, 
	 * all date was loaded from the web-server.
	 */
	UNCACHED;
	
	static transients = ['cached'];
	
	/**
	 * <p>
	 * Determines weather this cached-view-state is a cached state (repeated 
	 * view) or an un-cached state (first view).
	 * </p>
	 * 
	 * @return <code>true</code> if this is a cached state, 
	 *         <code>false</code> else.
	 */
	public boolean isCached()
	{
		return this == CACHED;
	}
}

/**
 * <p>
 * The results of one event in one and only one 
 * {@linkplain JobResult job-result}.
 * </p>
 * 
 * <p>
 * For job-results in WPT-multistep this is the result of one page-load
 * with its waterfall-data. It is assigned to one and only one job-result 
 * and grouped by a {@link MeasuredEvent}.
 * An event-result could be a cached (repeated view) or un-cached (first view)
 * execution (see {#cachedView}).
 * </p>
 * 
 * @author nkuhn
 * @author mze
 * @see JobResult
 */
class EventResult implements CsiValue {

	public static String TEST_DETAILS_STATIC_URL = "details.php?test={testid}&run={wptRun}&cached={cachedType}";

	OsmConfigCacheService osmConfigCacheService

	Long id
	Date dateCreated
	Date lastUpdated
	URL testDetailsWaterfallURL

	MeasuredEvent measuredEvent

	/** number of the run in wpt */
	Integer numberOfWptRun
	CachedView cachedView
	/** whether this result's doc-ready-time is the median time of all runs (if this jobrun includes just one run allways true) */
	Boolean medianValue
	Integer wptStatus

	Integer docCompleteIncomingBytes
	Integer docCompleteRequests
	Integer docCompleteTimeInMillisecs
	Integer domTimeInMillisecs
	Integer firstByteInMillisecs
	Integer fullyLoadedIncomingBytes
	Integer fullyLoadedRequestCount
	Integer fullyLoadedTimeInMillisecs
	Integer loadTimeInMillisecs
	Integer startRenderInMillisecs
	Double customerSatisfactionInPercent

	/**
	 * The WPT speed index received from WPT server.
	 *
	 * If value is not available please assign 
	 * {@link #SPEED_INDEX_DEFAULT_VALUE}.
	 *
	 * Never <code>null</code>.
	 */
	Integer speedIndex
	Integer visuallyCompleteInMillisecs
    /** tester from result xml */
    String testAgent

	/**
	 * This is value is to be used for {@link #speedIndex} if no value is
	 * available.
	 *
	 * @since IT-223
	 */
	public static final Integer SPEED_INDEX_DEFAULT_VALUE = -1;

	Integer downloadAttempts
	Date firstStatusUpdate
	Date lastStatusUpdate
	String validationState
	String tag
	WebPerformanceWaterfall webPerformanceWaterfall

	// from JobResult 
	Date jobResultDate
	Long jobResultJobConfigId

	/**
	 * These values are to be used to distinguish results according to their connectivities
	 *
	 * @since IT-643
	 */
	ConnectivityProfile connectivityProfile;

	// For reasons of performance is this just a string
	String customConnectivityName;

	//static belongsTo = JobResult
	static belongsTo = [jobResult: JobResult]

	static constraints = {
		id()
		measuredEvent(nullable: true) // FIXME mze-2013-07-30: CAHNGE IMMEDIATELLY to never be null!
		wptStatus()
		medianValue()
		numberOfWptRun()
		cachedView()
		testDetailsWaterfallURL(nullable: true)

		docCompleteIncomingBytes(nullable: true)
		docCompleteRequests(nullable: true)
		docCompleteTimeInMillisecs(nullable: true)
		domTimeInMillisecs(nullable: true)
		firstByteInMillisecs(nullable: true)
		fullyLoadedIncomingBytes(nullable: true)
		fullyLoadedRequestCount(nullable: true)
		fullyLoadedTimeInMillisecs(nullable: true)
		loadTimeInMillisecs(nullable: true)
		startRenderInMillisecs(nullable: true)
		customerSatisfactionInPercent(nullable: true)
		speedIndex()
		visuallyCompleteInMillisecs(nullable: true)

		downloadAttempts(nullable: true)
		firstStatusUpdate(nullable: true)
		lastStatusUpdate(nullable: true)
		validationState(nullable: true)

		// from JobResult
		jobResultDate()
		jobResultJobConfigId()

		tag(nullable: true)
		webPerformanceWaterfall(nullable: true)

        testAgent(nullable: true)

		connectivityProfile(nullable: true, validator: { connectivityProfileobj && !customConnectivityName })
		customConnectivityName(nullable: true, validator: { customConnectivityName && !connectivityProfile  })
	}

	static mapping = {
		jobResultDate(index: 'jobResultDate_and_jobResultJobConfigId_idx,wJRD_and_wJRJCId_and_mV_and_cV_idx')
		jobResultJobConfigId(index: 'jobResultDate_and_jobResultJobConfigId_idx,wJRD_and_wJRJCId_and_mV_and_cV_idx')
		medianValue(index: 'wJRD_and_wJRJCId_and_mV_and_cV_idx')
		cachedView(index: 'wJRD_and_wJRJCId_and_mV_and_cV_idx')
		tag(index: 'EventResultTagIndex')


		jobResultDate(index: 'GetLimitedMedianEventResultsBy')
		tag(index: 'GetLimitedMedianEventResultsBy')
		medianValue(index: 'GetLimitedMedianEventResultsBy')
		cachedView(index: 'GetLimitedMedianEventResultsBy')
	}<commit_msg>Added constraints for eventresults<commit_after>/* 
* OpenSpeedMonitor (OSM)
* Copyright 2014 iteratec GmbH
* 
* Licensed under the Apache License, Version 2.0 (the "License"); 
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 
* 	http://www.apache.org/licenses/LICENSE-2.0
* 
* Unless required by applicable law or agreed to in writing, software 
* distributed under the License is distributed on an "AS IS" BASIS, 
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
* See the License for the specific language governing permissions and 
* limitations under the License.
*/

package de.iteratec.osm.result

import de.iteratec.osm.measurement.schedule.ConnectivityProfile
import de.iteratec.osm.measurement.schedule.Job
import de.iteratec.osm.result.detail.WebPerformanceWaterfall
import de.iteratec.osm.csi.OsmConfigCacheService
import de.iteratec.osm.csi.CsiValue


/**
 * The cache-setting a {@link EventResult result} is based on.
 * 
 * @author nkuhn
 */
public enum CachedView {
	/**
	 * A WPT repeated view result; could have used some data out of the 
	 * browsers cache.
	 */
	CACHED,
	
	/**
	 * A WPT first view result; the browsers cache have been cleared before, 
	 * all date was loaded from the web-server.
	 */
	UNCACHED;
	
	static transients = ['cached'];
	
	/**
	 * <p>
	 * Determines weather this cached-view-state is a cached state (repeated 
	 * view) or an un-cached state (first view).
	 * </p>
	 * 
	 * @return <code>true</code> if this is a cached state, 
	 *         <code>false</code> else.
	 */
	public boolean isCached()
	{
		return this == CACHED;
	}
}

/**
 * <p>
 * The results of one event in one and only one 
 * {@linkplain JobResult job-result}.
 * </p>
 * 
 * <p>
 * For job-results in WPT-multistep this is the result of one page-load
 * with its waterfall-data. It is assigned to one and only one job-result 
 * and grouped by a {@link MeasuredEvent}.
 * An event-result could be a cached (repeated view) or un-cached (first view)
 * execution (see {#cachedView}).
 * </p>
 * 
 * @author nkuhn
 * @author mze
 * @see JobResult
 */
class EventResult implements CsiValue {

	public static String TEST_DETAILS_STATIC_URL = "details.php?test={testid}&run={wptRun}&cached={cachedType}";

	OsmConfigCacheService osmConfigCacheService

	Long id
	Date dateCreated
	Date lastUpdated
	URL testDetailsWaterfallURL

	MeasuredEvent measuredEvent

	/** number of the run in wpt */
	Integer numberOfWptRun
	CachedView cachedView
	/** whether this result's doc-ready-time is the median time of all runs (if this jobrun includes just one run allways true) */
	Boolean medianValue
	Integer wptStatus

	Integer docCompleteIncomingBytes
	Integer docCompleteRequests
	Integer docCompleteTimeInMillisecs
	Integer domTimeInMillisecs
	Integer firstByteInMillisecs
	Integer fullyLoadedIncomingBytes
	Integer fullyLoadedRequestCount
	Integer fullyLoadedTimeInMillisecs
	Integer loadTimeInMillisecs
	Integer startRenderInMillisecs
	Double customerSatisfactionInPercent

	/**
	 * The WPT speed index received from WPT server.
	 *
	 * If value is not available please assign 
	 * {@link #SPEED_INDEX_DEFAULT_VALUE}.
	 *
	 * Never <code>null</code>.
	 */
	Integer speedIndex
	Integer visuallyCompleteInMillisecs
    /** tester from result xml */
    String testAgent

	/**
	 * This is value is to be used for {@link #speedIndex} if no value is
	 * available.
	 *
	 * @since IT-223
	 */
	public static final Integer SPEED_INDEX_DEFAULT_VALUE = -1;

	Integer downloadAttempts
	Date firstStatusUpdate
	Date lastStatusUpdate
	String validationState
	String tag
	WebPerformanceWaterfall webPerformanceWaterfall

	// from JobResult 
	Date jobResultDate
	Long jobResultJobConfigId

	/**
	 * These values are to be used to distinguish results according to their connectivities
	 *
	 * @since IT-643
	 */
	ConnectivityProfile connectivityProfile;

	// For reasons of performance is this just a string
	String customConnectivityName;

	//static belongsTo = JobResult
	static belongsTo = [jobResult: JobResult]

	static constraints = {
		id()
		measuredEvent(nullable: true) // FIXME mze-2013-07-30: CAHNGE IMMEDIATELLY to never be null!
		wptStatus()
		medianValue()
		numberOfWptRun()
		cachedView()
		testDetailsWaterfallURL(nullable: true)

		docCompleteIncomingBytes(nullable: true)
		docCompleteRequests(nullable: true)
		docCompleteTimeInMillisecs(nullable: true)
		domTimeInMillisecs(nullable: true)
		firstByteInMillisecs(nullable: true)
		fullyLoadedIncomingBytes(nullable: true)
		fullyLoadedRequestCount(nullable: true)
		fullyLoadedTimeInMillisecs(nullable: true)
		loadTimeInMillisecs(nullable: true)
		startRenderInMillisecs(nullable: true)
		customerSatisfactionInPercent(nullable: true)
		speedIndex()
		visuallyCompleteInMillisecs(nullable: true)

		downloadAttempts(nullable: true)
		firstStatusUpdate(nullable: true)
		lastStatusUpdate(nullable: true)
		validationState(nullable: true)

		// from JobResult
		jobResultDate()
		jobResultJobConfigId()

		tag(nullable: true)
		webPerformanceWaterfall(nullable: true)

        testAgent(nullable: true)

		connectivityProfile(nullable: true, validator: { val, obj -> return (val == null && obj.customConnectivityName != null) || (val != null) })
		customConnectivityName(nullable: true, validator: { val, obj -> (val == null && obj.connectivityProfile != null) || (val != null) })
	}

	static mapping = {
		jobResultDate(index: 'jobResultDate_and_jobResultJobConfigId_idx,wJRD_and_wJRJCId_and_mV_and_cV_idx')
		jobResultJobConfigId(index: 'jobResultDate_and_jobResultJobConfigId_idx,wJRD_and_wJRJCId_and_mV_and_cV_idx')
		medianValue(index: 'wJRD_and_wJRJCId_and_mV_and_cV_idx')
		cachedView(index: 'wJRD_and_wJRJCId_and_mV_and_cV_idx')
		tag(index: 'EventResultTagIndex')


		jobResultDate(index: 'GetLimitedMedianEventResultsBy')
		tag(index: 'GetLimitedMedianEventResultsBy')
		medianValue(index: 'GetLimitedMedianEventResultsBy')
		cachedView(index: 'GetLimitedMedianEventResultsBy')
	}
{'fraction_non_alphanumeric': 0.08371550070874677, 'fraction_numerical': 0.0038355707496039357, 'mean_word_length': 4.657547169811321, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6985222', 'n_tokens_mistral': 3963, 'n_tokens_neox': 3668, 'n_words': 1066}