private void Calc1MioMeters(List <IErg> recordErgs, IErg playerErg) { DateTime earliestWorkout = DateTime.Now; foreach (var erg in recordErgs) { if (erg.WorkoutDate != null) { if (erg.WorkoutDate < earliestWorkout) { earliestWorkout = erg.WorkoutDate; } } } TimeSpan overallWorkoutTimeSpan = DateTime.Now - earliestWorkout; var totalDist = recordedTotalDistance; if (playerErg != null) { totalDist += playerErg.Distance; } var progressFactor = 1000000.0 / totalDist; overallWorkoutTimeSpan = TimeSpan.FromTicks((long)(overallWorkoutTimeSpan.Ticks * progressFactor)); DateTime finishDate = DateTime.Now + overallWorkoutTimeSpan; FinishStr = finishDate.ToString("yy-MM-dd HH:mm"); }
private void UpdateRanking(List <IErg> givenErgs, double baseDistance) { List <IErg> tempSortableList = new List <IErg>(); tempSortableList.AddRange(givenErgs); tempSortableList.Sort((x, y) => y.Distance.CompareTo(x.Distance)); //NOTE: Instead of updating the actual values we're clearing and repopulating the whole list each frame. // This is very performance heavy and not the best design. See LaneDisplay for the kind of workaround this causes. RankedErgList.Clear(); RankItem player = null; for (int index = 0; index < tempSortableList.Count; index++) //we need the index, so use a for-loop instead of foreach { IErg erg = tempSortableList[index]; var newRankItem = new RankItem() { Erg = erg, Position = index + 1, BaseDistance = baseDistance, TotalRange = 0.0 }; RankedErgList.Add(newRankItem); if (erg.IsPlayer) { player = newRankItem; } } //get the player and trim the list around him int playerIndex = RankedErgList.IndexOf(player); if (playerIndex < 0) { playerIndex = 0; } RankedErgList = TrimListAroundIndex(RankedErgList, playerIndex, maxErgsInList, false, false); //get the range where we want to display the boats in //we do this after trimming around the index, else we'd care for boats that aren't visible anyways. var totalRange = Math.Abs(RankedErgList.Last().Distance - RankedErgList.First().Distance); if (totalRange > MaxTotalRange) { totalRange = MaxTotalRange; } if (totalRange < MinTotalRange) { totalRange = MinTotalRange; } foreach (var erg in RankedErgList) { erg.TotalRange = totalRange; } }
public void PerformUpdate(IErg playerErg, List <IErg> recordedErgs) { var concatenatedErgs = new List <IErg>(); concatenatedErgs.Add(playerErg); concatenatedErgs.AddRange(recordedErgs); UpdateRanking(concatenatedErgs, playerErg.Distance); NotifyOfPropertyChange(() => RankedErgList); }
private void UpdatePosition(IErg playerErg, List <IErg> recordedErgs) { int numOfBetterErgs = 1; //start at 1, we need to put ourself in the ranking too ;) foreach (IErg erg in recordedErgs) { if (playerErg.Distance < erg.Distance) { numOfBetterErgs++; } } PositionStr = numOfBetterErgs + "/" + (recordedErgs.Count + 1); }
/// <summary> /// Called to initiate an send to the hub /// </summary> /// <param name="performanceMonitor">The performance monitor</param> public async Task BroadcastWorkoutData(IErg performanceMonitor) { if (performanceMonitor == null) { _logger.LogWarning("When requested to send statistics to hub, the performance monitor was null. Returning without sending."); return; } // Send the data await Clients.All.BroadcastWorkoutStatistics(performanceMonitor).ConfigureAwait(false); return; }
internal void PerformUpdate(IErg playerErg, List <IErg> recordedErgs) { UpdatePosition(playerErg, recordedErgs); double totalDistanceDouble = recordedTotalDistance + playerErg.Distance; double totalExTimeDouble = recordedTotalExTime + playerErg.ExerciseTime; double avgPaceDouble = 500.0 / (totalDistanceDouble / totalExTimeDouble); TotalDistanceStr = totalDistanceDouble.ToString("#.") + " m"; TotalExTimeStr = TimeSpan.FromSeconds(totalExTimeDouble).ToString(@"hh\:mm\:ss"); TotalAvgPaceStr = TimeSpan.FromSeconds(avgPaceDouble).ToString(@"mm\:ss\.fff"); Calc1MioMeters(recordedErgs, playerErg); NotifyOfPropertyChange(() => PositionStr); NotifyOfPropertyChange(() => TotalDistanceStr); NotifyOfPropertyChange(() => TotalExTimeStr); NotifyOfPropertyChange(() => TotalAvgPaceStr); NotifyOfPropertyChange(() => FinishStr); }
public ShellViewModel() { DisplayName = "MeVersusMany"; SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED); //init the EventAggregator eventAggregator = new EventAggregator(); eventAggregator.Subscribe(this); //get a connection to the C2 ergometer if (dryRun) { c2erg = new SqliteErg("recordings/session_21-1-19_11-52-27.Kickstarter.db"); //NOTE: use a ghost as primary erg for testing purposes c2erg.IsPlayer = true; } else { c2erg = new C2Erg(); c2erg.IsPlayer = true; } storage = new SqliteWriter(dryRun); //get all recorded sessions string[] databaseFiles = Directory.GetFiles(".", "recordings/*.db"); foreach (var file in databaseFiles) { var sqliteErg = new SqliteErg(file); recordedErgs.Add(sqliteErg); } //init the UI components playerStats = new PlayerStatsViewModel(); overallStats = new OverallStatsViewModel(recordedErgs); ranking = new RankingViewModel(recordedErgs); //subscribe to the WPF Rendering event to get some sort of GameLoop CompositionTarget.Rendering += PerformUpdate; }