1

I am currently writing a program that takes in data regarding exercise. The variables are

Exercise - Ex) Bench Press

Date - Ex) 08/12/13

Reps - Ex) 10

Weight - Ex) 135

Sets at weight - Ex) 3

Rest Time - Ex) 120 (in seconds)

Body weight at date - Ex) 200

I am importing from a CSV file. I've parsed the data and have it so that it gives me a class that's set up as such

    Public Class WorkoutInformation
   {
   public string Exercise{get;set;}
   public List<DateTime> date; 
   public List<dynamic> sets {get;set;}
   public List<dynamic> reps {get; set;}
   public List<dynamic> weight {get;set;}
   public List<dynamic> restTime {get; set;}
   public List<dynamic> bodyWeight {get;set;}

}

So here is my problem. I am finding that when I plot these that the dates are not getting sorted and I would like the earlier days to be shown first. So I've been sorting my List<WorkoutInformation>. But I am finding that this leaves me vulnerable to losing which dates go with which weights, or reps, or other information. My question then is how do I create a class where I can access information like a list Ex) MyList.date[i] but when I change the index of MyList.date[i] all the other pieces of information are appropriately indexed with it?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
user2023068
  • 435
  • 1
  • 6
  • 14
  • 2
    Why do many of your lists utilize dynamics? It seems that using the appropriate types would be better – David L Jan 29 '13 at 20:32
  • I've done that because some of the inputs may not be int's, an example is if someone is doing a set of 10 but get's to 6 then takes a 10 second breaks and finishes the last 4. I am accounting for that in how the user inputs their data into the CSV file. So that data point's reps would not be 10 it would be 6x4x10 meaning 6 reps, 4 reps, 10 seconds in between. Or something close to that. – user2023068 Jan 30 '13 at 16:19
  • You should always know your expected input types. If they aren't ints but strings, then parse them on the way in. That, or make them the correct data type. You're just causing yourself unnecessary pain by using dynamics when you don't need them – David L Jan 30 '13 at 16:21

1 Answers1

1

A better design might be to create a class that holds one session of data for you:

public class WorkOutSession
{
    public string Exercise { get; set; }
    public DateTime Date { get; set; }
    public int Sets { get; set; }
    public int Reps { get; set; }
    public int Weight { get; set; }
    public int RestTime { get; set; }
    public int BodyWeight { get; set; }
}

public class WorkOutInformation
{
    public List<WorkOutSession> Sessions { get; set; }
}

With that design, you can sort your Sessions list by date and all of the data for the session will stay associated:

var sessionsByDate = Sessions.OrderBy(s => s.Date);
itsme86
  • 19,266
  • 4
  • 41
  • 57