public static void AnalyseRide(ModelDataContext context, int userId, int rideId) { var speedAchievements = context.SpeedAchievement .Select(row => new MinSpeedAchievement { SpeedAchievementId = row.SpeedAchievementId, MinMph = row.MinMph, Name = row.Name, }) .ToList(); var jumpAchievements = context.JumpAchievement .Select(row => new MinJumpAchievement { JumpAchievementId = row.JumpAchievementId, MinAirtime = row.MinAirtime, Name = row.Name, }) .ToArray(); var rideLocations = AnalyserHelper.GetRideLocations(context, rideId); var rideJumps = AnalyserHelper.GetRideJumps(context, rideId); foreach (var speedAchievement in speedAchievements) { if (speedAchievement.Check(rideLocations)) { UserSpeedAchievement userSpeedAchievement = new UserSpeedAchievement { RideId = rideId, SpeedAchievementId = speedAchievement.SpeedAchievementId, UserId = userId, }; context.UserSpeedAchievement.Add(userSpeedAchievement); context.SaveChanges(); } } foreach (var jumpAchievement in jumpAchievements) { if (jumpAchievement.Check(rideJumps)) { UserJumpAchievement userJumpAchievement = new UserJumpAchievement { RideId = rideId, JumpAchievementId = jumpAchievement.JumpAchievementId, UserId = userId, }; context.UserJumpAchievement.Add(userJumpAchievement); context.SaveChanges(); } } }
private static void Analyse(ModelDataContext context, int userId, int rideId, int segmentId) { var segmentLocations = AnalyserHelper.GetSegmentLocations(context, segmentId); var rideLocations = AnalyserHelper.GetRideLocations(context, rideId); var rideJumps = AnalyserHelper.GetRideJumps(context, rideId); var result = LocationsMatch(segmentLocations.Cast <ILatLng>().ToList(), rideLocations.Cast <ILatLng>().ToList()); if (result.MatchesSegment) { SegmentAttempt attempt = new SegmentAttempt { RideId = rideId, SegmentId = segmentId, UserId = userId, StartUtc = rideLocations[result.StartIdx].Timestamp, EndUtc = rideLocations[result.EndIdx].Timestamp, }; attempt.Medal = (int)GetMedal(context, attempt.EndUtc - attempt.StartUtc, segmentId); context.SegmentAttempt.Add(attempt); context.SaveChanges(); var locations = rideLocations[result.StartIdx..result.EndIdx]