<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace Manisero.PerformanceMonitor.Util
{
	public static class ReportFormatter
	{
		public static string FormatReport<TTask>(TasksDurations<TTask> tasksDurations, bool includeHeader = true, Func<TTask, string> taskNameFormatter = null, Func<TimeSpan, string> taskDurationFormatter = null)
		{
			if (taskNameFormatter == null)
			{
				taskNameFormatter = x => x.ToString();
			}

			if (taskDurationFormatter == null)
			{
				taskDurationFormatter = x => x.TotalMilliseconds.ToString();
			}

			var report = GetSubReport(tasksDurations, 0, taskNameFormatter, taskDurationFormatter).ToList();

			if (includeHeader)
			{
				var header = typeof(TTask).Name + " performance report:";
				report.Insert(0, header);
			}

			return string.Join(Environment.NewLine, report);
		}

		private static IEnumerable<string> GetSubReport<TTask>(TasksDurations<TTask> tasksDurations, int depth, Func<TTask, string> taskNameFormatter, Func<TimeSpan, string> taskDurationFormatter)
		{
			var subreport = new List<string>();
			var indent = string.Join(string.Empty, Enumerable.Repeat("\t", depth));

			foreach (var taskDuration in tasksDurations)
			{
				subreport.Add(string.Format("{0}{1}: {2}",
											indent,
											taskNameFormatter(taskDuration.Key),
											taskDurationFormatter(taskDuration.Value.Duration)));

				if (taskDuration.Value.SubtasksDurations != null)
				{
					subreport.AddRange(GetSubReport(taskDuration.Value.SubtasksDurations,
													depth + 1,
													taskNameFormatter,
													taskDurationFormatter));
				}
			}

			return subreport;
		}
	}
}
<commit_msg>ReportFormatter now appends 'ms' to task durations by default<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace Manisero.PerformanceMonitor.Util
{
	public static class ReportFormatter
	{
		public static string FormatReport<TTask>(TasksDurations<TTask> tasksDurations, bool includeHeader = true, Func<TTask, string> taskNameFormatter = null, Func<TimeSpan, string> taskDurationFormatter = null)
		{
			if (taskNameFormatter == null)
			{
				taskNameFormatter = x => x.ToString();
			}

			if (taskDurationFormatter == null)
			{
				taskDurationFormatter = x => x.TotalMilliseconds.ToString() + " ms";
			}

			var report = GetSubReport(tasksDurations, 0, taskNameFormatter, taskDurationFormatter).ToList();

			if (includeHeader)
			{
				var header = typeof(TTask).Name + " performance report:";
				report.Insert(0, header);
			}

			return string.Join(Environment.NewLine, report);
		}

		private static IEnumerable<string> GetSubReport<TTask>(TasksDurations<TTask> tasksDurations, int depth, Func<TTask, string> taskNameFormatter, Func<TimeSpan, string> taskDurationFormatter)
		{
			var subreport = new List<string>();
			var indent = string.Join(string.Empty, Enumerable.Repeat("\t", depth));

			foreach (var taskDuration in tasksDurations)
			{
				subreport.Add(string.Format("{0}{1}: {2}",
											indent,
											taskNameFormatter(taskDuration.Key),
											taskDurationFormatter(taskDuration.Value.Duration)));

				if (taskDuration.Value.SubtasksDurations != null)
				{
					subreport.AddRange(GetSubReport(taskDuration.Value.SubtasksDurations,
													depth + 1,
													taskNameFormatter,
													taskDurationFormatter));
				}
			}

			return subreport;
		}
	}
}

{'fraction_non_alphanumeric': 0.11023851076207097, 'fraction_numerical': 0.0034904013961605585, 'mean_word_length': 3.8849431818181817, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 27, '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': '7063235', 'n_tokens_mistral': 1278, 'n_tokens_neox': 998, 'n_words': 209}