简体   繁体   中英

Python sqlite3 - Truly at a loss at how I should structure my database tables

I'm making an application that allows a user to input diet and exercise information, track it over time and output graphs and charts about the data they put in. Right now I'm trying to come up with a structure for just one part(the exercise part).

The first column would be date ( the date of the entries). Then every column after that would be an exercise then how much weight for that exercise, the number of reps they did, and for how many sets. Here's an example of one day that a person might enter.

'date' = '1/13/2014'

'entries = {'Bent Over Row(Barbell)': [['1', '6', '135'], ['1', '5', '155']], 'Deadlift': [['1', '4', '315'], ['1', '2', '315']]}

The exercises would of course change from day to day, and a person wouldn't do all possible exercises in one day.

My Question :

  1. Should I have a column for each exercise in addition to columns for the reps,weight,and sets for that exercise? (4 in total for each exercise).

    Right now I have 20 possible exercises(I intend to add more later) which would be a total of 101 columns in my table including the date column. This seems like it would problematic to work with...am I wrong? Or are tables typically this big? (will probably double soon, to 200+ columns)

  2. How should I deal with exercises in the table the person didn't do that day? Just put 'NULL' or 'N/A'?

  3. How do I deal with a person doing the same exercise in one day? I'm at a complete loss at this one. Let's say that a person does two squats at different weights and reps, I feel like I need to enter in a list of lists to the table. Any better way to do this?

Thanks in advance for any reply.

You should try to make your table structures as flat as possible, ie definitely not a column for each exercise/set/rep. I would suggest two tables:

  1. Exercises (just ID and Name); and
  2. Events (ID, Date, ExerciseID, Sets, Reps, Weight).

You don't need to have entries in Events for every exercise, only the ones the person does, and you can easily group together entries in the table by eg ExerciseID or Date for reporting. If they do the same exercise multiple times in one day that's fine, have multiple entries in Events.

Exercises
---

ID  Name
1   Dead lift 
2   Bent over row (barbell)
...

Events 
---

ID  Date       ExerciseID  Weight  Sets  Reps
1   13/1/2014  2           135     1     6
2   13/1/2014  2           155     1     5
3   13/1/2014  1           315     1     4
...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM