All Downloads are FREE. Search and download functionalities are using the official Maven repository.

step.plugins.views.functions.ErrorRateView Maven / Gradle / Ivy

There is a newer version: 3.27.0
Show newest version
/*******************************************************************************
 * Copyright (C) 2020, exense GmbH
 *  
 * This file is part of STEP
 *  
 * STEP is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *  
 * STEP is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *  
 * You should have received a copy of the GNU Affero General Public License
 * along with STEP.  If not, see .
 ******************************************************************************/
package step.plugins.views.functions;

import step.core.artefacts.reports.ReportNode;
import step.core.views.View;

import java.util.Map.Entry;

@View
public class ErrorRateView extends AbstractTimeBasedView {

	@Override
	public void afterReportNodeSkeletonCreation(AbstractTimeBasedModel model, ReportNode node) {}

	@Override
	public void beforeReportNodeExecution(AbstractTimeBasedModel model, ReportNode node) {	}

	private ErrorRateEntry createPoint(ReportNode node) {
		ErrorRateEntry e = null;
		if(node.getError()!=null) {
			e = new ErrorRateEntry();
			e.count = 1;
			e.countByErrorMsg.put(node.getError().getMsg()==null?"":node.getError().getMsg(), 1);
		}
		return e;
	}

	@Override
	public void afterReportNodeExecution(AbstractTimeBasedModel model, ReportNode node) {
		ErrorRateEntry e = createPoint(node);
		if (e != null) {
			addPoint(model, node.getExecutionTime(), e);
		}
	}
	
	@Override
	protected void mergePoints(ErrorRateEntry target, ErrorRateEntry source) {
		target.count+=source.count;
		for(Entry e:source.countByErrorMsg.entrySet()) {
			Integer count = target.countByErrorMsg.get(e.getKey());
			if(count==null) {
				count = e.getValue();
			} else {
				count = count+e.getValue();
			}
			target.countByErrorMsg.put(e.getKey(), count);
		}
	}

	@Override
	public String getViewId() {
		return "ErrorRate";
	}

	@Override
	public void onReportNodeRemoval(AbstractTimeBasedModel model, ReportNode node) {
		removeErrorPointIfAny(model, node);
	}

	private void removeErrorPointIfAny(AbstractTimeBasedModel model, ReportNode node) {
		ErrorRateEntry e = createPoint(node);
		if (e != null) {
			removePoint(model, node.getExecutionTime(), e);
		}
	}

	@Override
	public void onErrorContributionRemoval(AbstractTimeBasedModel model, ReportNode node) {
		removeErrorPointIfAny(model, node);
	}

	@Override
	protected void unMergePoints(ErrorRateEntry target, ErrorRateEntry source) {
		target.count-=source.count;
		for(Entry e:source.countByErrorMsg.entrySet()) {
			Integer count = target.countByErrorMsg.get(e.getKey());
			if(count!=null) {
				count = count-e.getValue();
				target.countByErrorMsg.put(e.getKey(), count);
			}
			
		}
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy