<commit_before>package satori.type;

import satori.common.SAssert;

public enum STimeType implements SType {
	INSTANCE;
	
	@Override public boolean isValid(Object obj) {
		try { getRaw(obj); }
		catch(STypeException ex) { return false; }
		return true;
	}
	@Override public Object getRaw(Object obj) throws STypeException {
		if (obj == null) return null;
		SAssert.assertTrue(obj instanceof String, "Incorrect argument type");
		String str = (String)obj;
		if (str.endsWith("s")) {
			double time;
			try { time = Double.valueOf(str.substring(0, str.length()-1))*1000.0; }
			catch(NumberFormatException ex) { throw new STypeException("Invalid format: " + str); }
			long rnd_time = Math.round(time);
			if (rnd_time != time) throw new STypeException("Invalid format: " + str);
			if (rnd_time <= 0) throw new STypeException("Invalid format: " + str);
			return String.valueOf(rnd_time);
		} else throw new STypeException("Invalid format: " + str);
	}
	@Override public Object getFormatted(Object obj) throws STypeException {
		if (obj == null) return null;
		SAssert.assertTrue(obj instanceof String, "Incorrect argument type");
		String str = (String)obj;
		long time;
		try { time = Long.valueOf(str); }
		catch(NumberFormatException ex) { throw new STypeException("Invalid attribute data: " + str); }
		if (time <= 0) throw new STypeException("Invalid attribute data: " + str);
		return String.valueOf(time*0.001) + "s";
	}
}<commit_msg>better time formatting<commit_after>package satori.type;

import java.text.DecimalFormat;

import satori.common.SAssert;

public enum STimeType implements SType {
	INSTANCE;
	
	private static final DecimalFormat fmt = new DecimalFormat("0.###");
	
	@Override public boolean isValid(Object obj) {
		try { getRaw(obj); }
		catch(STypeException ex) { return false; }
		return true;
	}
	@Override public Object getRaw(Object obj) throws STypeException {
		if (obj == null) return null;
		SAssert.assertTrue(obj instanceof String, "Incorrect argument type");
		String str = (String)obj;
		if (str.endsWith("s")) {
			double time;
			try { time = Double.valueOf(str.substring(0, str.length()-1))*1000.0; }
			catch(NumberFormatException ex) { throw new STypeException("Invalid format: " + str); }
			long rnd_time = Math.round(time);
			if (rnd_time != time) throw new STypeException("Invalid format: " + str);
			if (rnd_time <= 0) throw new STypeException("Invalid format: " + str);
			return String.valueOf(rnd_time);
		} else throw new STypeException("Invalid format: " + str);
	}
	@Override public Object getFormatted(Object obj) throws STypeException {
		if (obj == null) return null;
		SAssert.assertTrue(obj instanceof String, "Incorrect argument type");
		String str = (String)obj;
		long time;
		try { time = Long.valueOf(str); }
		catch(NumberFormatException ex) { throw new STypeException("Invalid attribute data: " + str); }
		if (time <= 0) throw new STypeException("Invalid attribute data: " + str);
		return fmt.format(time*0.001) + "s";
	}
}
{'fraction_non_alphanumeric': 0.12725450901803606, 'fraction_numerical': 0.009018036072144289, 'mean_word_length': 4.629699248120301, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '3623075', 'n_tokens_mistral': 1008, 'n_tokens_neox': 938, 'n_words': 275}