private void AddValueEvent(TimeLineStatisticCollection collection, DateTime dt) { if (!_configuring) { //find the indices int boatIndex = _replay.Boats.IndexOf(collection.ReplayBoat); int?legIndex = collection.legIndex; int?tackIndex = collection.tackIndex; //now find the index in our selections list int selectionIndex = 0; for (int i = 0; i < _statistics.Count; i++) { if (_statistics[i].BoatIndex == boatIndex && _statistics[i].LegIndex == legIndex && _statistics[i].TackIndex == tackIndex) { selectionIndex = i; break; } } lock (_curves) { AddPoint(_curves[selectionIndex], dt, collection.GetValue(_statisticName, _unitType, dt)); } //_needsRepaint = true; } }
public DataSet GetFullStatistics(StatisticUnitType unittype) { //get //{ DataSet ds = new DataSet("Statistics"); lock (_boats) { DataTable boats = new DataTable("Boats"); boats.Columns.Add(new DataColumn("id", typeof(int))); boats.Columns.Add(new DataColumn("name", typeof(string))); boats.Columns.Add(new DataColumn("number", typeof(string))); boats.Columns.Add(new DataColumn("color", typeof(System.Drawing.Color))); foreach (ReplayBoat b in _boats) { object[] row = new object[4]; row[0] = b.Id; row[1] = b.Name; row[2] = b.Number; row[3] = b.Color; boats.Rows.Add(row); } ds.Tables.Add(boats); DataTable legs = new DataTable("Legs"); DataColumn dc = legs.Columns.Add("index", typeof(int)); legs.Columns.Add("description", typeof(string)); for (int i = 0; i <= _race.Course.Route.Count; i++) { string description = ""; if (i == 0) { description = "Pre-Start"; } else if (i > 0 && i < _race.Course.Route.Count) { description = i + " " + _race.Course.Route[i - 1].Name + " to " + _race.Course.Route[i].Name; } else if (i == _race.Course.Route.Count) { description = "Post-Finish"; } else { throw new Exception("Invalid Course Leg Reached"); } object[] row = { i, description }; legs.Rows.Add(row); } object[] row2 = { DBNull.Value, "Overall" }; legs.Rows.Add(row2); ds.Tables.Add(legs); DataTable tacks = new DataTable("Tacks"); DataColumn boatId = tacks.Columns.Add("boat_id", typeof(int)); DataColumn legIndex = tacks.Columns.Add("leg_index", typeof(int)); DataColumn tackIndex = tacks.Columns.Add("tack_index", typeof(int)); DataColumn tackname = tacks.Columns.Add("name", typeof(string)); DataTable stats = new DataTable("Statistics"); stats.Columns.Add("boat_id", typeof(int)); DataColumn dc2 = stats.Columns.Add("leg_index", typeof(int)); dc2.AllowDBNull = true; DataColumn dc3 = stats.Columns.Add("tack_index", typeof(int)); dc3.AllowDBNull = true; DataTable statinfo = new DataTable("StatisticInfo"); statinfo.Columns.Add("name", typeof(string)); statinfo.Columns.Add("type", typeof(string)); statinfo.Columns.Add("unit", typeof(string)); statinfo.Columns.Add("description", typeof(string)); TimeLineStatisticCollection example = _boats[0].TotalStatistics; foreach (Type statType in example.StatisticDirectory.Keys) { foreach (string name in example.StatisticDirectory[statType]) { if (!stats.Columns.Contains(name)) { stats.Columns.Add(name, statType /*example[name].GetValue(unittype, _simTime).GetType()*/); object[] info = null; if (unittype == StatisticUnitType.metric) { object[] t = { name, statType.ToString(), example.GetStatisticMetricUnit(statType, name).ToString(), "" }; info = t; } else if (unittype == StatisticUnitType.standard) { object[] t = { name, statType.ToString(), example.GetStatisticStandardUnit(statType, name).ToString(), "" }; info = t; } statinfo.Rows.Add(info); } } } ds.Tables.Add(statinfo); foreach (ReplayBoat b in _boats) { DataRow dr = stats.NewRow(); dr["boat_id"] = b.Id; dr["leg_index"] = System.DBNull.Value; dr["tack_index"] = System.DBNull.Value; TimeLineStatisticCollection fullstats = b.TotalStatistics; foreach (Type t in fullstats.StatisticDirectory.Keys) { foreach (string s in fullstats.StatisticDirectory[t]) { dr[s] = fullstats.GetValue(t, s, _simTime, unittype); } } stats.Rows.Add(dr); List <TimeLineStatisticCollection> legstats = b.LegStatistics; for (int i = 0; i < legstats.Count && i <= b.GetCurrentLeg(_simTime); i++) { DataRow d = stats.NewRow(); d["boat_id"] = b.Id; d["leg_index"] = i; d["tack_index"] = DBNull.Value; foreach (Type t in legstats[i].StatisticDirectory.Keys) { foreach (string s in legstats[i].StatisticDirectory[t]) { d[s] = legstats[i].GetValue(t, s, _simTime, unittype); } } stats.Rows.Add(d); } lock (b.Tacks) { for (int i = 0; i < b.Tacks.Count && i <= b.GetCurrentTack(_simTime); i++) { DataRow d = tacks.NewRow(); d["boat_id"] = b.Id; d["leg_index"] = b.Tacks[i].LegIndex; d["tack_index"] = b.Tacks[i].Index; d["name"] = (b.Tacks[i].IndexOnLeg + 1) + " " + b.Tacks[i].Direction.ToString(); tacks.Rows.Add(d); TimeLineStatisticCollection tackstats = b.TackStatistics[b.Tacks[i].Index]; DataRow td = stats.NewRow(); td["boat_id"] = b.Id; td["leg_index"] = b.Tacks[i].LegIndex; td["tack_index"] = b.Tacks[i].Index; foreach (Type tt in tackstats.StatisticDirectory.Keys) { foreach (string s in tackstats.StatisticDirectory[tt]) { td[s] = tackstats.GetValue(tt, s, _simTime, unittype); } } stats.Rows.Add(td); } } } ds.Tables.Add(stats); ds.Tables.Add(tacks); } return(ds); //} }
private void AddValueEvent(TimeLineStatisticCollection collection, DateTime dt) { if (!_configuring) { //find the indices int boatIndex = _replay.Boats.IndexOf(collection.ReplayBoat); int? legIndex = collection.legIndex; int? tackIndex = collection.tackIndex; //now find the index in our selections list int selectionIndex = 0; for (int i = 0; i < _statistics.Count; i++) { if (_statistics[i].BoatIndex == boatIndex && _statistics[i].LegIndex == legIndex && _statistics[i].TackIndex == tackIndex) { selectionIndex = i; break; } } lock (_curves) { AddPoint(_curves[selectionIndex], dt, collection.GetValue(_statisticName,_unitType,dt)); } //_needsRepaint = true; } }
private void UpdateStatisticGroup(TimeLineStatisticCollection stats, DateTime now,double distance, bool isCurrent) { stats.AddValue<int>("Current Leg",now, _currentMarkIndex.GetValue(now)); stats.AddValue<int>("Current Tack",now, _currentTackIndex.GetValue(now)); stats.AddValue<float>("Speed", now, speed); //stats.AddValue<float>("Speed (10 Second Average)",now, speed); stats.AddValue<float>("VMG to Wind",now, VelocityAgainstWind); stats.AddValue<float>("VMG to Mark",now, VelocityToMark); stats.AddValue<float>("VMG to Course", now, VelocityOnCourse); stats.AddValue<float>("Average VMG to Wind", now, VelocityAgainstWind); stats.AddValue<float>("Average VMG to Mark", now, VelocityToMark); stats.AddValue<float>("Average VMG to Course", now, VelocityOnCourse); stats.AddValue<float>("Distance to Mark",now, DistanceToMark); stats.AddValue<float>("Distance to Course",now, DistanceToStraightCourse); stats.AddValue<float>("Angle to Mark", now, MathHelper.ToDegrees((float)Math.Abs(RelativeAngleToMark))); stats.AddValue<float>("Angle to Wind",now, MathHelper.ToDegrees((float)Math.Abs(RelativeAngleToWind))); stats.AddValue<float>("Angle to Course", now, MathHelper.ToDegrees((float)Math.Abs(RelativeAngleToCourse))); stats.AddValue<float>("Average Speed",now, speed); stats.AddValue<float>("Minimum Speed",now, speed); stats.AddValue<float>("Maximum Speed",now, speed); stats.AddValue<float>("Start Distance to Mark",now, DistanceToMark); stats.AddValue<float>("End Distance to Mark",now, DistanceToMark); stats.AddValue<float>("Average Angle to Wind",now, MathHelper.ToDegrees((float)Math.Abs(RelativeAngleToWind))); stats.AddValue<float>("Average Angle to Course", now, MathHelper.ToDegrees((float)Math.Abs(RelativeAngleToCourse))); stats.AddValue<float>("Distance Covered", now, (float)distance); stats.AddValue<DateTime>("Start Time", now, now); stats.AddValue<DateTime>("End Time", now, now); DateTime start = stats.GetValue<DateTime>("Start Time", now); DateTime end = stats.GetValue<DateTime>("End Time", now); stats.AddValue<TimeSpan>("Elapsed", now, new TimeSpan(end.Ticks - start.Ticks)); }