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

namespace LiveSplit.Model
{
    public static class SumOfBest
    {
        private static void PopulatePrediction(IList<TimeSpan?> predictions, TimeSpan? predictedTime, int segmentIndex, TimingMethod method = TimingMethod.RealTime)
        {
            if (predictedTime.HasValue && (!predictions[segmentIndex].HasValue || predictedTime < predictions[segmentIndex].Value))
            {
                predictions[segmentIndex] = predictedTime;
            }
        }

        private static void PopulatePredictions(IRun run, TimeSpan? currentTime, int segmentIndex, IList<TimeSpan?> predictions, bool simpleCalculation, TimingMethod method = TimingMethod.RealTime)
        {
            if (currentTime != null)
            {
                PopulatePrediction(predictions, currentTime + run[segmentIndex].BestSegmentTime[method], segmentIndex + 1);
                if (!simpleCalculation)
                {
                    foreach (var nullSegment in run[segmentIndex].SegmentHistory.Where(x => !x.Time[method].HasValue))
                    {
                        var prediction = TrackBranch(run, currentTime, segmentIndex + 1, nullSegment.Index);
                        PopulatePrediction(predictions, prediction.Time[method], prediction.Index, method);
                    }
                }
                var currentRunPrediction = TrackCurrentRun(run, currentTime, segmentIndex);
                PopulatePrediction(predictions, currentRunPrediction.Time[method], currentRunPrediction.Index, method);
                var personalBestRunPrediction = TrackPersonalBestRun(run, currentTime, segmentIndex);
                PopulatePrediction(predictions, personalBestRunPrediction.Time[method], personalBestRunPrediction.Index, method);
            }
        }

        private static IndexedTime TrackCurrentRun(IRun run, TimeSpan? currentTime, int segmentIndex, TimingMethod method = TimingMethod.RealTime)
        {
            if (segmentIndex > 0 && !run[segmentIndex - 1].SplitTime[method].HasValue)
                return new IndexedTime(default(Time), 0);
            var firstSplitTime = segmentIndex < 1 ? TimeSpan.Zero : run[segmentIndex - 1].SplitTime[method];
            while (segmentIndex < run.Count)
            {
                var secondSplitTime = run[segmentIndex].SplitTime[method];
                if (secondSplitTime.HasValue)
                {
                    return new IndexedTime(new Time(secondSplitTime - firstSplitTime + currentTime), segmentIndex + 1);
                }<commit_msg>Use GameTime properly in SoB calculation<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace LiveSplit.Model
{
    public static class SumOfBest
    {
        private static void PopulatePrediction(IList<TimeSpan?> predictions, TimeSpan? predictedTime, int segmentIndex, TimingMethod method = TimingMethod.RealTime)
        {
            if (predictedTime.HasValue && (!predictions[segmentIndex].HasValue || predictedTime < predictions[segmentIndex].Value))
            {
                predictions[segmentIndex] = predictedTime;
            }
        }

        private static void PopulatePredictions(IRun run, TimeSpan? currentTime, int segmentIndex, IList<TimeSpan?> predictions, bool simpleCalculation, TimingMethod method = TimingMethod.RealTime)
        {
            if (currentTime != null)
            {
                PopulatePrediction(predictions, currentTime + run[segmentIndex].BestSegmentTime[method], segmentIndex + 1, method);
                if (!simpleCalculation)
                {
                    foreach (var nullSegment in run[segmentIndex].SegmentHistory.Where(x => !x.Time[method].HasValue))
                    {
                        var prediction = TrackBranch(run, currentTime, segmentIndex + 1, nullSegment.Index, method);
                        PopulatePrediction(predictions, prediction.Time[method], prediction.Index, method);
                    }
                }
                var currentRunPrediction = TrackCurrentRun(run, currentTime, segmentIndex, method);
                PopulatePrediction(predictions, currentRunPrediction.Time[method], currentRunPrediction.Index, method);
                var personalBestRunPrediction = TrackPersonalBestRun(run, currentTime, segmentIndex, method);
                PopulatePrediction(predictions, personalBestRunPrediction.Time[method], personalBestRunPrediction.Index, method);
            }
        }

        private static IndexedTime TrackCurrentRun(IRun run, TimeSpan? currentTime, int segmentIndex, TimingMethod method = TimingMethod.RealTime)
        {
            if (segmentIndex > 0 && !run[segmentIndex - 1].SplitTime[method].HasValue)
                return new IndexedTime(default(Time), 0);
            var firstSplitTime = segmentIndex < 1 ? TimeSpan.Zero : run[segmentIndex - 1].SplitTime[method];
            while (segmentIndex < run.Count)
            {
                var secondSplitTime = run[segmentIndex].SplitTime[method];
                if (secondSplitTime.HasValue)
                {
                    return new IndexedTime(new Time(secondSplitTime - firstSplitTime + currentTime), segmentIndex + 1);
                }
{'fraction_non_alphanumeric': 0.08407163053722903, 'fraction_numerical': 0.0030160226201696515, 'mean_word_length': 2.4679738562091504, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, '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': '6804669', 'n_tokens_mistral': 1316, 'n_tokens_neox': 1254, 'n_words': 281}