<commit_before>package org.metaborg.spoofax.benchmark.core.export;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.Field;
import java.util.Map;

import org.apache.commons.io.FileUtils;
import org.metaborg.spoofax.benchmark.core.process.ProcessedData;

import com.google.common.collect.Maps;

public final class CSVExporter {
	public void export(ProcessedData data, File directory) throws IOException, IllegalArgumentException,
		IllegalAccessException {
		FileUtils.forceMkdir(directory);
		
		writeCSV(data.time, new File(directory, "time.csv"));
		writeCSV(data.index, new File(directory, "index.csv"));
		writeCSV(data.taskEngine, new File(directory, "taskengine.csv"));
	}

	private void writeCSV(Object object, File file) throws IllegalArgumentException, IllegalAccessException,
		IOException {
		final Map<String, Object> values = Maps.newLinkedHashMap();
		for(Field field : object.getClass().getFields()) {
			final Class<?> type = field.getType();
			if(type.equals(long.class))
				values.put(field.getName(), field.getLong(object));
			else if(type.equals(double.class))
				values.put(field.getName(), field.getDouble(object));
		}<commit_msg>Export index and task engine kind metrics.<commit_after>package org.metaborg.spoofax.benchmark.core.export;

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.Field;
import java.util.Map;

import org.apache.commons.io.FileUtils;
import org.metaborg.spoofax.benchmark.core.process.ProcessedData;

import com.google.common.collect.Maps;
import com.google.common.collect.Multiset;
import com.google.common.collect.Multiset.Entry;

public final class CSVExporter {
	public void export(ProcessedData data, File directory) throws IOException, IllegalArgumentException,
		IllegalAccessException {
		FileUtils.forceMkdir(directory);
		
		writeCSVPrims(data.time, new File(directory, "time.csv"));
		writeCSVPrims(data.index, new File(directory, "index.csv"));
		writeCSVMultiset(data.index.numKinds, new File(directory, "index-kinds.csv"));
		writeCSVPrims(data.taskEngine, new File(directory, "taskengine.csv"));
		writeCSVMultiset(data.taskEngine.numKinds, new File(directory, "taskengine-kinds.csv"));
	}

	private void writeCSVPrims(Object object, File file) throws IllegalArgumentException, IllegalAccessException,
		IOException {
		final Map<String, Object> values = Maps.newLinkedHashMap();
		for(Field field : object.getClass().getFields()) {
			final Class<?> type = field.getType();
			if(type.equals(long.class))
				values.put(field.getName(), field.getLong(object));
			else if(type.equals(double.class))
				values.put(field.getName(), field.getDouble(object));
		}
		writeCSV(values, file);
	}
	
	private void writeCSVMultiset(Multiset<String> multiset, File file) throws IOException {
		final Map<String, Object> values = Maps.newLinkedHashMap();
		for(Entry<String> entry : multiset.entrySet()) {
			values.put(entry.getElement(), entry.getCount());
		}
{'fraction_non_alphanumeric': 0.12764550264550265, 'fraction_numerical': 0.0, 'mean_word_length': 5.797752808988764, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, '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': '3321795', 'n_tokens_mistral': 999, 'n_tokens_neox': 929, 'n_words': 186}