<commit_before>package com.dianping.cat.report.page.monitor;

import java.io.IOException;

import javax.servlet.ServletException;

import org.unidal.lookup.annotation.Inject;
import org.unidal.web.mvc.PageHandler;
import org.unidal.web.mvc.annotation.InboundActionMeta;
import org.unidal.web.mvc.annotation.OutboundActionMeta;
import org.unidal.web.mvc.annotation.PayloadMeta;

import com.dianping.cat.Cat;
import com.dianping.cat.message.Message;
import com.dianping.cat.message.Metric;
import com.dianping.cat.message.Transaction;
import com.dianping.cat.message.internal.DefaultMetric;
import com.dianping.cat.message.internal.DefaultTransaction;
import com.dianping.cat.message.spi.MessageTree;
import com.dianping.cat.report.ReportPage;
import com.dianping.cat.report.page.JsonBuilder;
import com.dianping.cat.report.task.alert.MetricType;
import com.site.lookup.util.StringUtils;

public class Handler implements PageHandler<Context> {
	@Inject
	private JspViewer m_jspViewer;

	@Inject
	private JsonBuilder m_builder;

	private void buildBatchMetric(String content) {
		String[] lines = content.split("\n");

		// group, domain, key, type, time, value
		for (String line : lines) {
			String[] tabs = line.split("\t");

			if (tabs.length >= 6) {
				try {
					String group = tabs[0];
					String domain = tabs[1];
					String key = tabs[2];
					String type = tabs[3];
					long time = Long.parseLong(tabs[4]);
					double value = Double.parseDouble(tabs[5]);
					buildMetric(group, domain, key, type, time, value);
				} catch (Exception e) {
					Cat.logError("Unrecognized batch data: " + line, e);
				}
			} else {
				Cat.logError(new RuntimeException("Unrecognized batch data: " + line));
			}
		}
	}

	private Metric buildMetric(Payload payload, String type, double value) {
		String group = payload.getGroup();
		String domain = payload.getDomain();
		String key = payload.getKey();
		long time = payload.getTimestamp();

		return buildMetric(group, domain, key, type, time, value);

	}

	private Metric buildMetric(String group, String domain, String key, String type, long time, double value) {
		Metric metric = Cat.getProducer().newMetric(group, key);
		DefaultMetric defaultMetric = (DefaultMetric) metric;

		if (defaultMetric != null) {
			defaultMetric.setTimestamp(time);
			if (MetricType.SUM.name().equalsIgnoreCase(type)) {
				defaultMetric.setStatus("S,C");
				defaultMetric.addData(String.format("%s,%.2f", 1, value));
			} else if (MetricType.AVG.name().equalsIgnoreCase(type)) {
				defaultMetric.setStatus("T");
				defaultMetric.addData(String.format("%.2f", value));
			} else if (MetricType.AVG.name().equalsIgnoreCase(type)) {
				defaultMetric.setStatus("C");
				defaultMetric.addData(String.valueOf(value));
			}
		}

		MessageTree tree = Cat.getManager().getThreadLocalMessageTree();
		Message message = tree.getMessage();

		if (message instanceof Transaction) {
			((DefaultTransaction) message).setTimestamp(time);
		}
		return defaultMetric;
	}

	public HttpStatus checkPars(Payload payload) {<commit_msg>modify the handler<commit_after>package com.dianping.cat.report.page.monitor;

import java.io.IOException;

import javax.servlet.ServletException;

import org.unidal.lookup.annotation.Inject;
import org.unidal.web.mvc.PageHandler;
import org.unidal.web.mvc.annotation.InboundActionMeta;
import org.unidal.web.mvc.annotation.OutboundActionMeta;
import org.unidal.web.mvc.annotation.PayloadMeta;

import com.dianping.cat.Cat;
import com.dianping.cat.message.Message;
import com.dianping.cat.message.Metric;
import com.dianping.cat.message.Transaction;
import com.dianping.cat.message.internal.DefaultMetric;
import com.dianping.cat.message.internal.DefaultTransaction;
import com.dianping.cat.message.spi.MessageTree;
import com.dianping.cat.report.ReportPage;
import com.dianping.cat.report.page.JsonBuilder;
import com.dianping.cat.report.task.alert.MetricType;
import com.site.lookup.util.StringUtils;

public class Handler implements PageHandler<Context> {
	@Inject
	private JspViewer m_jspViewer;

	@Inject
	private JsonBuilder m_builder;

	private void buildBatchMetric(String content) {
		String[] lines = content.split("\n");

		// group, domain, key, type, time, value
		for (String line : lines) {
			String[] tabs = line.split("\t");

			if (tabs.length >= 6) {
				try {
					String group = tabs[0];
					String domain = tabs[1];
					String key = tabs[2];
					String type = tabs[3];
					long time = Long.parseLong(tabs[4]);
					double value = Double.parseDouble(tabs[5]);
					buildMetric(group, domain, key, type, time, value);
				} catch (Exception e) {
					Cat.logError("Unrecognized batch data: " + line, e);
				}
			} else {
				Cat.logError(new RuntimeException("Unrecognized batch data: " + line));
			}
		}
	}

	private Metric buildMetric(Payload payload, String type, double value) {
		String group = payload.getGroup();
		String domain = payload.getDomain();
		String key = payload.getKey();
		long time = payload.getTimestamp();

		return buildMetric(group, domain, key, type, time, value);
	}

	private Metric buildMetric(String group, String domain, String key, String type, long time, double value) {
		Metric metric = Cat.getProducer().newMetric(group, key);
		DefaultMetric defaultMetric = (DefaultMetric) metric;

		if (defaultMetric != null) {
			defaultMetric.setTimestamp(time);
			if (MetricType.SUM.name().equalsIgnoreCase(type)) {
				defaultMetric.setStatus("S,C");
				defaultMetric.addData(String.format("%s,%.2f", 1, value));
			} else if (MetricType.AVG.name().equalsIgnoreCase(type)) {
				defaultMetric.setStatus("T");
				defaultMetric.addData(String.format("%.2f", value));
			} else if (MetricType.AVG.name().equalsIgnoreCase(type)) {
				defaultMetric.setStatus("C");
				defaultMetric.addData(String.valueOf(value));
			}
		}

		MessageTree tree = Cat.getManager().getThreadLocalMessageTree();
		Message message = tree.getMessage();

		if (message instanceof Transaction) {
			((DefaultTransaction) message).setTimestamp(time);
		}
		return defaultMetric;
	}

	public HttpStatus checkPars(Payload payload) {
{'fraction_non_alphanumeric': 0.13052011776251227, 'fraction_numerical': 0.0032711808963035655, 'mean_word_length': 4.5590909090909095, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '3958118', 'n_tokens_mistral': 2125, 'n_tokens_neox': 1889, 'n_words': 404}