Пример #1
0
 private static void FixComparisonTimes(IRun run, TimingMethod method)
 {
     foreach (var comparison in run.CustomComparisons)
     {
         var previousTime = TimeSpan.Zero;
         foreach (var curSplit in run)
         {
             if (curSplit.Comparisons[comparison][method] != null)
             {
                 if (curSplit.Comparisons[comparison][method] < previousTime)
                 {
                     var newComparison = new Time(curSplit.Comparisons[comparison]);
                     newComparison[method]            = previousTime;
                     curSplit.Comparisons[comparison] = newComparison;
                 }
                 var currentSegment = curSplit.Comparisons[comparison][method] - previousTime;
                 if (comparison == Run.PersonalBestComparisonName && (curSplit.BestSegmentTime[method] == null || curSplit.BestSegmentTime[method] > currentSegment))
                 {
                     var newTime = new Time(curSplit.BestSegmentTime);
                     newTime[method]          = currentSegment;
                     curSplit.BestSegmentTime = newTime;
                 }
                 previousTime = curSplit.Comparisons[comparison][method].Value;
             }
         }
     }
 }
Пример #2
0
        private static void RemoveNullValues(IRun run, TimingMethod method)
        {
            var cache    = new List <IIndexedTime>();
            var maxIndex = run.AttemptHistory.Select(x => x.Index).DefaultIfEmpty(0).Max();

            for (var runIndex = run.GetMinSegmentHistoryIndex(); runIndex <= maxIndex; runIndex++)
            {
                for (var index = 0; index < run.Count; index++)
                {
                    var segmentHistoryElement = run[index].SegmentHistory.FirstOrDefault(x => x.Index == runIndex);
                    if (segmentHistoryElement == null)
                    {
                        RemoveItemsFromCache(run, index, cache);
                    }
                    else if (segmentHistoryElement.Time.RealTime == null && segmentHistoryElement.Time.GameTime == null)
                    {
                        cache.Add(segmentHistoryElement);
                    }
                    else
                    {
                        cache.Clear();
                    }
                }
                RemoveItemsFromCache(run, run.Count, cache);
                cache.Clear();
            }
        }
        public void Generate(TimingMethod method)
        {
            var maxIndex = Run.AttemptHistory.Select(x => x.Index).DefaultIfEmpty(0).Max();
            for (var y = Run.GetMinSegmentHistoryIndex(); y <= maxIndex; y++)
            {
                var time = TimeSpan.Zero;

                foreach (var segment in Run)
                {
                    Time segmentHistoryElement;
                    if (segment.SegmentHistory.TryGetValue(y, out segmentHistoryElement))
                    {
                        var segmentTime = segmentHistoryElement[method];
                        if (segmentTime != null)
                        {
                            time += segmentTime.Value;

                            if (segment.Comparisons[Name][method] == null || time < segment.Comparisons[Name][method])
                            {
                                var newTime = new Time(segment.Comparisons[Name]);
                                newTime[method] = time;
                                segment.Comparisons[Name] = newTime;
                            }
                        }
                    }
                    else break;
                }
            }
        }
Пример #4
0
 private static void PopulatePredictions(IRun run, TimeSpan? currentTime, int segmentIndex, IList<TimeSpan?> predictions, bool useCurrentRun, TimingMethod method)
 {
     if (currentTime != null)
     {
         PopulatePrediction(predictions, currentTime + run[segmentIndex].BestSegmentTime[method], segmentIndex + 1);
         foreach (var segment in run[segmentIndex].SegmentHistory)
         {
             Time segmentTime;
             if (segmentIndex == 0 
                 || !run[segmentIndex - 1].SegmentHistory.TryGetValue(segment.Key, out segmentTime) 
                 || segmentTime[method] != null)
             {
                 var prediction = SumOfSegmentsHelper.TrackBranch(run, currentTime, segmentIndex, segment.Key, method);
                 PopulatePrediction(predictions, prediction.Time[method], prediction.Index);
             }
         }
         if (useCurrentRun)
         {
             var currentRunPrediction = SumOfSegmentsHelper.TrackCurrentRun(run, currentTime, segmentIndex, method);
             PopulatePrediction(predictions, currentRunPrediction.Time[method], currentRunPrediction.Index);
         }
         var personalBestRunPrediction = SumOfSegmentsHelper.TrackPersonalBestRun(run, currentTime, segmentIndex, method);
         PopulatePrediction(predictions, personalBestRunPrediction.Time[method], personalBestRunPrediction.Index);
     }
 }
Пример #5
0
        public override TimeSpan?GetTime(LiveSplitState state, TimingMethod method)
        {
            TimeSpan?lastSplit     = TimeSpan.Zero;
            var      runEndedDelay = state.CurrentPhase == TimerPhase.Ended ? 1 : 0;

            if (state.CurrentSplitIndex > 0 + runEndedDelay)
            {
                if (state.Run[state.CurrentSplitIndex - 1 - runEndedDelay].SplitTime[method] != null)
                {
                    lastSplit = state.Run[state.CurrentSplitIndex - 1 - runEndedDelay].SplitTime[method].Value;
                }
                else
                {
                    lastSplit = null;
                }
            }
            if (state.CurrentPhase == TimerPhase.NotRunning)
            {
                return(state.Run.Offset);
            }
            else
            {
                return(state.CurrentTime[method] - lastSplit);
            }
        }
Пример #6
0
        public void Generate(TimingMethod method)
        {
            for (var y = Run.GetMinSegmentHistoryIndex() + 1; y <= Run.RunHistory.Count; y++)
            {
                var time = TimeSpan.Zero;

                foreach (var segment in Run)
                {
                    var segmentHistoryElement = segment.SegmentHistory.FirstOrDefault(x => x.Index == y);
                    if (segmentHistoryElement != null)
                    {
                        var segmentTime = segmentHistoryElement.Time[method];
                        if (segmentTime != null)
                        {
                            time += segmentTime.Value;

                            if (segment.Comparisons[Name][method] == null || time < segment.Comparisons[Name][method])
                            {
                                var newTime = new Time(segment.Comparisons[Name]);
                                newTime[method]           = time;
                                segment.Comparisons[Name] = newTime;
                            }
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
Пример #7
0
        public virtual bool SubmitRun(
            IRun run,
            String username, String password,
            Func <Image> screenShotFunction = null,
            bool attachSplits   = false,
            TimingMethod method = TimingMethod.RealTime,
            String gameId       = "", String categoryId = "",
            String version      = "", String comment    = "",
            String video        = "",
            params String[] additionalParams)
        {
            try
            {
                if (attachSplits)
                {
                    comment += " " + SplitsIO.Instance.Share(run, screenShotFunction);
                }
                if (gameId == String.Empty)
                {
                    gameId = GetGameIdByName(run.GameName);
                }
                if (categoryId == String.Empty)
                {
                    categoryId = GetCategoryIdByName(gameId, run.CategoryName);
                }
                var json = ASUP.SubmitRun(run, username, password, gameId, categoryId, version, comment, video, additionalParams);
                return(json.result == "success");
            }
            catch (Exception e)
            {
                Log.Error(e);

                return(false);
            }
        }
        public void Generate(TimingMethod method)
        {
            var attemptIndex = GetAttemptIndex();

            if (attemptIndex > 0)
            {
                TimeSpan?totalTime = TimeSpan.Zero;
                for (var ind = 0; ind < Run.Count; ind++)
                {
                    TimeSpan?segmentTime = null;
                    if (Run[ind].SegmentHistory.ContainsKey(attemptIndex))
                    {
                        segmentTime = Run[ind].SegmentHistory[attemptIndex][method];
                    }
                    else
                    {
                        totalTime = null;
                    }

                    var time = new Time(Run[ind].Comparisons[Name]);
                    if (totalTime != null && segmentTime != null)
                    {
                        totalTime   += segmentTime;
                        time[method] = totalTime;
                    }
                    else
                    {
                        time[method] = null;
                    }

                    Run[ind].Comparisons[Name] = time;
                }
            }
        }
Пример #9
0
        private static void RemoveNullValues(IRun run, TimingMethod method)
        {
            var cache    = new List <IIndexedTime>();
            var maxIndex = run.AttemptHistory.Select(x => x.Index).DefaultIfEmpty(0).Max();

            for (var runIndex = run.GetMinSegmentHistoryIndex(); runIndex <= maxIndex; runIndex++)
            {
                for (var index = 0; index < run.Count; index++)
                {
                    Time segmentHistoryElement;
                    if (!run[index].SegmentHistory.TryGetValue(runIndex, out segmentHistoryElement))
                    {
                        //Remove null times in history that aren't followed by a non-null time
                        RemoveItemsFromCache(run, index, cache);
                    }
                    else if (segmentHistoryElement.RealTime == null && segmentHistoryElement.GameTime == null)
                    {
                        cache.Add(new IndexedTime(segmentHistoryElement, runIndex));
                    }
                    else
                    {
                        cache.Clear();
                    }
                }
                RemoveItemsFromCache(run, run.Count, cache);
                cache.Clear();
            }
        }
Пример #10
0
        public void AllBareLockTimeout_Timeout_NotAcquire(TimingMethod timingMethod, int sleepMs)
        {
            // setup
            var    locks      = new List <IBareLock>();
            object valueToken = null;

            {
                var l = new Mock <IBareLock>(MockBehavior.Strict);
                l.Setup(x => x.BarelyTryLock(1, out valueToken)).Returns(new TryLockTimeoutDelegate((int _, out object v) =>
                {
                    Thread.Sleep(sleepMs);
                    v = new object();
                    return(true);
                }));
                l.Setup(x => x.BarelyUnlock());
                locks.Add(l.Object);
            }
            {
                var l = new Mock <IBareLock>(MockBehavior.Strict);
                l.Setup(x => x.BarelyTryLock(out valueToken)).Returns(false);
                l.Setup(x => x.BarelyTryLock(0, out valueToken)).Returns(false);
                l.Setup(x => x.BarelyUnlock());
                locks.Add(l.Object);
            }
            locks.Add(new Mock <IBareLock>(MockBehavior.Strict).Object); // prevent infinite loop

            // act
            var guard = MultiSync.All(locks, 1, timingMethod);

            // assert
            guard.ShouldBeNull();
        }
Пример #11
0
 public RecentSplitsFile(string path, TimingMethod method, string gameName = null, string categoryName = null)
 {
     GameName         = gameName;
     CategoryName     = categoryName;
     Path             = path;
     LastTimingMethod = method;
 }
Пример #12
0
        private static void FixSegmentHistory(IRun run, TimingMethod method)
        {
            var maxIndex = run.AttemptHistory.Select(x => x.Index).DefaultIfEmpty(0).Max();

            foreach (var curSplit in run)
            {
                for (var runIndex = curSplit.SegmentHistory.GetMinIndex(); runIndex <= maxIndex; runIndex++)
                {
                    Time historyTime;
                    if (curSplit.SegmentHistory.TryGetValue(runIndex, out historyTime))
                    {
                        //Make sure no times in the history are lower than the Best Segment
                        if (curSplit.BestSegmentTime[method] != null && historyTime[method] < curSplit.BestSegmentTime[method])
                        {
                            historyTime[method] = curSplit.BestSegmentTime[method];
                        }

                        //If the Best Segment is gone, clear the history
                        if (curSplit.BestSegmentTime[method] == null && historyTime[method] != null)
                        {
                            curSplit.SegmentHistory.Remove(runIndex);
                        }
                        else
                        {
                            curSplit.SegmentHistory[runIndex] = historyTime;
                        }
                    }
                }
            }
        }
Пример #13
0
        protected void ProcessFinalSplit(string user, TimeSpan?time, TimingMethod method)
        {
            var run     = Model.CurrentState.Run;
            var segment = run.Last();

            AddSplit(user, segment, time, method);
        }
Пример #14
0
        protected void RemoveNullValues(TimingMethod method)
        {
            var cache = new List <IIndexedTime>();

            for (var runIndex = GetMinSegmentHistoryIndex(); runIndex <= AttemptHistory.Count; runIndex++)
            {
                for (var index = 0; index < Count; index++)
                {
                    var segmentHistoryElement = this[index].SegmentHistory.FirstOrDefault(x => x.Index == runIndex);
                    if (segmentHistoryElement == null)
                    {
                        RemoveItemsFromCache(index, cache);
                    }
                    else if (segmentHistoryElement.Time.RealTime == null && segmentHistoryElement.Time.GameTime == null)
                    {
                        cache.Add(segmentHistoryElement);
                    }
                    else
                    {
                        cache.Clear();
                    }
                }
                RemoveItemsFromCache(Count, cache);
                cache.Clear();
            }
        }
Пример #15
0
 public void FixWithMethod(TimingMethod method)
 {
     FixSegmentHistory(method);
     FixComparisonTimes(method);
     RemoveDuplicates(method);
     RemoveNullValues(method);
 }
Пример #16
0
 public RecentSplitsFile(string path, TimingMethod method, string gameName = null, string categoryName = null)
 {
     GameName = gameName;
     CategoryName = categoryName;
     Path = path;
     LastTimingMethod = method;
 }
        public void Generate(TimingMethod method)
        {
            for (var y = Run.GetMinSegmentHistoryIndex() + 1; y <= Run.AttemptHistory.Count; y++)
            {
                var time = TimeSpan.Zero;

                foreach (var segment in Run)
                {
                    var segmentHistoryElement = segment.SegmentHistory.FirstOrDefault(x => x.Index == y);
                    if (segmentHistoryElement != null)
                    {
                        var segmentTime = segmentHistoryElement.Time[method];
                        if (segmentTime != null)
                        {
                            time += segmentTime.Value;

                            if (segment.Comparisons[Name][method] == null || time < segment.Comparisons[Name][method])
                            {
                                var newTime = new Time(segment.Comparisons[Name]);
                                newTime[method] = time;
                                segment.Comparisons[Name] = newTime;
                            }
                        }
                    }
                    else break;
                }
            }
        }
Пример #18
0
        public void Generate(TimingMethod method)
        {
            var maxIndex = Run.AttemptHistory.Select(x => x.Index).DefaultIfEmpty(0).Max();

            for (var y = Run.GetMinSegmentHistoryIndex(); y <= maxIndex; y++)
            {
                var time = TimeSpan.Zero;

                foreach (var segment in Run)
                {
                    Time segmentHistoryElement;
                    if (segment.SegmentHistory.TryGetValue(y, out segmentHistoryElement))
                    {
                        var segmentTime = segmentHistoryElement[method];
                        if (segmentTime != null)
                        {
                            time += segmentTime.Value;

                            if (segment.Comparisons[Name][method] == null || time < segment.Comparisons[Name][method])
                            {
                                var newTime = new Time(segment.Comparisons[Name]);
                                newTime[method]           = time;
                                segment.Comparisons[Name] = newTime;
                            }
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
Пример #19
0
        public virtual bool SubmitRun(
            IRun run,
            string username, string password, 
            Func<Image> screenShotFunction = null,
            bool attachSplits = false,
            TimingMethod method = TimingMethod.RealTime,
            string gameId = "", string categoryId = "",
            string version = "", string comment = "",
            string video = "",
            params string[] additionalParams)
        {
            try
            {
                if (attachSplits)
                    comment += " " + SplitsIO.Instance.Share(run, screenShotFunction);
                if (gameId == string.Empty)
                    gameId = GetGameIdByName(run.GameName);
                if (categoryId == string.Empty)
                    categoryId = GetCategoryIdByName(gameId, run.CategoryName);
                var json = ASUP.SubmitRun(run, username, password, gameId, categoryId, version, comment, video, additionalParams);
                return json.result == "success";
            }
            catch (Exception e)
            {
                Log.Error(e);

                return false;
            }
        }
Пример #20
0
        private static void FixComparisonTimes(IRun run, TimingMethod method)
        {
            foreach (var comparison in run.CustomComparisons)
            {
                var previousTime = TimeSpan.Zero;
                foreach (var curSplit in run)
                {
                    if (curSplit.Comparisons[comparison][method] != null)
                    {
                        //Prevent comparison times from decreasing from one split to the next
                        if (curSplit.Comparisons[comparison][method] < previousTime)
                        {
                            var newComparison = curSplit.Comparisons[comparison];
                            newComparison[method]            = previousTime;
                            curSplit.Comparisons[comparison] = newComparison;
                        }

                        //Fix Best Segment time if the PB segment is faster
                        var currentSegment = curSplit.Comparisons[comparison][method] - previousTime;
                        if (comparison == Run.PersonalBestComparisonName && (curSplit.BestSegmentTime[method] == null || curSplit.BestSegmentTime[method] > currentSegment))
                        {
                            var newTime = curSplit.BestSegmentTime;
                            newTime[method]          = currentSegment;
                            curSplit.BestSegmentTime = newTime;
                        }
                        previousTime = curSplit.Comparisons[comparison][method].Value;
                    }
                }
            }
        }
Пример #21
0
 private static void PopulatePredictions(IRun run, TimeSpan? currentTime, int segmentIndex, IList<TimeSpan?> predictions, bool simpleCalculation, bool useCurrentRun, TimingMethod method)
 {
     if (currentTime != null)
     {
         PopulatePrediction(predictions, currentTime + run[segmentIndex].BestSegmentTime[method], segmentIndex + 1);
         if (!simpleCalculation)
         {
             foreach (var nullSegment in run[segmentIndex].SegmentHistory.Where(x => !x.Value[method].HasValue))
             {
                 Time segmentTime;
                 if (segmentIndex == 0 
                     || !run[segmentIndex - 1].SegmentHistory.TryGetValue(nullSegment.Key, out segmentTime)
                     || segmentTime[method] != null)
                 {
                     var prediction = TrackBranch(run, currentTime, segmentIndex + 1, nullSegment.Key, method);
                     PopulatePrediction(predictions, prediction.Time[method], prediction.Index);
                 }
             }
         }
         if (useCurrentRun)
         {
             var currentRunPrediction = TrackCurrentRun(run, currentTime, segmentIndex, method);
             PopulatePrediction(predictions, currentRunPrediction.Time[method], currentRunPrediction.Index);
         }
         var personalBestRunPrediction = TrackPersonalBestRun(run, currentTime, segmentIndex, method);
         PopulatePrediction(predictions, personalBestRunPrediction.Time[method], personalBestRunPrediction.Index);
     }
 }
Пример #22
0
 private static void PopulatePredictions(IRun run, TimeSpan? currentTime, int segmentIndex, IList<TimeSpan?> predictions, bool simpleCalculation, bool useCurrentRun, TimingMethod method)
 {
     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 segmentTime = segmentIndex > 0 ? run[segmentIndex - 1].SegmentHistory.FirstOrDefault(x => x.Index == nullSegment.Index) : null;
                 if (segmentTime == null || segmentTime.Time[method] != null)
                 {
                     var prediction = SumOfSegmentsHelper.TrackBranch(run, currentTime, segmentIndex + 1, nullSegment.Index, method);
                     PopulatePrediction(predictions, prediction.Time[method], prediction.Index);
                 }
             }
         }
         if (useCurrentRun)
         {
             var currentRunPrediction = SumOfSegmentsHelper.TrackCurrentRun(run, currentTime, segmentIndex, method);
             PopulatePrediction(predictions, currentRunPrediction.Time[method], currentRunPrediction.Index);
         }
         var personalBestRunPrediction = SumOfSegmentsHelper.TrackPersonalBestRun(run, currentTime, segmentIndex, method);
         PopulatePrediction(predictions, personalBestRunPrediction.Time[method], personalBestRunPrediction.Index);
     }
 }
Пример #23
0
        private static TimeSpan? GetSegmentTimeOrSegmentDelta(LiveSplitState state, int splitNumber, bool useCurrentTime, bool segmentTime, string comparison, TimingMethod method)
        {
            TimeSpan? currentTime;
            if (useCurrentTime)
                currentTime = state.CurrentTime[method];
            else
                currentTime = state.Run[splitNumber].SplitTime[method];
            if (currentTime == null)
                return null;

            for (int x = splitNumber - 1; x >= 0; x--)
            {
                var splitTime = state.Run[x].SplitTime[method];
                if (splitTime != null)
                {
                    if (segmentTime)
                        return currentTime - splitTime;
                    else if (state.Run[x].Comparisons[comparison][method] != null)
                        return (currentTime - state.Run[splitNumber].Comparisons[comparison][method]) - (splitTime - state.Run[x].Comparisons[comparison][method]);
                }
            }

            if (segmentTime)
                return currentTime;
            else
                return currentTime - state.Run[splitNumber].Comparisons[comparison][method];
        }
Пример #24
0
 private static void FixWithMethod(IRun run, TimingMethod method)
 {
     FixSegmentHistory(run, method);
     FixComparisonTimes(run, method);
     RemoveDuplicates(run, method);
     RemoveNullValues(run, method);
 }
Пример #25
0
 protected void FixComparisonTimes(TimingMethod method)
 {
     foreach (var comparison in CustomComparisons)
     {
         var previousTime = TimeSpan.Zero;
         foreach (var curSplit in InternalList)
         {
             if (curSplit.Comparisons[comparison][method] != null)
             {
                 if (curSplit.Comparisons[comparison][method] < previousTime)
                 {
                     var newComparison = new Time(curSplit.Comparisons[comparison]);
                     newComparison[method]            = previousTime;
                     curSplit.Comparisons[comparison] = newComparison;
                 }
                 var currentSegment = curSplit.Comparisons[comparison][method] - previousTime;
                 if (comparison == PersonalBestComparisonName && (curSplit.BestSegmentTime[method] == null || curSplit.BestSegmentTime[method] > currentSegment))
                 {
                     var newTime = new Time(curSplit.BestSegmentTime);
                     newTime[method]          = currentSegment;
                     curSplit.BestSegmentTime = newTime;
                 }
                 previousTime = curSplit.Comparisons[comparison][method].Value;
             }
         }
     }
 }
Пример #26
0
        private static void FixComparisonTimesAndHistory(IRun run, TimingMethod method)
        {
            //Remove negative Best Segment times
            foreach (var curSplit in run)
            {
                if (curSplit.BestSegmentTime[method] < TimeSpan.Zero)
                {
                    var newTime = curSplit.BestSegmentTime;
                    newTime[method]          = null;
                    curSplit.BestSegmentTime = newTime;
                }
            }

            var maxIndex = run.AttemptHistory.Select(x => x.Index).DefaultIfEmpty(0).Max();

            foreach (var curSplit in run)
            {
                var minIndex = curSplit.SegmentHistory.GetMinIndex();
                FixHistoryFromNullBestSegments(curSplit, method, minIndex, maxIndex);
            }

            foreach (var comparison in run.CustomComparisons)
            {
                var previousTime = TimeSpan.Zero;
                foreach (var curSplit in run)
                {
                    if (curSplit.Comparisons[comparison][method] != null)
                    {
                        //Prevent comparison times from decreasing from one split to the next
                        if (curSplit.Comparisons[comparison][method] < previousTime)
                        {
                            var newComparison = curSplit.Comparisons[comparison];
                            newComparison[method]            = previousTime;
                            curSplit.Comparisons[comparison] = newComparison;
                        }

                        //Fix Best Segment time if the PB segment is faster
                        if (comparison == Run.PersonalBestComparisonName)
                        {
                            var currentSegment = curSplit.Comparisons[comparison][method] - previousTime;
                            if (curSplit.BestSegmentTime[method] == null || curSplit.BestSegmentTime[method] > currentSegment)
                            {
                                var newTime = curSplit.BestSegmentTime;
                                newTime[method]          = currentSegment;
                                curSplit.BestSegmentTime = newTime;
                            }
                        }

                        previousTime = curSplit.Comparisons[comparison][method].Value;
                    }
                }
            }

            foreach (var curSplit in run)
            {
                var minIndex = curSplit.SegmentHistory.GetMinIndex();
                FixHistoryFromBestSegmentTimes(curSplit, method, minIndex, maxIndex);
            }
        }
Пример #27
0
 public bool CheckBestSegment(LiveSplitState state, int splitNumber, TimingMethod method)
 {
     if (Settings.ShowBestSegments)
     {
         return(LiveSplitStateHelper.CheckBestSegment(state, splitNumber, method));
     }
     return(false);
 }
Пример #28
0
        protected void AddSplit(string user, ISegment segment, TimeSpan?time, TimingMethod method)
        {
            var comparisonName = SRLComparisonGenerator.GetRaceComparisonName(user);
            var newTime        = new Time(segment.Comparisons[comparisonName]);

            newTime[method] = time;
            segment.Comparisons[comparisonName] = newTime;
        }
Пример #29
0
        public TimedRun(String paramValue,
            TimingMethod timingMethod = TimingMethod.Stopwatch)
        {
            ParamValue = paramValue;

            Method = timingMethod;
            Start();
        }
Пример #30
0
        protected void AddSplit(string user, ISegment segment, TimeSpan?time, TimingMethod method)
        {
            var comparisonName = "[Race] " + user;
            var newTime        = new Time(segment.Comparisons[comparisonName]);

            newTime[method] = time;
            segment.Comparisons[comparisonName] = newTime;
        }
Пример #31
0
        public bool SubmitRun(
            IRun run,
            string username, string password,
            Func <Image> screenShotFunction = null,
            bool attachSplits   = false,
            TimingMethod method = TimingMethod.RealTime,
            string gameId       = "", string categoryId = "",
            string version      = "", string comment    = "",
            string video        = "", params string[] additionalParams)
        {
            if (!IsLoggedIn)
            {
                if (!VerifyLogin())
                {
                    return(false);
                }
            }

            TwitchGame game = null;

            try
            {
                var gameList = FindGame(run.GameName);

                game = gameList.First(twitchGame => twitchGame.Name == run.GameName);
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                bool resolved = false;

                do
                {
                    try
                    {
                        var dialog = new TwitchGameResolveDialog(run.GameName);
                        var result = dialog.ShowDialog();
                        if (result != DialogResult.OK)
                        {
                            return(false);
                        }
                        else if (dialog.Game != null)
                        {
                            game = dialog.Game;
                        }
                        resolved = true;
                    }
                    catch (Exception exc)
                    {
                        Log.Error(exc);
                    }
                } while (!resolved);
            }

            SetStreamTitleAndGame(comment, game);

            return(true);
        }
Пример #32
0
        private static Time parseTime(int? time, TimingMethod timingMethod)
        {
            var parsedTime = new Time();

            if (time.HasValue)
                parsedTime[timingMethod] = TimeSpan.FromMilliseconds(time.Value);

            return parsedTime;
        }
Пример #33
0
 /// <summary>
 /// Gets the last non-live delta in the run starting from splitNumber.
 /// </summary>
 /// <param name="state">The current state.</param>
 /// <param name="splitNumber">The split number to start checking deltas from.</param>
 /// <param name="comparison">The comparison that you are comparing with.</param>
 /// <param name="method">The timing method that you are using.</param>
 /// <returns>Returns the last non-live delta or null if there have been no deltas yet.</returns>
 public static TimeSpan? GetLastDelta(LiveSplitState state, int splitNumber, string comparison, TimingMethod method)
 {
     for (var x = splitNumber; x >= 0; x--)
     {
         if (state.Run[x].Comparisons[comparison][method] != null && state.Run[x].SplitTime[method] != null)
             return state.Run[x].SplitTime[method] - state.Run[x].Comparisons[comparison][method];
     }
     return null;
 }
Пример #34
0
 public RecentSplitsFile(string path, IRun run, TimingMethod method)
     : this(path, method)
 {
     if (run != null)
     {
         GameName = run.GameName;
         CategoryName = run.GetExtendedCategoryName();
     }
 }
Пример #35
0
 public RecentSplitsFile(string path, IRun run, TimingMethod method, string hotkeyProfile)
     : this(path, method, hotkeyProfile)
 {
     if (run != null)
     {
         GameName     = run.GameName;
         CategoryName = run.GetExtendedCategoryName();
     }
 }
Пример #36
0
        protected void ProcessSplit(string user, string segmentName, TimeSpan?time, TimingMethod method)
        {
            var run     = Model.CurrentState.Run;
            var segment = GetMatchingSegment(run, user, segmentName, method, time.HasValue);

            if (segment != null)
            {
                AddSplit(user, segment, time, method);
            }
        }
Пример #37
0
        protected void ProcessSplit(string user, string segmentName, TimeSpan?time, TimingMethod method)
        {
            var run     = Model.CurrentState.Run;
            var segment = run.FirstOrDefault(x => x.Name.Trim().ToLower() == segmentName.Trim().ToLower());

            if (segment != null)
            {
                AddSplit(user, segment, time, method);
            }
        }
        public void Generate(TimingMethod method)
        {
            var allHistory = new List <List <TimeSpan> >();

            foreach (var segment in Run)
            {
                allHistory.Add(new List <TimeSpan>());
            }
            foreach (var attempt in Run.AttemptHistory)
            {
                var ind = attempt.Index;
                var ignoreNextHistory = false;
                foreach (var segment in Run)
                {
                    IIndexedTime history;
                    history = segment.SegmentHistory.FirstOrDefault(x => x.Index == ind);
                    if (history != null)
                    {
                        if (history.Time[method] == null)
                        {
                            ignoreNextHistory = true;
                        }
                        else if (!ignoreNextHistory)
                        {
                            allHistory[Run.IndexOf(segment)].Add(history.Time[method].Value);
                        }
                        else
                        {
                            ignoreNextHistory = false;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
            TimeSpan?totalTime = TimeSpan.Zero;

            for (var ind = 0; ind < Run.Count; ind++)
            {
                var curList = allHistory[ind];
                if (curList.Count == 0)
                {
                    totalTime = null;
                }
                if (totalTime != null)
                {
                    totalTime += CalculateMedian(curList);
                }
                var time = new Time(Run[ind].Comparisons[Name]);
                time[method] = totalTime;
                Run[ind].Comparisons[Name] = time;
            }
        }
Пример #39
0
 public virtual TimeSpan?GetTime(LiveSplitState state, TimingMethod method)
 {
     if (state.CurrentPhase == TimerPhase.NotRunning)
     {
         return(state.Run.Offset);
     }
     else
     {
         return(state.CurrentTime[method]);
     }
 }
Пример #40
0
 public TimeSpan? this[TimingMethod method]
 {
     get { return method == TimingMethod.RealTime ? RealTime : GameTime; }
     set
     {
         if (method == TimingMethod.RealTime)
             RealTime = value;
         else
             GameTime = value;
     }
 }
Пример #41
0
        private static Time parseTime(int?time, TimingMethod timingMethod)
        {
            var parsedTime = new Time();

            if (time.HasValue)
            {
                parsedTime[timingMethod] = TimeSpan.FromMilliseconds(time.Value);
            }

            return(parsedTime);
        }
Пример #42
0
        private static void RemoveDuplicates(IRun run, TimingMethod method)
        {
            var rtaSet = new HashSet <TimeSpan>();
            var igtSet = new HashSet <TimeSpan>();

            foreach (var segment in run)
            {
                rtaSet.Clear();
                igtSet.Clear();

                foreach (var attempt in run.AttemptHistory)
                {
                    var  ind = attempt.Index;
                    Time element;
                    if (segment.SegmentHistory.TryGetValue(ind, out element))
                    {
                        if (element.RealTime != null)
                        {
                            rtaSet.Add(element.RealTime.Value);
                        }
                        if (element.GameTime != null)
                        {
                            igtSet.Add(element.GameTime.Value);
                        }
                    }
                }

                for (var runIndex = segment.SegmentHistory.GetMinIndex(); runIndex <= 0; runIndex++)
                {
                    Time element;
                    if (segment.SegmentHistory.TryGetValue(runIndex, out element))
                    {
                        var isNull   = true;
                        var isUnique = false;
                        if (element.RealTime != null)
                        {
                            isUnique |= rtaSet.Add(element.RealTime.Value);
                            isNull    = false;
                        }
                        if (element.GameTime != null)
                        {
                            isUnique |= igtSet.Add(element.GameTime.Value);
                            isNull    = false;
                        }

                        if (!isUnique && !isNull)
                        {
                            segment.SegmentHistory.Remove(runIndex);
                        }
                    }
                }
            }
        }
Пример #43
0
        /// <summary>
        /// Calculates whether or not the Split Times for the indicated split qualify as a Best Segment.
        /// </summary>
        /// <param name="state">The current state.</param>
        /// <param name="splitNumber">The split to check.</param>
        /// <param name="method">The timing method to use.</param>
        /// <returns>Returns whether or not the indicated split is a Best Segment.</returns>
        public static bool CheckBestSegment(SplitterState state, int splitNumber, TimingMethod method)
        {
            if (state.Run[splitNumber].SplitTime[method] == null)
            {
                return(false);
            }
            var delta       = GetPreviousSegmentDelta(state, splitNumber, BestSegmentsComparisonGenerator.ComparisonName, method);
            var curSegment  = GetPreviousSegmentTime(state, splitNumber, method);
            var bestSegment = state.Run[splitNumber].BestSegmentTime[method];

            return(bestSegment == null || curSegment < bestSegment || delta < TimeSpan.Zero);
        }
Пример #44
0
 private static IDisposable CreateTimer(TimingMethod timingMethod)
 {
     switch (timingMethod)
     {
         case TimingMethod.WallClock:
             return new MyWallTimer();
         case TimingMethod.CPU:
             return new MyCpuTimer();
         default:
             return new NullTimer();
     }
 }
Пример #45
0
 public static TimeSpan? CalculateSumOfBest(IRun run, int startIndex, int endIndex, IList<TimeSpan?> predictions, bool simpleCalculation = false, bool useCurrentRun = true, TimingMethod method = TimingMethod.RealTime)
 {
     int segmentIndex = 0;
     TimeSpan? currentTime = TimeSpan.Zero;
     predictions[startIndex] = TimeSpan.Zero;
     foreach (var segment in run.Skip(startIndex).Take(endIndex - startIndex + 1))
     {
         currentTime = predictions[segmentIndex];
         PopulatePredictions(run, currentTime, segmentIndex, predictions, simpleCalculation, useCurrentRun, method);
         segmentIndex++;
     }
     return predictions[endIndex + 1];
 }
Пример #46
0
        /// <summary>
        /// Runs an action a given number of times.
        /// </summary>
        public static void Run(int numberOfIterations, Action action, Action betweenEachAction = null, TimingMethod timingMethod = TimingMethod.None)
        {
            using (var timer = CreateTimer(timingMethod))
            {
                for (int i = 1; i <= numberOfIterations; i++)
                {
                    action();

                    if (i < numberOfIterations)
                    {
                        betweenEachAction?.Invoke();
                    }
                }
            }
        }
Пример #47
0
 public override TimeSpan? GetTime(Model.LiveSplitState state, TimingMethod method)
 {
     TimeSpan? lastSplit = TimeSpan.Zero;
     var runEndedDelay = state.CurrentPhase == TimerPhase.Ended ? 1 : 0;
     if (state.CurrentSplitIndex > 0 + runEndedDelay)
     {
         if (state.Run[state.CurrentSplitIndex - 1 - runEndedDelay].SplitTime[method] != null)
             lastSplit = state.Run[state.CurrentSplitIndex - 1 - runEndedDelay].SplitTime[method].Value;
         else
             lastSplit = null;
     }
     if (state.CurrentPhase == TimerPhase.NotRunning)
         return state.Run.Offset;
     else
         return state.CurrentTime[method] - lastSplit;
 }
Пример #48
0
 public 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(method, secondSplitTime - firstSplitTime + currentTime), segmentIndex + 1);
         }
         segmentIndex++;
     }
     return new IndexedTime(default(Time), 0);
 }
Пример #49
0
 public static void Clean(IRun run, TimingMethod method, CleanUpCallback callback = null)
 {
     var predictions = new TimeSpan?[run.Count + 1];
     CalculateSumOfBest(run, 0, run.Count - 1, predictions, true, false, method);
     int segmentIndex = 0;
     TimeSpan? currentTime = TimeSpan.Zero;
     foreach (var segment in run)
     {
         currentTime = predictions[segmentIndex];
         foreach (var nullSegment in run[segmentIndex].SegmentHistory.Where(x => !x.Value[method].HasValue))
         {
             var prediction = TrackBranch(run, currentTime, segmentIndex + 1, nullSegment.Key, method);
             CheckPrediction(run, predictions, prediction.Time[method], segmentIndex - 1, prediction.Index - 1, nullSegment.Key, method, callback);
         } 
         segmentIndex++;
     }
 }
        public bool SubmitRun(IRun run, string username, string password, Func<System.Drawing.Image> screenShotFunction = null, bool attachSplits = false, TimingMethod method = TimingMethod.RealTime, string gameId = "", string categoryId = "", string version = "", string comment = "", string video = "", params string[] additionalParams)
        {
            string reason;
            var isValid = SpeedrunCom.ValidateRun(run.Metadata.LiveSplitRun, out reason);

            if (!isValid)
            {
                MessageBox.Show(reason, "Submitting Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return false;
            }

            using (var submitDialog = new SpeedrunComSubmitDialog(run.Metadata))
            {
                var result = submitDialog.ShowDialog();
                return result == DialogResult.OK;
            }
        }
Пример #51
0
 public static IndexedTime TrackBranch(IRun run, TimeSpan? currentTime, int segmentIndex, int runIndex, TimingMethod method = TimingMethod.RealTime)
 {
     while (segmentIndex < run.Count)
     {
         var segmentTime = run[segmentIndex].SegmentHistory.FirstOrDefault(x => x.Index == runIndex);
         if (segmentTime != null)
         {
             var curTime = segmentTime.Time[method];
             if (curTime.HasValue)
             {
                 return new IndexedTime(new Time(method, curTime + currentTime), segmentIndex + 1);
             }
         }
         else break;
         segmentIndex++;
     }
     return new IndexedTime(default(Time), 0);
 }
Пример #52
0
 public static IndexedTime TrackBranch(IRun run, TimeSpan? currentTime, int segmentIndex, int runIndex, TimingMethod method = TimingMethod.RealTime)
 {
     while (segmentIndex < run.Count)
     {
         Time segmentTime;
         if (run[segmentIndex].SegmentHistory.TryGetValue(runIndex, out segmentTime))
         {
             var curTime = segmentTime[method];
             if (curTime.HasValue)
             {
                 return new IndexedTime(new Time(method, curTime + currentTime), segmentIndex + 1);
             }
         }
         else break;
         segmentIndex++;
     }
     return new IndexedTime(default(Time), 0);
 }
Пример #53
0
        private Leaderboard getLeaderboard(
            string uri, int? top = null,
            string platformId = null, string regionId = null,
            EmulatorsFilter emulatorsFilter = EmulatorsFilter.NotSet, bool filterOutRunsWithoutVideo = false,
            TimingMethod? orderBy = null,
            IEnumerable<VariableValue> variableFilters = null,
            LeaderboardEmbeds embeds = default(LeaderboardEmbeds))
        {
            var parameters = new List<string>() { embeds.ToString() };

            if (top.HasValue)
                parameters.Add(string.Format("top={0}", top.Value));
            if (!string.IsNullOrEmpty(platformId))
                parameters.Add(string.Format("platform={0}", Uri.EscapeDataString(platformId)));
            if (!string.IsNullOrEmpty(regionId))
                parameters.Add(string.Format("region={0}", Uri.EscapeDataString(regionId)));
            if (emulatorsFilter != EmulatorsFilter.NotSet)
                parameters.Add(string.Format("emulators={0}",
                    emulatorsFilter == EmulatorsFilter.OnlyEmulators ? "true" : "false"));
            if (filterOutRunsWithoutVideo)
                parameters.Add("video-only=true");
            if (orderBy.HasValue)
            {
                var timing = orderBy.Value.ToAPIString();
                parameters.Add(string.Format("timing={0}", timing));
            }
            if (variableFilters != null)
            {
                foreach (var variableValue in variableFilters)
                {
                    parameters.Add(string.Format("var-{0}={1}",
                        Uri.EscapeDataString(variableValue.VariableID),
                        Uri.EscapeDataString(variableValue.ID)));
                }
            }

            var innerUri = GetLeaderboardsUri(string.Format("{0}{1}",
                uri,
                parameters.ToParameters()));

            var result = baseClient.DoRequest(innerUri);
            return Leaderboard.Parse(baseClient, result.data);
        }
Пример #54
0
 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 = SumOfSegmentsHelper.TrackBranch(run, currentTime, segmentIndex + 1, nullSegment.Index, method);
                 PopulatePrediction(predictions, prediction.Time[method], prediction.Index);
             }
         }
         var currentRunPrediction = SumOfSegmentsHelper.TrackCurrentRun(run, currentTime, segmentIndex, method);
         PopulatePrediction(predictions, currentRunPrediction.Time[method], currentRunPrediction.Index);
         var personalBestRunPrediction = SumOfSegmentsHelper.TrackPersonalBestRun(run, currentTime, segmentIndex, method);
         PopulatePrediction(predictions, personalBestRunPrediction.Time[method], personalBestRunPrediction.Index);
     }
 }
Пример #55
0
 private static void CheckPrediction(IRun run, TimeSpan?[] predictions, TimeSpan? predictedTime, int startingIndex, int endingIndex, int runIndex, TimingMethod method, CleanUpCallback callback)
 {
     if (predictedTime.HasValue && (!predictions[endingIndex + 1].HasValue || predictedTime < predictions[endingIndex + 1].Value))
     {
         var segmentHistoryElement = run[endingIndex].SegmentHistory.FirstOrDefault(x => x.Index == runIndex);
         var parameters = new CleanUpCallbackParameters
         {
             startingSegment = startingIndex >= 0 ? run[startingIndex] : null,
             endingSegment = endingIndex >= 0 ? run[endingIndex] : null,
             timeBetween = segmentHistoryElement.Time[method].Value,
             combinedSumOfBest = predictions[endingIndex + 1].HasValue ? (TimeSpan?)(predictions[endingIndex + 1].Value - predictions[startingIndex + 1].Value) : null,
             attempt = run.AttemptHistory.FirstOrDefault(x => x.Index == runIndex),
             method = method
         };
         if (callback == null || callback(parameters))
         {
             run[endingIndex].SegmentHistory.Remove(segmentHistoryElement);
         }
     }
 }
Пример #56
0
        public Leaderboard GetLeaderboardForFullGameCategory(
            string gameId, string categoryId,
            int? top = null,
            string platformId = null, string regionId = null,
            EmulatorsFilter emulatorsFilter = EmulatorsFilter.NotSet, bool filterOutRunsWithoutVideo = false,
            TimingMethod? orderBy = null,
            IEnumerable<VariableValue> variableFilters = null,
            LeaderboardEmbeds embeds = default(LeaderboardEmbeds))
        {
            var uri = string.Format("/{0}/category/{1}",
                Uri.EscapeDataString(gameId),
                Uri.EscapeDataString(categoryId));

            return getLeaderboard(uri,
                top,
                platformId, regionId,
                emulatorsFilter, filterOutRunsWithoutVideo,
                orderBy, variableFilters,
                embeds);
        }
 public void Generate(TimingMethod method)
 {
     var allHistory = new List<List<TimeSpan>>();
     foreach (var segment in Run)
         allHistory.Add(new List<TimeSpan>());
     foreach (var attempt in Run.AttemptHistory)
     {
         var ind = attempt.Index;
         var ignoreNextHistory = false;
         foreach (var segment in Run)
         {
             IIndexedTime history;
             history = segment.SegmentHistory.FirstOrDefault(x => x.Index == ind);
             if (history != null)
             {
                 if (history.Time[method] == null)
                     ignoreNextHistory = true;
                 else if (!ignoreNextHistory)
                 {
                     allHistory[Run.IndexOf(segment)].Add(history.Time[method].Value);
                 }
                 else ignoreNextHistory = false;
             }
             else ignoreNextHistory = false;
         }
     }
     TimeSpan? totalTime = TimeSpan.Zero;
     for (var ind = 0; ind < Run.Count; ind++)
     {
         var curList = allHistory[ind];
         if (curList.Count == 0)
             totalTime = null;
         if (totalTime != null)
             totalTime += CalculateAverage(curList);
         var time = new Time(Run[ind].Comparisons[Name]);
         time[method] = totalTime;
         Run[ind].Comparisons[Name] = time;
     }
 }
Пример #58
0
        public bool SubmitRun(IRun run, string username, string password, Func<Image> screenShotFunction = null, bool attachSplits = false, TimingMethod method = TimingMethod.RealTime, string gameId = "", string categoryId = "", string version = "", string comment = "", string video = "", params string[] additionalParams)
        {
            using (var dialog = new SaveFileDialog())
            {
                dialog.Filter = "Excel Sheet (*.xlsx)|*.xlsx";
                var result = dialog.ShowDialog();
                if (result == DialogResult.OK)
                {
                    var path = dialog.FileName;

                    if (!File.Exists(path))
                        File.Create(path).Close();
                    using (var stream = File.Open(path, FileMode.Create, FileAccess.Write))
                    {
                        var runSaver = new ExcelRunSaver();
                        runSaver.Save(run, stream);
                        return true;
                    }
                }
            }
            return false;
        }
 public void Generate(TimingMethod method)
 {
     var allHistory = new List<List<TimeSpan>>();
     foreach (var segment in Run)
         allHistory.Add(new List<TimeSpan>());
     foreach (var attempt in Run.AttemptHistory)
     {
         var ind = attempt.Index;
         var ignoreNextHistory = false;
         foreach (var segment in Run)
         {
             Time history;
             if (segment.SegmentHistory.TryGetValue(ind, out history))
             {
                 if (history[method] == null)
                     ignoreNextHistory = true;
                 else if (!ignoreNextHistory)
                 {
                     allHistory[Run.IndexOf(segment)].Add(history[method].Value);
                 }
                 else ignoreNextHistory = false;
             }
             else break;
         }
     }
     TimeSpan? totalTime = TimeSpan.Zero;
     for (var ind = 0; ind < Run.Count; ind++)
     {
         var curList = allHistory[ind];
         if (curList.Count == 0)
             totalTime = null;
         if (totalTime != null)
             totalTime += CalculateMedian(curList);
         var time = new Time(Run[ind].Comparisons[Name]);
         time[method] = totalTime;
         Run[ind].Comparisons[Name] = time;
     }
 }
Пример #60
0
        public bool SubmitRun(IRun run, string username, string password, Func<System.Drawing.Image> screenShotFunction = null, bool attachSplits = false, TimingMethod method = TimingMethod.RealTime, string gameId = "", string categoryId = "", string version = "", string comment = "", string video = "", params string[] additionalParams)
        {
            try
            {
                var image = screenShotFunction();

                using (var dialog = new SaveFileDialog())
                {
                    dialog.Filter = "PNG (*.png)|*.png|JPEG (*.jpeg)|*.jpeg|GIF (*.gif)|*.gif|Bitmap (*.bmp)|*.bmp|TIFF (*.tiff)|*.tiff|WMF (*.wmf)|*.wmf";
                    var result = dialog.ShowDialog();
                    if (result == DialogResult.OK)
                    {
                        image.Save(dialog.FileName);
                        return true;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }
            return false;
        }