public IHttpActionResult CreateTimeSplit(int Id)
        {
            var rental = _context.Rentals.SingleOrDefault(r => r.RentalId == Id);

            if (rental == null)
            {
                return(BadRequest("Invalid Rental"));
            }

            var lastSplit = _context.SplitTimes.OrderByDescending(s => s.SplitTimeId)
                            .Where(s => s.Rental.RentalId == Id)
                            .Take(1)
                            .SingleOrDefault();
            //prevent spamming and split time when rental time under 15 minutes
            var splitSpan = (lastSplit != null) ? DateTime.Now.Subtract(lastSplit.TimeSplit) : DateTime.Now.Subtract(rental.From);

            if (splitSpan.TotalMinutes < 15)
            {
                return(BadRequest("Can't split time when rental time under 15 minutes"));
            }

            var splitTime = new SplitTime
            {
                Rental    = rental,
                TimeSplit = DateTime.Now
            };

            _context.SplitTimes.Add(splitTime);
            _context.SaveChanges();

            return(Json(splitTime));
        }
示例#2
0
        /// <summary>
        /// Get all locations for split
        /// </summary>
        /// <param name="personResult"></param>
        /// <param name="id"></param>
        /// <returns>Task with list of locations</returns>
        protected async Task <List <Location> > GetSplitLocationsForComparison(PersonResult personResult, int?id)
        {
            SplitTime splitTime = personResult.Result.SplitTimes.Where(st => st.SplitID == id).SingleOrDefault();

            if (splitTime == null)
            {
                return(null);
            }

            Path path = await GetSinglePathAsync(p => p.ID == personResult.PathID);

            if (path == null)
            {
                return(null);
            }

            List <Location> SplitSegment = pathAnalysis.InterpolationByDistance(GetSplitPath(path, splitTime), 5);

            if (SplitSegment == null)
            {
                return(null);
            }

            return(SplitSegment);
        }
示例#3
0
        /// <summary>
        /// Get a path trimmed by results
        /// </summary>
        /// <param name="path"></param>
        /// <param name="splitTime"></param>
        /// <returns>List with locations</returns>
        protected List <Location> GetSplitPath(Path path, SplitTime splitTime)
        {
            int startIndex          = pathAnalysis.GetLocationIndex(path, splitTime.Time.AddSeconds(-splitTime.TimeSpan));
            int finishIndex         = pathAnalysis.GetLocationIndex(path, splitTime.Time);
            var interpolationByTime = pathAnalysis.InterpolationByTime(path.Locations, 1);

            List <Location> splitPath = null;

            if (startIndex < 0)
            {
                startIndex = 0;
            }

            if (finishIndex < 0)
            {
                finishIndex = interpolationByTime.Count - 1;
            }

            if (startIndex < finishIndex)
            {
                splitPath = interpolationByTime.GetRange(startIndex, finishIndex - startIndex);
            }

            return(splitPath);
        }
示例#4
0
 public bool Delete(SplitTime splitTime)
 {
     return(template.Execute(
                @"delete from Splittime where racedataId=@racedataId and runNo=@runNo and splittimeNo=@splittimeNo",
                new QueryParameter("@racedataId", splitTime.RaceDataId),
                new QueryParameter("@runNo", splitTime.RunNo),
                new QueryParameter("@splittimeNo", splitTime.SplittimeNo)) >= 1);
 }
示例#5
0
 public static SplitTimeOutDto FromSplitTime(SplitTime splitTime)
 {
     return(new SplitTimeOutDto()
     {
         RunNo = splitTime.RunNo,
         SplitTime = splitTime.Time,
         SplitTimeNo = splitTime.SplittimeNo
     });
 }
示例#6
0
 public bool Update(SplitTime splitTime)
 {
     return(template.Execute(
                @"update Splittime set splittime=@splittime where racedataId=@racedataId and runNo=@runNo and splittimeNo=@splittimeNo",
                new QueryParameter("@splittime", splitTime.Time.ToString("HH:mm:ss.fff")),
                new QueryParameter("@racedataId", splitTime.RaceDataId),
                new QueryParameter("@runNo", splitTime.RunNo),
                new QueryParameter("@splittimeNo", splitTime.SplittimeNo)) == 1);
 }
示例#7
0
 public int Insert(SplitTime splitTime)
 {
     return(template.Execute(
                @"insert into Splittime(racedataId, runNo, splittimeNo, splittime) values (@racedataId, @runNo, @splittimeNo, @splittime); SELECT last_insert_rowid();",
                new QueryParameter("@racedataId", splitTime.RaceDataId),
                new QueryParameter("@runNo", splitTime.RunNo),
                new QueryParameter("@splittimeNo", splitTime.SplittimeNo),
                new QueryParameter("@splittime", splitTime.Time.ToString("HH:mm:ss.fff"))));
 }
示例#8
0
        public void InsertTest()
        {
            var test = new SplitTime
            {
                Time        = DateTime.Now,
                RunNo       = 2,
                SplittimeNo = 7,
                RaceDataId  = 5
            };

            Assert.True(splitTimeDao.Insert(test) > 0);
        }
示例#9
0
        public async Task <IActionResult> GetPath(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            var path = await GetSinglePathAsync(p => p.ID == id);

            if (path == null)
            {
                return(NotFound());
            }

            var personResult = await GetSinglePersonResultAsync(pr => pr.PathID == path.ID);

            if (personResult == null)
            {
                return(NotFound());
            }

            var splitTimeOfAllPath = new SplitTime {
                Time = path.PersonResult.Result.FinishTime, TimeSpan = (path.PersonResult.Result.FinishTime - path.PersonResult.Result.StartTime).Seconds
            };
            var locationsTruncatedByResults = GetSplitPath(path, splitTimeOfAllPath);

            if (locationsTruncatedByResults != null)
            {
                path.Locations = locationsTruncatedByResults;
            }

            var options = new Newtonsoft.Json.JsonSerializerSettings
            {
                MaxDepth              = 1,
                NullValueHandling     = Newtonsoft.Json.NullValueHandling.Ignore,
                ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore,
                DefaultValueHandling  = Newtonsoft.Json.DefaultValueHandling.Ignore
            };

            return(Json(path, options));
        }
示例#10
0
文件: Entry.cs 项目: larnin/Spectrum
        private TimeSpan GetBestSplitTime()
        {
            var fs = new FileSystem(typeof(SplitTimes.Entry));

            var path = Path.Combine(Defaults.PluginDataDirectory, fs.DirectoryPath);

            path = Path.Combine(path, SplitTime.GetSavePath(
                                    G.Sys.GameManager_.Level_,
                                    G.Sys.GameManager_.Mode_,
                                    G.Sys.PlayerManager_.Current_.profile_
                                    ));
            path = Path.Combine(path, "pb.txt");

            if (File.Exists(path))
            {
                try
                {
                    using (var sr = new StreamReader(path))
                    {
                        string[] line;
                        while ((line = sr.ReadLine()?.Split('\t')) != null)
                        {
                            if (line.Length == 2)
                            {
                                return(TimeSpan.Parse("00:" + line[0]));
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Spectrum.Plugins.SplitTracks: Tried to load time from Spectrum.Plugins.SplitTimes and failed. Exception below:\n{ex}");
                }
            }

            return(TimeSpan.Zero);
        }