示例#1
0
        public async Task <IActionResult> Upload(int?raceID, int?competitorID, IFormFile file)
        {
            if (raceID == null || competitorID == null)
            {
                return(NotFound());
            }
            var race = await _context.Races.SingleOrDefaultAsync(r => r.ID == raceID);

            var competitor = await _context.Person.SingleOrDefaultAsync(r => r.ID == competitorID);

            if (race == null || competitor == null)
            {
                return(NotFound());
            }

            var personResult = await _context.PersonResults.Where(r => r.Person == competitor && r.Race == race).Include(pr => pr.Result).SingleOrDefaultAsync();

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

            if (file.Length > 0)
            {
                var gpxFilePath = System.IO.Path.GetTempFileName();

                using (var stream = System.IO.File.Create(gpxFilePath))
                {
                    await file.CopyToAsync(stream);
                }

                GpxReader       gpxReader = new GpxReader(gpxFilePath);
                Models.GPS.Path path      = gpxReader.Read();

                if (path != null)
                {
                    await GPSManipulationAsync(path, personResult);

                    return(Ok(new { id = path.ID }));
                }
            }
            return(BadRequest());
        }
示例#2
0
        private async Task GPSManipulationAsync(Models.GPS.Path path, PersonResult personResult)
        {
            var interpolated = pathAnalysis.InterpolationByTime(path.Locations, 1);
            var splits       = await _context.SplitTimes.Where(st => st.Result == personResult.Result)
                               .Include(st => st.Split)
                               .ThenInclude(s => s.SecondControl)
                               .ToListAsync();

            double ofsset            = pathAnalysis.GetOffsetFromSplits(splits, interpolated);
            var    completeLocations = pathAnalysis.SetOffset(interpolated, ofsset);

            path.Locations    = null;
            path.PersonResult = personResult;
            _context.Add(path);
            _context.SaveChanges();

            foreach (var cl in completeLocations)
            {
                cl.PathID = path.ID;
            }
            _context.BulkInsert(completeLocations);
        }