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

namespace Starcraft2.ReplayParser
{
    using System.Text;

    using MpqLib.Mpq;

    public class Replay
    {
        internal Replay()
        {
        }

        /// <summary>
        /// Gets the version number of the replay.
        /// </summary>
        public string ReplayVersion { get; internal set; }

        /// <summary>
        /// Gets the build number of the Starcraft 2 version used in creating the replay.
        /// </summary>
        public int ReplayBuild { get; internal set; }

        /// <summary>
        /// Gets the details of all players in the replay.
        /// </summary>
        public Player[] Players { get; internal set; }
        
        /// <summary>
        /// Gets the map the game was played on.
        /// </summary>
        public string Map { get; internal set; }

        /// <summary>
        /// Gets the Time at which the game took place.
        /// </summary>
        public DateTime Timestamp { get; internal set; }

        /// <summary>
        /// Gets the speed the game was played at.
        /// </summary>
        public GameSpeed GameSpeed { get; internal set; }

        /// <summary>
        /// Gets the team size of the selected gametype.
        /// </summary>
        /// <example>1v1, 2v2, 3v3, 4v4</example>
        public string TeamSize { get; internal set; }

        /// <summary> Gets the Gateway (KR, NA, etc.) that the game was played in. </summary>
        public string Gateway { get; internal set; }

        /// <summary>
        /// Gets the type of game this replay covers, whether it was a private or open match.
        /// </summary>
        public GameType GameType { get; internal set; }

        /// <summary>
        /// Gets a list of all chat messages which took place during the game.
        /// </summary>
        public IList<ChatMessage> ChatMessages { get; internal set; }

        public List<IGameEvent> PlayerEvents { get; internal set; }

        public Player GetPlayerById(int playerId)
        {
            int playerIndex = playerId - 1;

            if (playerId < this.Players.Length)
            {
                return this.Players[playerIndex];
            }

            return null;
        }

        /// <summary>
        /// Parses a .SC2Replay file and returns relevant replay information.
        /// </summary>
        /// <param name="fileName">Full path to a .SC2Replay file.</param>
        public static Replay Parse(string fileName)
        {
            if (File.Exists(fileName) == false)
            {
                throw new FileNotFoundException("The specified file does not exist.", fileName);
            }<commit_msg>GetPlayerById was incorrectly testing the player ID for "out of bounds" issues, rather than the playerIndex, so trying to get the last player in the Players array would return null instead.<commit_after>﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Starcraft2.ReplayParser
{
    using System.Text;

    using MpqLib.Mpq;

    public class Replay
    {
        internal Replay()
        {
        }

        /// <summary>
        /// Gets the version number of the replay.
        /// </summary>
        public string ReplayVersion { get; internal set; }

        /// <summary>
        /// Gets the build number of the Starcraft 2 version used in creating the replay.
        /// </summary>
        public int ReplayBuild { get; internal set; }

        /// <summary>
        /// Gets the details of all players in the replay.
        /// </summary>
        public Player[] Players { get; internal set; }
        
        /// <summary>
        /// Gets the map the game was played on.
        /// </summary>
        public string Map { get; internal set; }

        /// <summary>
        /// Gets the Time at which the game took place.
        /// </summary>
        public DateTime Timestamp { get; internal set; }

        /// <summary>
        /// Gets the speed the game was played at.
        /// </summary>
        public GameSpeed GameSpeed { get; internal set; }

        /// <summary>
        /// Gets the team size of the selected gametype.
        /// </summary>
        /// <example>1v1, 2v2, 3v3, 4v4</example>
        public string TeamSize { get; internal set; }

        /// <summary> Gets the Gateway (KR, NA, etc.) that the game was played in. </summary>
        public string Gateway { get; internal set; }

        /// <summary>
        /// Gets the type of game this replay covers, whether it was a private or open match.
        /// </summary>
        public GameType GameType { get; internal set; }

        /// <summary>
        /// Gets a list of all chat messages which took place during the game.
        /// </summary>
        public IList<ChatMessage> ChatMessages { get; internal set; }

        public List<IGameEvent> PlayerEvents { get; internal set; }

        public Player GetPlayerById(int playerId)
        {
            int playerIndex = playerId - 1;

            if (playerIndex < this.Players.Length)
            {
                return this.Players[playerIndex];
            }

            return null;
        }

        /// <summary>
        /// Parses a .SC2Replay file and returns relevant replay information.
        /// </summary>
        /// <param name="fileName">Full path to a .SC2Replay file.</param>
        public static Replay Parse(string fileName)
        {
            if (File.Exists(fileName) == false)
            {
                throw new FileNotFoundException("The specified file does not exist.", fileName);
            }
{'fraction_non_alphanumeric': 0.10650991402000351, 'fraction_numerical': 0.004562203895420249, 'mean_word_length': 1.6536312849162011, 'pattern_counts': {'":': 0, '<': 61, '<?xml version=': 0, '>': 59, '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': '2342447', 'n_tokens_mistral': 1497, 'n_tokens_neox': 1436, 'n_words': 556}