<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using DamageMeter.Database.Structures;
using Tera.Game;
using Skill = Tera.Game.Skill;

namespace DamageMeter
{
    public class SkillAggregate
    {
        private readonly PlayerDamageDealt _playerDamageDealt;
        private readonly Entity _target;
        private readonly bool _timed;

        public SkillAggregate(Skill skill, Skills skillsData, Entity source, Entity target, PlayerDamageDealt playerDamageDealt,
            bool timed, Database.Database.Type type)
        {
            _playerDamageDealt = playerDamageDealt;
            _timed = timed;
            _target = target;
            Type = type;
            Skills = new Dictionary<Skill, List<Entity>>();
            Name = skill.ShortName;
            SkillsData = skillsData;
            Skills.Add(skill, new List<Entity>{ source });
        }

        public Dictionary<Skill, List<Entity>> Skills { get; }
        public string Name { get; }

        private Skills SkillsData { get; }

        private bool _playerDealtUnrelieable;

        public Database.Database.Type Type { get; }

        public bool Add(Skill skill, Entity source)
        {
            if (skill.ShortName != Name) return false;
            if (Skills.Any(sk => skill.Id == sk.Key.Id && skill.IsHotDot == sk.Key.IsHotDot && sk.Value.Contains(source)))
            {
                return false;
            }

            if (Skills.ContainsKey(skill))
            {
                Skills[skill].Add(source);
                _playerDealtUnrelieable = true;
            }
            else
            {
                Skills.Add(skill, new List<Entity> {source});
            }
            return true;
        }

        public long Amount()
        {
            var result = from skill in Skills
                         from source in skill.Value
                            select SkillsData.Amount(source, _target, skill.Key.Id, _timed, Type);
            return result.Sum();
        }

        public long Amount(int skillId)
        {
            var result = from skill in Skills
                         where skill.Key.Id == skillId
                         from source in skill.Value
                         select SkillsData.Amount(source, _target, skillId, _timed, Type);
            return result.Sum();
        }

        public long BiggestCrit()
        {
            var result = from skill in Skills
                         from source in skill.Value
                         select SkillsData.BiggestCrit(source, _target, skill.Key.Id, _timed, Type);
            var enumerable = result as long[] ?? result.ToArray();
            return !enumerable.Any() ? 0 : enumerable.Max();
        }

        public long LowestCrit()
        {
            var result = from skill in Skills
                         from source in skill.Value
                         select SkillsData.LowestCrit(source, _target, skill.Key.Id, _timed, Type);
            var enumerable = result as long[] ?? result.ToArray();
            return !enumerable.Any() ? 0 : enumerable.Min();
        }

        public long BiggestCrit(int skillId)
        {
            var result = from skill in Skills
                         where skill.Key.Id == skillId
                         from source in skill.Value
                         select SkillsData.BiggestCrit(source, _target, skillId, _timed, Type);
            var enumerable = result as long[] ?? result.ToArray();<commit_msg>Fix LowestCrit shows 0 when there was subskill without crits<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using DamageMeter.Database.Structures;
using Tera.Game;
using Skill = Tera.Game.Skill;

namespace DamageMeter
{
    public class SkillAggregate
    {
        private readonly PlayerDamageDealt _playerDamageDealt;
        private readonly Entity _target;
        private readonly bool _timed;

        public SkillAggregate(Skill skill, Skills skillsData, Entity source, Entity target, PlayerDamageDealt playerDamageDealt,
            bool timed, Database.Database.Type type)
        {
            _playerDamageDealt = playerDamageDealt;
            _timed = timed;
            _target = target;
            Type = type;
            Skills = new Dictionary<Skill, List<Entity>>();
            Name = skill.ShortName;
            SkillsData = skillsData;
            Skills.Add(skill, new List<Entity>{ source });
        }

        public Dictionary<Skill, List<Entity>> Skills { get; }
        public string Name { get; }

        private Skills SkillsData { get; }

        private bool _playerDealtUnrelieable;

        public Database.Database.Type Type { get; }

        public bool Add(Skill skill, Entity source)
        {
            if (skill.ShortName != Name) return false;
            if (Skills.Any(sk => skill.Id == sk.Key.Id && skill.IsHotDot == sk.Key.IsHotDot && sk.Value.Contains(source)))
            {
                return false;
            }

            if (Skills.ContainsKey(skill))
            {
                Skills[skill].Add(source);
                _playerDealtUnrelieable = true;
            }
            else
            {
                Skills.Add(skill, new List<Entity> {source});
            }
            return true;
        }

        public long Amount()
        {
            var result = from skill in Skills
                         from source in skill.Value
                            select SkillsData.Amount(source, _target, skill.Key.Id, _timed, Type);
            return result.Sum();
        }

        public long Amount(int skillId)
        {
            var result = from skill in Skills
                         where skill.Key.Id == skillId
                         from source in skill.Value
                         select SkillsData.Amount(source, _target, skillId, _timed, Type);
            return result.Sum();
        }

        public long BiggestCrit()
        {
            var result = from skill in Skills
                         from source in skill.Value
                         select SkillsData.BiggestCrit(source, _target, skill.Key.Id, _timed, Type);
            var enumerable = result as long[] ?? result.ToArray();
            return !enumerable.Any() ? 0 : enumerable.Max();
        }

        public long LowestCrit()
        {
            var result = from skill in Skills
                         from source in skill.Value
                         let res = SkillsData.LowestCrit(source, _target, skill.Key.Id, _timed, Type)
                         where res !=0
                         select res;
            var enumerable = result as long[] ?? result.ToArray();
            return !enumerable.Any() ? 0 : enumerable.Min();
        }

        public long BiggestCrit(int skillId)
        {
            var result = from skill in Skills
                         where skill.Key.Id == skillId
                         from source in skill.Value
                         select SkillsData.BiggestCrit(source, _target, skillId, _timed, Type);
            var enumerable = result as long[] ?? result.ToArray();
{'fraction_non_alphanumeric': 0.0818672946391467, 'fraction_numerical': 0.000831140047097936, 'mean_word_length': 1.5776508389860764, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6593098', 'n_tokens_mistral': 1899, 'n_tokens_neox': 1803, 'n_words': 518}