<commit_before>using System;
using System.IO;
using System.Collections.Generic;
using System.Xml.Serialization;
using Microsoft.Extensions.Logging;
using Server.BuildConfig;
using Server.Runtime;
using System.Text;
using System.Linq;
using Server.Services.Stats;

namespace Server.Services {
	public class StatService : IService {
		public string ContainerPath { get; private set; }

		ILogger _logger;

		BuildServer   _server;
		BuildProcess  _process;
		StatContainer _container;

		bool _skipShortTasks;

		public StatService(string containerPath, LoggerFactory loggerFactory, bool skipShortTasks) {
			ContainerPath = containerPath;
			_logger = loggerFactory.CreateLogger<StatService>();
			_skipShortTasks = skipShortTasks;
		}

		public bool TryInit(BuildServer server, Project project) {
			_server = server;
			_server.OnInitBuild += OnInitBuild;
			_server.AddCommand("stats", "show builds stats (build cout, min,max,average build times)", OnStatsRequested);
			_server.AddCommand("history", "show builds history (last completed builds list)", OnHistoryRequested);
			LoadContainer();
			_logger.LogDebug($"Container: {_container.Builds.Count} builds");
			return true;
		}

		XmlSerializer CreateSerializer() {
			return XmlSerializer.FromTypes(new[] { typeof(StatContainer) })[0];
		}

		void LoadContainer() {
			if ( !File.Exists(ContainerPath) ) {
				_container = new StatContainer();
				_logger.LogDebug($"Not found stat file at '{ContainerPath}', initialize as empty.");
				return;
			}
			var serializer = CreateSerializer();
			using ( var stream = new FileStream(ContainerPath, FileMode.OpenOrCreate) ) {
				try {
					_container = serializer.Deserialize(stream) as StatContainer;
				} catch (Exception e) {
					_logger.LogError($"Can't load stat file from '{ContainerPath}': \"{e}\"");
					_container = new StatContainer();
				}
			}
		}

		void SaveContainer() {
			_logger.LogDebug("SaveContainer");
			var serializer = CreateSerializer();<commit_msg>Fixed typo in 'stats' command text output<commit_after>using System;
using System.IO;
using System.Collections.Generic;
using System.Xml.Serialization;
using Microsoft.Extensions.Logging;
using Server.BuildConfig;
using Server.Runtime;
using System.Text;
using System.Linq;
using Server.Services.Stats;

namespace Server.Services {
	public class StatService : IService {
		public string ContainerPath { get; private set; }

		ILogger _logger;

		BuildServer   _server;
		BuildProcess  _process;
		StatContainer _container;

		bool _skipShortTasks;

		public StatService(string containerPath, LoggerFactory loggerFactory, bool skipShortTasks) {
			ContainerPath = containerPath;
			_logger = loggerFactory.CreateLogger<StatService>();
			_skipShortTasks = skipShortTasks;
		}

		public bool TryInit(BuildServer server, Project project) {
			_server = server;
			_server.OnInitBuild += OnInitBuild;
			_server.AddCommand("stats", "show builds stats (build count, min, max, average build times)", OnStatsRequested);
			_server.AddCommand("history", "show builds history (last completed builds list)", OnHistoryRequested);
			LoadContainer();
			_logger.LogDebug($"Container: {_container.Builds.Count} builds");
			return true;
		}

		XmlSerializer CreateSerializer() {
			return XmlSerializer.FromTypes(new[] { typeof(StatContainer) })[0];
		}

		void LoadContainer() {
			if ( !File.Exists(ContainerPath) ) {
				_container = new StatContainer();
				_logger.LogDebug($"Not found stat file at '{ContainerPath}', initialize as empty.");
				return;
			}
			var serializer = CreateSerializer();
			using ( var stream = new FileStream(ContainerPath, FileMode.OpenOrCreate) ) {
				try {
					_container = serializer.Deserialize(stream) as StatContainer;
				} catch (Exception e) {
					_logger.LogError($"Can't load stat file from '{ContainerPath}': \"{e}\"");
					_container = new StatContainer();
				}
			}
		}

		void SaveContainer() {
			_logger.LogDebug("SaveContainer");
			var serializer = CreateSerializer();
{'fraction_non_alphanumeric': 0.1085814360770578, 'fraction_numerical': 0.0005003752814610958, 'mean_word_length': 4.638928067700987, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6061688', 'n_tokens_mistral': 1295, 'n_tokens_neox': 1117, 'n_words': 299}