<commit_before>﻿using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using PoESkillTree.Computation.Common;
using PoESkillTree.Computation.Model;

namespace PoESkillTree.Computation.ViewModels
{
    public class ModifierNodeViewModelFactory
    {
        private readonly ObservableCalculator _calculator;
        private readonly CalculationNodeViewModelFactory _nodeFactory;

        public ModifierNodeViewModelFactory(ObservableCalculator calculator,
            CalculationNodeViewModelFactory nodeFactory)
        {
            _calculator = calculator;
            _nodeFactory = nodeFactory;
        }

        public async Task<IReadOnlyList<ModifierNodeViewModel>> CreateAsync(IStat stat, NodeType nodeType)
        {
            var totalOverrideNodes = await CreateTotalOverrideAsync(stat, nodeType);
            if (totalOverrideNodes.Any())
                return totalOverrideNodes;

            var nodes = new List<ModifierNodeViewModel>();
            nodes.AddRange(await CreateBaseAsync(stat, nodeType));
            nodes.AddRange(await CreateIncreaseMoreAsync(stat, nodeType));

            return nodes.OrderBy(n => n.Form).ThenBy(n => n.ModifierSource.ToString()).ToList();
        }

        private async Task<IReadOnlyList<ModifierNodeViewModel>> CreateTotalOverrideAsync(IStat stat, NodeType nodeType)
        {
            if (nodeType != NodeType.Total && nodeType != NodeType.TotalOverride)
                return new ModifierNodeViewModel[0];

            var totalOverrideValue = await _calculator.GetNodeValueAsync(stat, NodeType.TotalOverride);
            if (totalOverrideValue.HasValue)
                return await CreateFormNodesAsync(stat, Form.TotalOverride, PathDefinition.MainPath);
            return new ModifierNodeViewModel[0];
        }

        private async Task<IReadOnlyList<ModifierNodeViewModel>> CreateBaseAsync(IStat stat, NodeType nodeType)
        {
            if (nodeType == NodeType.Increase || nodeType == NodeType.More)
                return new ModifierNodeViewModel[0];

            var nodes = new List<ModifierNodeViewModel>();
            var paths = (await _calculator.GetPathsAsync(stat)).ToList();
            if (nodeType != NodeType.BaseSet)
            {
                nodes.AddRange(await CreateFormNodesAsync(stat, Form.BaseAdd, paths));
            }
            if (nodeType != NodeType.BaseAdd)
            {
                nodes.AddRange(await CreateFormNodesAsync(stat, Form.BaseSet, paths));
            }
            return nodes;
        }

        private async Task<IReadOnlyList<ModifierNodeViewModel>> CreateIncreaseMoreAsync(IStat stat, NodeType nodeType)
        {
            if (nodeType == NodeType.Base || nodeType == NodeType.BaseSet || nodeType == NodeType.BaseAdd)
                return new ModifierNodeViewModel[0];

            var allPaths = (await _calculator.GetPathsAsync(stat)).ToList();            
            var consideredPaths = new HashSet<PathDefinition>();
            foreach (var path in allPaths)
            {
                var baseValue = await _calculator.GetNodeValueAsync(stat, NodeType.Base, path);
                if (baseValue is null)
                    continue;

                foreach (var influencingSource in path.ModifierSource.InfluencingSources)
                {
                    consideredPaths.Add(new PathDefinition(influencingSource));
                }
            }<commit_msg>Fix modifier nodes tooltip being empty for Increase IndependetResults<commit_after>﻿using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using PoESkillTree.Computation.Common;
using PoESkillTree.Computation.Model;

namespace PoESkillTree.Computation.ViewModels
{
    public class ModifierNodeViewModelFactory
    {
        private readonly ObservableCalculator _calculator;
        private readonly CalculationNodeViewModelFactory _nodeFactory;

        public ModifierNodeViewModelFactory(ObservableCalculator calculator,
            CalculationNodeViewModelFactory nodeFactory)
        {
            _calculator = calculator;
            _nodeFactory = nodeFactory;
        }

        public async Task<IReadOnlyList<ModifierNodeViewModel>> CreateAsync(IStat stat, NodeType nodeType)
        {
            var totalOverrideNodes = await CreateTotalOverrideAsync(stat, nodeType);
            if (totalOverrideNodes.Any())
                return totalOverrideNodes;

            var nodes = new List<ModifierNodeViewModel>();
            nodes.AddRange(await CreateBaseAsync(stat, nodeType));
            nodes.AddRange(await CreateIncreaseMoreAsync(stat, nodeType));

            return nodes.OrderBy(n => n.Form).ThenBy(n => n.ModifierSource.ToString()).ToList();
        }

        private async Task<IReadOnlyList<ModifierNodeViewModel>> CreateTotalOverrideAsync(IStat stat, NodeType nodeType)
        {
            if (nodeType != NodeType.Total && nodeType != NodeType.TotalOverride)
                return new ModifierNodeViewModel[0];

            var totalOverrideValue = await _calculator.GetNodeValueAsync(stat, NodeType.TotalOverride);
            if (totalOverrideValue.HasValue)
                return await CreateFormNodesAsync(stat, Form.TotalOverride, PathDefinition.MainPath);
            return new ModifierNodeViewModel[0];
        }

        private async Task<IReadOnlyList<ModifierNodeViewModel>> CreateBaseAsync(IStat stat, NodeType nodeType)
        {
            if (nodeType == NodeType.Increase || nodeType == NodeType.More)
                return new ModifierNodeViewModel[0];

            var nodes = new List<ModifierNodeViewModel>();
            var paths = (await _calculator.GetPathsAsync(stat)).ToList();
            if (nodeType != NodeType.BaseSet)
            {
                nodes.AddRange(await CreateFormNodesAsync(stat, Form.BaseAdd, paths));
            }
            if (nodeType != NodeType.BaseAdd)
            {
                nodes.AddRange(await CreateFormNodesAsync(stat, Form.BaseSet, paths));
            }
            return nodes;
        }

        private async Task<IReadOnlyList<ModifierNodeViewModel>> CreateIncreaseMoreAsync(IStat stat, NodeType nodeType)
        {
            if (nodeType == NodeType.Base || nodeType == NodeType.BaseSet || nodeType == NodeType.BaseAdd)
                return new ModifierNodeViewModel[0];

            var allPaths = (await _calculator.GetPathsAsync(stat)).ToList();            
            var consideredPaths = new HashSet<PathDefinition>();
            foreach (var path in allPaths)
            {
                if (nodeType != NodeType.Increase && nodeType != NodeType.More)
                {
                    var baseValue = await _calculator.GetNodeValueAsync(stat, NodeType.Base, path);
                    if (baseValue is null)
                        continue;
                }

                foreach (var influencingSource in path.ModifierSource.InfluencingSources)
                {
                    consideredPaths.Add(new PathDefinition(influencingSource));
                }
            }
{'fraction_non_alphanumeric': 0.07882882882882883, 'fraction_numerical': 0.0011261261261261261, 'mean_word_length': 2.384945212005717, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 29, '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': '1565275', 'n_tokens_mistral': 1791, 'n_tokens_neox': 1714, 'n_words': 371}