Exemplo n.º 1
0
 public Control[] ControlsForTrainingEntry(TrainingEntry entry)
 {
     return(new Control[] {
         new Label {
             Text = (entry.Date ?? DateTime.MinValue).ToLongDateString(), TextAlign = ContentAlignment.MiddleCenter, Tag = (entry.Date ?? DateTime.MinValue).ToOADate()
         },
         new Label {
             Text = entry.Sport + (entry.TrainingTypeSpecified ? " (" + entry.TrainingType + ")" : ""), TextAlign = ContentAlignment.MiddleCenter, Tag = entry.Sport + (entry.TrainingTypeSpecified ? " (" + entry.TrainingType + ")" : "")
         },
         new Label {
             Text = entry.Duration.ToString(), TextAlign = ContentAlignment.MiddleCenter, Tag = (entry.Duration ?? TimeSpan.Zero).TotalSeconds
         },
         new Label {
             Text = entry.Calories == 0 ? "" : entry.Calories.ToString(), TextAlign = ContentAlignment.MiddleCenter, Tag = entry.Calories ?? 0
         },
         new ZoneDataBox {
             ZoneData = entry.HrZones ?? ZoneData.Empty(), OverlayText = entry.AverageHrSpecified ? '\u00d8' + entry.AverageHr.ToString() : "", Tag = entry.AverageHr ?? 0
         },
         new Label {
             Text = entry.DistanceKm > 0 ? entry.DistanceKm.ToString(CultureInfo.InvariantCulture) : "", TextAlign = ContentAlignment.MiddleCenter, Tag = entry.DistanceM ?? 0
         },
         new Label {
             Text = entry.Feeling == Common.Index.None ? "" : Enum.GetName(typeof(Common.Index), entry.Feeling ?? Common.Index.Count), BackColor = entry.Feeling < Common.Index.Count ? GetColor((double)(entry.Feeling ?? Common.Index.Count) / ((int)Common.Index.Count - 1), Color.Red, Color.Yellow, Color.Green) : _elcTraining.FirstColor, TextAlign = ContentAlignment.MiddleCenter, Tag = entry.Feeling == Common.Index.None ? "" : Enum.GetName(typeof(Common.Index), entry.Feeling ?? Common.Index.Count)
         },
         new Label {
             Text = entry.Note, Tag = entry.Note ?? "", TextAlign = ContentAlignment.MiddleLeft
         }
     });
 }
Exemplo n.º 2
0
 public Control[] ControlsForUnifiedTrainingEntry(TrainingEntry entry)
 {
     return(new Control[] {
         new Label {
             Text = (entry.Date ?? DateTime.MinValue).ToLongDateString(), TextAlign = ContentAlignment.MiddleCenter, Tag = (entry.Date ?? DateTime.MinValue).ToOADate()
         },
         new Label {
             Text = entry.Sport + (entry.TrainingTypeSpecified ? " (" + entry.TrainingType + ")" : "") + " - " + entry.Duration, TextAlign = ContentAlignment.MiddleCenter, Tag = entry.Sport + (entry.TrainingTypeSpecified ? " (" + entry.TrainingType + ")" : "") + " - " + entry.Duration
         },
         new Label {
             Text = entry.Feeling == Common.Index.None ? "" : Enum.GetName(typeof(Common.Index), (entry.Feeling ?? Common.Index.Count)), BackColor = entry.Feeling < Common.Index.Count ? GetColor((double)(entry.Feeling ?? Common.Index.Count) / ((int)Common.Index.Count - 1), Color.Red, Color.Yellow, Color.Green) : _elcUnified.FirstColor, TextAlign = ContentAlignment.MiddleCenter, Tag = entry.Feeling == Common.Index.None ? "" : Enum.GetName(typeof(Common.Index), (entry.Feeling ?? Common.Index.Count))
         },
         new ZoneDataBox {
             ZoneData = entry.HrZones ?? ZoneData.Empty(), OverlayText = entry.AverageHr == 0 ? "" : '\u00d8' + entry.AverageHr.ToString(), Tag = entry.AverageHr > 0 ? entry.AverageHr.ToString() : ""
         },
         new Label {
             Text = entry.DistanceKm > 0 ? entry.DistanceKm.ToString(CultureInfo.InvariantCulture) + " km" : "", TextAlign = ContentAlignment.MiddleCenter, Tag = entry.DistanceKm
         },
         new Label {
             Text = entry.Calories > 0 ? entry.Calories.ToString() + " kcal" : "", BorderStyle = BorderStyle.None, TextAlign = ContentAlignment.MiddleCenter, Tag = entry.Calories
         },
         new Label {
             Text = entry.Note, TextAlign = ContentAlignment.MiddleLeft, Tag = entry.NoteSpecified ? entry.Note : ""
         }
     });
 }
Exemplo n.º 3
0
        private void FillEntryData(TrainingEntry entry)
        {
            ResetForm();

            if (entry.AverageHrSpecified)
            {
                txtAvgHR.Text = entry.AverageHr.ToString();
            }
            if (entry.CaloriesSpecified)
            {
                txtCalories.Text = entry.Calories.ToString();
            }
            if (entry.DateSpecified)
            {
                datDate.Value = entry.Date ?? DateTime.MinValue;
            }
            if (entry.DistanceMSpecified)
            {
                txtDistance.Text = entry.DistanceKm.ToString(CultureInfo.InvariantCulture);
            }
            if (entry.DurationStringSpecified)
            {
                txtDuration.Text = entry.DurationString;
            }
            if (entry.FeelingSpecified)
            {
                comFeeling.Text = Enum.GetName(typeof(Common.Index), entry.Feeling ?? Common.Index.Count);
            }
            if (entry.HrZoneStringSpecified)
            {
                txtZone1.Text = (entry.HrZones ?? ZoneData.Empty()).Zone1.ToString();
                txtZone2.Text = (entry.HrZones ?? ZoneData.Empty()).Zone2.ToString();
                txtZone3.Text = (entry.HrZones ?? ZoneData.Empty()).Zone3.ToString();
                txtZone4.Text = (entry.HrZones ?? ZoneData.Empty()).Zone4.ToString();
                txtZone5.Text = (entry.HrZones ?? ZoneData.Empty()).Zone5.ToString();
            }
            if (entry.NoteSpecified)
            {
                txtNotes.Text = entry.Note;
            }
            if (entry.SportSpecified)
            {
                comSport.Text = Enum.GetName(typeof(Common.Sport), entry.Sport ?? Common.Sport.Count);
            }
            if (entry.TrainingTypeSpecified)
            {
                comTrainingType.Text = Enum.GetName(typeof(Common.TrainingType), entry.TrainingType);
            }
            if (entry.EquipmentNameSpecified)
            {
                comEquipment.Text = entry.Equipment.Name;
            }

            DistanceTimeChanged();
        }
Exemplo n.º 4
0
        protected override void AddEntries()
        {
            // clear old data
            foreach (var s in Series)
            {
                s.Points.Clear();
            }

            var entries = GetEntries();

            if (entries.Length == 0)
            {
                return;
            }

            var data  = new List <TrainingEntry[]>();
            var index = 0;

            foreach (var e in entries)
            {
                if (data.Count != index)
                {
                    // we are currently still in an array
                    if (e.Date.Equals(data[index][0].Date))
                    {
                        // add date to first free item in array
                        var added = false;

                        for (var i = 0; i < data[index].Length; i++)
                        {
                            if (data[index][i] == null)
                            {
                                data[index][i] = (TrainingEntry)e;
                                added          = true;
                                break;
                            }
                        }

                        if (added)
                        {
                            continue;
                        }

                        throw new Exception("PROBABLY need more zonedataseries (too many trainings in one day)");
                    }

                    // get to next index
                    index++;
                }

                // add new array
                data.Add(new TrainingEntry[Series.Count / 5]);
                data[index][0] = (TrainingEntry)e;
            }

            var max = double.MinValue;

            foreach (var tes in data)
            {
                for (var i = 0; i < tes.Length; i++)
                {
                    var sum = 0.0;
                    for (var j = 0; j < 5; j++)
                    {
                        var zd = tes[i] == null ? TimeSpan.Zero : (tes[i].HrZones ?? ZoneData.Empty()).Zones[j];

                        var dp = new DataPoint((tes[0].Date ?? DateTime.MinValue).ToOADate(),
                                               new DateTime(1, 1, 1, zd.Hours, zd.Minutes, zd.Seconds).ToOADate())
                        {
                            ToolTip = tes[i] == null ? "" : tes[i].ToString()
                        };
                        Series["Zone " + (j + 1) + " (" + i + ")"].Points.Add(dp);

                        sum += dp.YValues[0];
                        if (sum > max)
                        {
                            max = sum;
                        }
                    }
                }
            }
            var dt = DateTime.FromOADate(max);

            if (dt.Minute > 30)
            {
                dt = dt.AddHours(1);
            }
            dt = dt.AddMinutes(30 - dt.Minute);
            dt = dt.AddSeconds(-dt.Second);
            ChartAreas[0].AxisY.Maximum = dt.ToOADate();
        }
Exemplo n.º 5
0
        protected override void AddEntries()
        {
            // must add entries manually once _sport is set
            if (_sport == Common.Sport.Count)
            {
                return;
            }

            // clear old data
            foreach (var s in Series)
            {
                s.Points.Clear();
            }

            var entries = GetEntries().Cast <TrainingEntry>().ToArray();

            // totals
            var sumDistance = 0.0;
            var sumTime     = 0.0;

            foreach (var e in entries)
            {
                sumDistance += e.DistanceKm;
                Series["Distance"].Points.Add(new DataPoint((e.Date ?? DateTime.MinValue).ToOADate(), sumDistance));
                if (e.Duration == null)
                {
                    throw new Exception();
                }
                sumTime += e.Duration.Value.TotalHours;
                Series["Time"].Points.Add(new DataPoint((e.Date ?? DateTime.MinValue).ToOADate(), sumTime));
            }

            // training types
            var types = Common.GetTrainingTypes(_sport);
            var trainingTypeColors = Common.GetTrainingTypeColors(_sport);
            var count = new int[types.Length];

            foreach (var e in entries)
            {
                count[Array.IndexOf(types, e.TrainingType)]++;
            }

            for (var i = 0; i < types.Length; i++)
            {
                if (count[i] > 0)
                {
                    Series["Training Types"].Points.Add(new DataPoint(0, count[i])
                    {
                        Label = Enum.GetName(typeof(Common.TrainingType), types[i]) + ": " + count[i] + " (" + Math.Round((double)count[i] / count.Sum() * 100, 1) + "%)", Color = trainingTypeColors[i]
                    });
                }
            }

            // heart rate zones
            var zd = ZoneData.Empty();

            foreach (var e in entries.Where(e => e.HrZones != null))
            {
                for (var i = 0; i < 5; i++)
                {
                    zd.Zones[i] = zd.Zones[i].Add((e.HrZones ?? ZoneData.Empty()).Zones[i]);
                }
            }

            for (var i = 0; i < 5; i++)
            {
                Series["Heart Rate Zones"].Points.Add(new DataPoint(0, zd.Zones[i].TotalHours)
                {
                    Color = ZoneDataBox.ZoneColors[i], Label = "Zone " + (i + 1) + " (" + Math.Round(zd.Zones[i].TotalHours / zd.Duration.TotalHours * 100, 1) + "%):\n" + (zd.Zones[i].Days * 24 + zd.Zones[i].Hours) + "h " + zd.Zones[i].Minutes + "m " + zd.Zones[i].Seconds + "s"
                });
            }

            // monthly training types
            var month = entries.First().Date ?? DateTime.MaxValue;

            month = new DateTime(month.Year, month.Month, 1);
            foreach (var s in Series.Where(s => s.Name.StartsWith("Training Type ")))
            {
                s.Points.Add(new DataPoint(month.ToOADate(), 0));
            }

            foreach (var e in entries)
            {
                if (e.Date == null)
                {
                    throw new Exception();
                }
                if (e.Date.Value.Month != month.Month)
                {
                    // add new dp
                    month = month.AddMonths(1);
                    foreach (var s in Series.Where(s => s.Name.StartsWith("Training Type ")))
                    {
                        s.Points.Add(new DataPoint(month.ToOADate(), 0));
                    }
                }
                Series["Training Type " + e.TrainingType.ToString()].Points.Last().YValues[0]++;
            }

            // monthly training zones
            month = entries.First().Date ?? DateTime.MaxValue;
            month = new DateTime(month.Year, month.Month, 1);
            foreach (var s in Series.Where(s => s.Name.StartsWith("Zone ")))
            {
                s.Points.Add(new DataPoint(month.ToOADate(), 0));
            }

            foreach (var e in entries)
            {
                if (e.Date == null)
                {
                    throw new Exception();
                }
                if (e.HrZones == null)
                {
                    continue;
                }
                if (e.Date.Value.Month != month.Month)
                {
                    // add new dp
                    month = month.AddMonths(1);
                    foreach (var s in Series.Where(s => s.Name.StartsWith("Zone ")))
                    {
                        s.Points.Add(new DataPoint(month.ToOADate(), 0));
                    }
                }

                for (var i = 0; i < 5; i++)
                {
                    Series["Zone " + (i + 1)].Points.Last().YValues[0] += e.HrZones.Value.Zones[i].TotalHours;
                }
            }
        }