<commit_before>package rokclock;

import java.io.*;
import java.text.*;
import java.util.*;

/**
 * The analyser of the log files. It currently provides a summary for top-level
 * projects for a specified time period.
 */
public class Analyser {
	/**
	 * A platform-independent newline.
	 */
	private final String nl = System.getProperty("line.separator");

	/**
	 * The main method of this analyser, which is used for running it from the
	 * command prompt. As arguments, it expects the name of the log file,
	 * followed by the start date (inclusive) and the stop date (exclusive). The
	 * dates should have the "dd/MM/yyyy" format. The results are written to the
	 * standard output.
	 *
	 * @param args
	 *            The command-line arguments as specified above.
	 * @throws Exception
	 *             Thrown if the processing fails.
	 */
	public static void main(String[] args) throws Exception {
		if (args.length != 1 && args.length != 3) {
			System.err.println("Usage: java -cp bin rokclock.Analyser <logFilename> [<start date inclusive> <stop date exclusive>]");
			System.exit(1);
		}
		String logFilename = args[0];
		Date fromDate = null, toDate = null;
		String dfS = "dd/MM/yyyy";
		DateFormat df = new SimpleDateFormat(dfS);
		if (3 <= args.length)
			try {
				fromDate = df.parse(args[1]);
				toDate = df.parse(args[2]);
			} catch (ParseException e) {
				System.err.println("Dates should be specified in the following format: " + dfS);
				System.exit(1);
			}
		Analyser a = new Analyser();
		a.processLogFile(logFilename, fromDate, toDate);
		a.displayResults();
	}

	/**
	 * The field that maps top-level project names to the sum of milliseconds
	 * spent on them for a specified time period.
	 */
	private Map<String,Long> sums;
	/**
	 * The start of a specified time period.
	 */
	private Date fromDate;
	/**
	 * The end of a specified time period.
	 */
	private Date toDate;

	/**
	 * This method reads the specified log file for the specified time period.
	 * The processing of individual log entries is delegated to @
	 * #readLogEntry(String)} .
	 *
	 * @param logFilename
	 *            The name of the log file.
	 * @param fromDate
	 *            The start of the time period.
	 * @param toDate
	 *            The end of the time period.
	 * @return The resulting map of results.
	 * @throws IOException
	 *             Thrown if reading or parsing fails.
	 */
	Map<String,Long> processLogFile(String logFilename, Date fromDate, Date toDate) throws IOException {
		sums = new TreeMap<String,Long>();
		this.fromDate = fromDate;
		this.toDate = toDate;
		BufferedReader br = new BufferedReader(new FileReader(logFilename));
		String line;
		while ((line = br.readLine()) != null)
			readLogEntry(line);
		br.close();
		return sums;
	}

	/**
	 * Parses a single log entry. Fields should be separated by commas; any
	 * spaces around commas are ignored. If the first field is recognised as a
	 * date, the new log format (from,to,project,sub-project,...) is used;
	 * otherwise, the old log format (project,sub-project,from,to) is used. The
	 * recording of data is delegated to
	 * {@link #recordData(String, String, String, String)}.
	 *
	 * @param entry
	 *            A single log entry to process.
	 */
	private void readLogEntry(String entry) {
		String[] fields = entry.split("\\s*,\\s*");<commit_msg>Improved log analyser's error handling.<commit_after>package rokclock;

import java.io.*;
import java.text.*;
import java.util.*;

/**
 * The analyser of the log files. It currently provides a summary for top-level
 * projects for a specified time period.
 */
public class Analyser {
	/**
	 * A platform-independent newline.
	 */
	private final String nl = System.getProperty("line.separator");

	/**
	 * The main method of this analyser, which is used for running it from the
	 * command prompt. As arguments, it expects the name of the log file,
	 * followed by the start date (inclusive) and the stop date (exclusive). The
	 * dates should have the "dd/MM/yyyy" format. The results are written to the
	 * standard output.
	 *
	 * @param args
	 *            The command-line arguments as specified above.
	 * @throws Exception
	 *             Thrown if the processing fails.
	 */
	public static void main(String[] args) throws Exception {
		if (args.length != 1 && args.length != 3) {
			System.err.println("Usage: java -cp bin rokclock.Analyser <logFilename> [<start date inclusive> <stop date exclusive>]");
			System.exit(1);
		}
		String logFilename = args[0];
		Date fromDate = null, toDate = null;
		String dfS = "dd/MM/yyyy";
		DateFormat df = new SimpleDateFormat(dfS);
		if (3 <= args.length)
			try {
				fromDate = df.parse(args[1]);
				toDate = df.parse(args[2]);
			} catch (ParseException e) {
				System.err.println("Dates should be specified in the following format: " + dfS);
				System.exit(1);
			}
		Analyser a = new Analyser();
		a.processLogFile(logFilename, fromDate, toDate);
		a.displayResults();
	}

	/**
	 * The field that maps top-level project names to the sum of milliseconds
	 * spent on them for a specified time period.
	 */
	private Map<String,Long> sums;
	/**
	 * The start of a specified time period.
	 */
	private Date fromDate;
	/**
	 * The end of a specified time period.
	 */
	private Date toDate;

	/**
	 * This method reads the specified log file for the specified time period.
	 * The processing of individual log entries is delegated to @
	 * #readLogEntry(String)} .
	 *
	 * @param logFilename
	 *            The name of the log file.
	 * @param fromDate
	 *            The start of the time period.
	 * @param toDate
	 *            The end of the time period.
	 * @return The resulting map of results.
	 * @throws IOException
	 *             Thrown if reading or parsing fails.
	 */
	Map<String,Long> processLogFile(String logFilename, Date fromDate, Date toDate) throws IOException {
		sums = new TreeMap<String,Long>();
		this.fromDate = fromDate;
		this.toDate = toDate;
		BufferedReader br = new BufferedReader(new FileReader(logFilename));
		String line;
		int lineNumber = 0;
		while ((line = br.readLine()) != null)
			try {lineNumber++; readLogEntry(line);}
			catch (Exception e) {
				System.err.println("Could not process log entry on line "
						+ lineNumber + ": \"" + line + "\"");
			}
		br.close();
		return sums;
	}

	/**
	 * Parses a single log entry. Fields should be separated by commas; any
	 * spaces around commas are ignored. If the first field is recognised as a
	 * date, the new log format (from,to,project,sub-project,...) is used;
	 * otherwise, the old log format (project,sub-project,from,to) is used. The
	 * recording of data is delegated to
	 * {@link #recordData(String, String, String, String)}.
	 *
	 * @param entry
	 *            A single log entry to process.
	 */
	private void readLogEntry(String entry) {
		String[] fields = entry.split("\\s*,\\s*");
{'fraction_non_alphanumeric': 0.11148255813953488, 'fraction_numerical': 0.0024709302325581395, 'mean_word_length': 3.0812574139976276, 'pattern_counts': {'":': 1, '<': 17, '<?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': '744124', 'n_tokens_mistral': 2196, 'n_tokens_neox': 1979, 'n_words': 772}