<commit_before>﻿// Copyright (c) 2007-2017 ppy Pty Ltd <<EMAIL>>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE

using osu.Game.Rulesets.Objects;
using System.Collections.Generic;
using osu.Game.Rulesets.Mods;
using osu.Framework.Timing;
using System.Linq;
using osu.Framework.Extensions.IEnumerableExtensions;

namespace osu.Game.Beatmaps
{
    public abstract class DifficultyCalculator
    {
        protected double TimeRate = 1;

        public abstract double Calculate(Dictionary<string, string> categoryDifficulty = null);
    }

    public abstract class DifficultyCalculator<T> : DifficultyCalculator where T : HitObject
    {
        protected readonly Beatmap Beatmap;
        protected readonly Mod[] Mods;

        protected List<T> Objects;

        protected DifficultyCalculator(Beatmap beatmap)
            : this(beatmap, null)
        {
        }

        protected DifficultyCalculator(Beatmap beatmap, Mod[] mods)
        {
            Beatmap = beatmap;
            Mods = mods ?? new Mod[0];

            Objects = CreateBeatmapConverter().Convert(beatmap).HitObjects;

            foreach (var h in Objects)
                h.ApplyDefaults(beatmap.ControlPointInfo, beatmap.BeatmapInfo.BaseDifficulty);

            ApplyMods(mods);

            PreprocessHitObjects();
        }

        protected virtual void ApplyMods(Mod[] mods)
        {
            var clock = new StopwatchClock();
            mods.OfType<IApplicableToClock>().ForEach(m => m.ApplyToClock(clock));
            TimeRate = clock.Rate;

            foreach (var mod in mods.OfType<IApplicableToHitObject<T>>())
                foreach (var obj in Objects)
                    mod.ApplyToHitObject(obj);
        }

        protected virtual void PreprocessHitObjects()
        {
        }

        protected abstract BeatmapConverter<T> CreateBeatmapConverter();
    }<commit_msg>Fix DifficultyCalculator using incorrect mods<commit_after>﻿// Copyright (c) 2007-2017 ppy Pty Ltd <<EMAIL>>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE

using osu.Game.Rulesets.Objects;
using System.Collections.Generic;
using osu.Game.Rulesets.Mods;
using osu.Framework.Timing;
using System.Linq;
using osu.Framework.Extensions.IEnumerableExtensions;

namespace osu.Game.Beatmaps
{
    public abstract class DifficultyCalculator
    {
        protected double TimeRate = 1;

        public abstract double Calculate(Dictionary<string, string> categoryDifficulty = null);
    }

    public abstract class DifficultyCalculator<T> : DifficultyCalculator where T : HitObject
    {
        protected readonly Beatmap Beatmap;
        protected readonly Mod[] Mods;

        protected List<T> Objects;

        protected DifficultyCalculator(Beatmap beatmap)
            : this(beatmap, null)
        {
        }

        protected DifficultyCalculator(Beatmap beatmap, Mod[] mods)
        {
            Beatmap = beatmap;
            Mods = mods ?? new Mod[0];

            Objects = CreateBeatmapConverter().Convert(beatmap).HitObjects;

            foreach (var h in Objects)
                h.ApplyDefaults(beatmap.ControlPointInfo, beatmap.BeatmapInfo.BaseDifficulty);

            ApplyMods(Mods);

            PreprocessHitObjects();
        }

        protected virtual void ApplyMods(Mod[] mods)
        {
            var clock = new StopwatchClock();
            mods.OfType<IApplicableToClock>().ForEach(m => m.ApplyToClock(clock));
            TimeRate = clock.Rate;

            foreach (var mod in mods.OfType<IApplicableToHitObject<T>>())
                foreach (var obj in Objects)
                    mod.ApplyToHitObject(obj);
        }

        protected virtual void PreprocessHitObjects()
        {
        }

        protected abstract BeatmapConverter<T> CreateBeatmapConverter();
    }
{'fraction_non_alphanumeric': 0.08818978855079938, 'fraction_numerical': 0.005157297576070139, 'mean_word_length': 2.4664879356568363, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 23, 'https://': 2, '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': '4140560', 'n_tokens_mistral': 1133, 'n_tokens_neox': 1050, 'n_words': 246}