/// <summary> /// get all avrages for every statistic /// </summary> /// <returns> /// returns a BikeStatEvent with all the avrages for every statistic. If there is no avrage available for a /// statistic "NaN" will be returned for that specific statistic /// </returns> public BikeStatEvent getAverage() { var bikeStatEvent = new BikeStatEvent(BikeStatEvent.StatTypes.AVERAGE_STATISTICS); foreach (StatName naam in Enum.GetValues(typeof(StatName))) { bikeStatEvent.values[(int)naam] = Math.Floor(average(naam)); } bikeStatEvent.source = source; return(bikeStatEvent); }
/// <summary> /// get all the latest data for every stat /// </summary> /// <returns> returns a BikeStatEvent with the latest know data for every statistic</returns> public BikeStatEvent getLatest() { var bikeStatEvent = new BikeStatEvent(BikeStatEvent.StatTypes.CURRENT_STATISTICS); foreach (StatName naam in Enum.GetValues(typeof(StatName))) { double last = 0; if ((getAll(naam) != null) && (getAll(naam).Count > 0)) { last = getAll(naam).Last(); } bikeStatEvent.values[(int)naam] = last; } return(bikeStatEvent); }
/// <summary> /// Stores data from the bike in the stats dictionary /// </summary> /// <param name="sender"> object that send the data</param> /// <param name="e">command that was send</param> private void addStat(string data) { // switch to process return statements. if (data.Contains("ACK") || data.Contains("RUN") || data.Contains("ERROR")) { return; } var statE = new BikeStatEvent(BikeStatEvent.StatTypes.CURRENT_STATISTICS); var dict = getValuesFromInput(data); foreach (var name in dict.Keys) { double value = 0; dict.TryGetValue(name, out value); stats.addResult(name, value); statE.values[(int)name] = value; } newStats.Invoke(statE); }