Question

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?

Was it helpful?

Solution

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top