<commit_before>package net.anotheria.moskito.webui.gauges.api;

import net.anotheria.anoplass.api.APIException;
import net.anotheria.anoplass.api.APIInitException;
import net.anotheria.moskito.core.config.MoskitoConfigurationHolder;
import net.anotheria.moskito.core.config.gauges.GaugeConfig;
import net.anotheria.moskito.core.config.gauges.GaugeValueConfig;
import net.anotheria.moskito.core.config.gauges.GaugesConfig;
import net.anotheria.moskito.core.producers.IStats;
import net.anotheria.moskito.core.producers.IStatsProducer;
import net.anotheria.moskito.core.registry.IProducerRegistryAPI;
import net.anotheria.moskito.core.registry.ProducerRegistryAPIFactory;
import net.anotheria.moskito.core.stats.TimeUnit;
import net.anotheria.moskito.webui.producers.api.LongValueAO;
import net.anotheria.moskito.webui.producers.api.StatValueAO;
import net.anotheria.moskito.webui.producers.api.StringValueAO;
import net.anotheria.moskito.webui.shared.api.AbstractMoskitoAPIImpl;

import java.util.LinkedList;
import java.util.List;

/**
 * Gauge api implementation.
 *
 * @author lrosenberg
 * @since 25.03.15 11:41
 */
public class GaugeAPIImpl extends AbstractMoskitoAPIImpl implements GaugeAPI {

	private IProducerRegistryAPI producerRegistryAPI;

	@Override
	public void init() throws APIInitException {
		super.init();
		producerRegistryAPI = new ProducerRegistryAPIFactory().createProducerRegistryAPI();
	}

	public List<GaugeAO> getGauges(){
		GaugesConfig gg = MoskitoConfigurationHolder.getConfiguration().getGaugesConfig();
		List<GaugeAO> gaugeAOList = new LinkedList<GaugeAO>();
		for (GaugeConfig g : gg.getGauges()){
			GaugeAO ao = createGaugeAO(g);
			gaugeAOList.add(ao);
		}
		return gaugeAOList;
	}

	@Override
	public List<GaugeAO> getGauges(String... names) throws APIException {
		if (names==null)
			throw new APIException("Unexpected parameter null for gauge names");

		LinkedList<GaugeAO> ret = new LinkedList<GaugeAO>();
		for (String name : names){
			GaugeConfig config = getGaugeConfigByName(name);
			ret.add(createGaugeAO(config));
		}
		return ret;
	}

	private GaugeConfig getGaugeConfigByName(String name) throws APIException{
		GaugesConfig gg = MoskitoConfigurationHolder.getConfiguration().getGaugesConfig();
		for (GaugeConfig g : gg.getGauges()){
			if (g.getName().equals(name))
				return g;
		}
		throw new APIException("Can't find gauge configuration for '"+name+"'");

	}

	private GaugeAO createGaugeAO(GaugeConfig fromConfig){

		GaugeAO ao = new GaugeAO();
		ao.setName(fromConfig.getName());
		ao.setCaption(fromConfig.getCaption());
		boolean complete = true;
		StatValueAO current = gaugeValue2statValue(fromConfig.getCurrentValue());
		ao.setCurrent(current);
		StatValueAO min = gaugeValue2statValue(fromConfig.getMinValue());
		ao.setMin(min);
		StatValueAO max = gaugeValue2statValue(fromConfig.getMaxValue());
		ao.setMax(max);
		if (current instanceof StringValueAO ||
				min instanceof StringValueAO ||
				max instanceof StringValueAO
				) {
			complete = false;
		}
		ao.setComplete(true);
		return ao;<commit_msg>fix complete<commit_after>package net.anotheria.moskito.webui.gauges.api;

import net.anotheria.anoplass.api.APIException;
import net.anotheria.anoplass.api.APIInitException;
import net.anotheria.moskito.core.config.MoskitoConfigurationHolder;
import net.anotheria.moskito.core.config.gauges.GaugeConfig;
import net.anotheria.moskito.core.config.gauges.GaugeValueConfig;
import net.anotheria.moskito.core.config.gauges.GaugesConfig;
import net.anotheria.moskito.core.producers.IStats;
import net.anotheria.moskito.core.producers.IStatsProducer;
import net.anotheria.moskito.core.registry.IProducerRegistryAPI;
import net.anotheria.moskito.core.registry.ProducerRegistryAPIFactory;
import net.anotheria.moskito.core.stats.TimeUnit;
import net.anotheria.moskito.webui.producers.api.LongValueAO;
import net.anotheria.moskito.webui.producers.api.StatValueAO;
import net.anotheria.moskito.webui.producers.api.StringValueAO;
import net.anotheria.moskito.webui.shared.api.AbstractMoskitoAPIImpl;

import java.util.LinkedList;
import java.util.List;

/**
 * Gauge api implementation.
 *
 * @author lrosenberg
 * @since 25.03.15 11:41
 */
public class GaugeAPIImpl extends AbstractMoskitoAPIImpl implements GaugeAPI {

	private IProducerRegistryAPI producerRegistryAPI;

	@Override
	public void init() throws APIInitException {
		super.init();
		producerRegistryAPI = new ProducerRegistryAPIFactory().createProducerRegistryAPI();
	}

	public List<GaugeAO> getGauges(){
		GaugesConfig gg = MoskitoConfigurationHolder.getConfiguration().getGaugesConfig();
		List<GaugeAO> gaugeAOList = new LinkedList<GaugeAO>();
		for (GaugeConfig g : gg.getGauges()){
			GaugeAO ao = createGaugeAO(g);
			gaugeAOList.add(ao);
		}
		return gaugeAOList;
	}

	@Override
	public List<GaugeAO> getGauges(String... names) throws APIException {
		if (names==null)
			throw new APIException("Unexpected parameter null for gauge names");

		LinkedList<GaugeAO> ret = new LinkedList<GaugeAO>();
		for (String name : names){
			GaugeConfig config = getGaugeConfigByName(name);
			ret.add(createGaugeAO(config));
		}
		return ret;
	}

	private GaugeConfig getGaugeConfigByName(String name) throws APIException{
		GaugesConfig gg = MoskitoConfigurationHolder.getConfiguration().getGaugesConfig();
		for (GaugeConfig g : gg.getGauges()){
			if (g.getName().equals(name))
				return g;
		}
		throw new APIException("Can't find gauge configuration for '"+name+"'");

	}

	private GaugeAO createGaugeAO(GaugeConfig fromConfig){

		GaugeAO ao = new GaugeAO();
		ao.setName(fromConfig.getName());
		ao.setCaption(fromConfig.getCaption());
		boolean complete = true;
		StatValueAO current = gaugeValue2statValue(fromConfig.getCurrentValue());
		ao.setCurrent(current);
		StatValueAO min = gaugeValue2statValue(fromConfig.getMinValue());
		ao.setMin(min);
		StatValueAO max = gaugeValue2statValue(fromConfig.getMaxValue());
		ao.setMax(max);
		if (current instanceof StringValueAO ||
				min instanceof StringValueAO ||
				max instanceof StringValueAO
				) {
			complete = false;
		}
		ao.setComplete(complete);
		return ao;
{'fraction_non_alphanumeric': 0.10950446791226645, 'fraction_numerical': 0.004224207961007311, 'mean_word_length': 5.647948164146868, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '380141', 'n_tokens_mistral': 2262, 'n_tokens_neox': 2064, 'n_words': 360}