[Pharo] Personal fitness tracker web app.
MFTSetGroup is now responsible for interpreting the sets it contains.
Changed files
src/MyFitnessTracker/MFTMuscleGroup.class.st
@@ -11,6 +11,18 @@
11
11
#category : #'MyFitnessTracker-Model'
12
12
}
13
13
14
Added:
{ #category : #'as yet unclassified' }
15
Added:
MFTMuscleGroup class >> antagonistIds [
16
Added:
"TODO: is this sufficiently robust ?"
17
Added:
18
Added:
^ {
19
Added:
{ 2. 4 } asSet.
20
Added:
{ 5. 6 } asSet.
21
Added:
{ 8. 9 } asSet.
22
Added:
{ 8. 11 } asSet.
23
Added:
{ 12. 13 } asSet }
24
Added:
]
25
Added:
14
26
{ #category : #'instance creation' }
15
27
MFTMuscleGroup class >> newFromDictionary: aDictionary [
16
28
src/MyFitnessTracker/MFTSQLite3Database.class.st
@@ -122,21 +122,47 @@
122
122
]
123
123
124
124
{ #category : #accessing }
125
Added:
MFTSQLite3Database class >> getAllSetsForUserId: anInteger [
126
Added:
127
Added:
| connection allSetRows sets |
128
Added:
connection := self defaultConnection open.
129
Added:
allSetRows := (connection
130
Added:
execute:
131
Added:
'SELECT s.* FROM Sets s JOIN Workouts w ON s.workout_id = w.id WHERE w.user_id = ?'
132
Added:
value: anInteger) rows.
133
Added:
sets := allSetRows collect: [ :row |
134
Added:
MFTSet newFromDictionary: row asDictionary ].
135
Added:
^ sets
136
Added:
]
137
Added:
138
Added:
{ #category : #accessing }
139
Added:
MFTSQLite3Database class >> getAllWorkoutsForTestUser [
140
Added:
141
Added:
^ self getAllWorkoutsForUserId: 1
142
Added:
]
143
Added:
144
Added:
{ #category : #accessing }
125
145
MFTSQLite3Database class >> getAllWorkoutsForUser: aMFTUser [
126
146
127
Removed:
| connection allRepsRows allWorkoutRows |
147
Added:
^ self getAllWorkoutsForUserId: aMFTUser id
148
Added:
]
149
Added:
150
Added:
{ #category : #accessing }
151
Added:
MFTSQLite3Database class >> getAllWorkoutsForUserId: anInteger [
152
Added:
153
Added:
| connection allWorkoutRows workouts sets |
128
154
connection := self defaultConnection open.
129
155
connection beginTransaction.
130
Removed:
allRepsRows := ((connection execute:
131
Removed:
'SELECT * FROM Workouts WHERE user_id = ?') with:
132
Removed:
{ aMFTUser id }) rows.
133
Removed:
allWorkoutRows := ((connection execute:
134
Removed:
'SELECT * FROM Workouts WHERE user_id = ?')
135
Removed:
with: { aMFTUser id }) rows.
136
Removed:
connection commitTransaction.
137
Removed:
connection close.
138
Removed:
^ Array withAll: (allWorkoutRows collect: [ :row |
139
Removed:
MFTWorkout newFromDictionary: row asDictionary ])
156
Added:
allWorkoutRows := (connection
157
Added:
execute:
158
Added:
'SELECT * FROM Workouts WHERE user_id = ?'
159
Added:
value: anInteger) rows.
160
Added:
workouts := allWorkoutRows collect: [ :row |
161
Added:
MFTWorkout newFromDictionary: row asDictionary ].
162
Added:
sets := self getAllSetsForUserId: anInteger.
163
Added:
workouts do: [ :workout |
164
Added:
workout sets: (sets select: [ :set | set workoutId = workout id ]) ].
165
Added:
^ workouts
140
166
]
141
167
142
168
{ #category : #'as yet unclassified' }
@@ -379,8 +405,8 @@
379
405
with: {
380
406
workoutId.
381
407
aMFTSet exerciseId.
382
Removed:
aMFTSet setGroup.
383
Removed:
aMFTSet setNumber.
408
Added:
aMFTSet number.
409
Added:
aMFTSet group.
384
410
aMFTSet reps.
385
411
aMFTSet load.
386
412
aMFTSet rpe.
src/MyFitnessTracker/MFTSet.class.st
@@ -5,8 +5,8 @@
5
5
'id',
6
6
'workoutId',
7
7
'exerciseId',
8
Removed:
'setGroup',
9
Removed:
'setNumber',
8
Added:
'number',
9
Added:
'group',
10
10
'reps',
11
11
'load',
12
12
'rpe',
@@ -27,20 +27,6 @@
27
27
yourself
28
28
]
29
29
30
Removed:
{ #category : #'as yet unclassified' }
31
Removed:
MFTSet class >> id: id workoutId: workoutId exerciseId: exerciseId setGroup: setGroup setNumber: setNumber reps: reps [
32
Removed:
"These are the fields mandated by the database schema."
33
Removed:
34
Removed:
^ self new
35
Removed:
id: id;
36
Removed:
workoutId: workoutId;
37
Removed:
exerciseId: exerciseId;
38
Removed:
setGroup: setGroup;
39
Removed:
setNumber: setNumber;
40
Removed:
reps: reps;
41
Removed:
yourself
42
Removed:
]
43
Removed:
44
30
{ #category : #'instance creation' }
45
31
MFTSet class >> newFromDictionary: aDictionary [
46
32
@@ -48,8 +34,8 @@
48
34
id: (aDictionary at: 'id');
49
35
workoutId: (aDictionary at: 'workout_id');
50
36
exerciseId: (aDictionary at: 'exercise_id');
51
Removed:
setGroup: (aDictionary at: 'set_group');
52
Removed:
setNumber: (aDictionary at: 'set');
37
Added:
number: (aDictionary at: 'set_number');
38
Added:
group: (aDictionary at: 'set_group');
53
39
reps: (aDictionary at: 'reps');
54
40
rpe: (aDictionary at: 'rpe');
55
41
restAfter: (aDictionary at: 'rest_after');
@@ -65,8 +51,8 @@
65
51
id: 1;
66
52
workoutId: 1;
67
53
exerciseId: 2;
68
Removed:
setGroup: 1;
69
Removed:
setNumber: 1;
54
Added:
group: 1;
55
Added:
number: 1;
70
56
reps: 8;
71
57
load: 20;
72
58
rpe: 8).
@@ -74,8 +60,8 @@
74
60
id: 2;
75
61
workoutId: 1;
76
62
exerciseId: 2;
77
Removed:
setGroup: 1;
78
Removed:
setNumber: 2;
63
Added:
group: 1;
64
Added:
number: 2;
79
65
reps: 8;
80
66
load: 25;
81
67
rpe: 9).
@@ -83,8 +69,8 @@
83
69
id: 3;
84
70
workoutId: 1;
85
71
exerciseId: 2;
86
Removed:
setGroup: 1;
87
Removed:
setNumber: 3;
72
Added:
group: 1;
73
Added:
number: 3;
88
74
reps: 8;
89
75
load: 30;
90
76
rpe: 10) }.
@@ -93,8 +79,8 @@
93
79
id: 4;
94
80
workoutId: 2;
95
81
exerciseId: 3;
96
Removed:
setGroup: 1;
97
Removed:
setNumber: 1;
82
Added:
group: 1;
83
Added:
number: 1;
98
84
reps: 50;
99
85
load: 15;
100
86
rpe: 4).
@@ -102,8 +88,8 @@
102
88
id: 5;
103
89
workoutId: 2;
104
90
exerciseId: 4;
105
Removed:
setGroup: 2;
106
Removed:
setNumber: 2;
91
Added:
group: 2;
92
Added:
number: 2;
107
93
reps: 8;
108
94
load: 25;
109
95
rpe: 6).
@@ -111,8 +97,8 @@
111
97
id: 6;
112
98
workoutId: 2;
113
99
exerciseId: 4;
114
Removed:
setGroup: 2;
115
Removed:
setNumber: 3;
100
Added:
group: 2;
101
Added:
number: 3;
116
102
reps: 8;
117
103
load: 30;
118
104
rpe: 8) }.
@@ -121,8 +107,8 @@
121
107
id: 7;
122
108
workoutId: 3;
123
109
exerciseId: 10;
124
Removed:
setGroup: 1;
125
Removed:
setNumber: 1;
110
Added:
group: 1;
111
Added:
number: 1;
126
112
reps: 5;
127
113
load: 100;
128
114
rpe: 8).
@@ -130,8 +116,8 @@
130
116
id: 8;
131
117
workoutId: 3;
132
118
exerciseId: 11;
133
Removed:
setGroup: 2;
134
Removed:
setNumber: 2;
119
Added:
group: 1;
120
Added:
number: 2;
135
121
reps: 5;
136
122
load: 100;
137
123
rpe: 9).
@@ -139,8 +125,8 @@
139
125
id: 9;
140
126
workoutId: 3;
141
127
exerciseId: 12;
142
Removed:
setGroup: 3;
143
Removed:
setNumber: 3;
128
Added:
group: 2;
129
Added:
number: 3;
144
130
reps: 5;
145
131
load: 100;
146
132
rpe: 10) }.
@@ -217,6 +203,18 @@
217
203
exerciseId := anInteger
218
204
]
219
205
206
Added:
{ #category : #accessing }
207
Added:
MFTSet >> group [
208
Added:
209
Added:
^ group
210
Added:
]
211
Added:
212
Added:
{ #category : #accessing }
213
Added:
MFTSet >> group: anInteger [
214
Added:
215
Added:
group := anInteger
216
Added:
]
217
Added:
220
218
{ #category : #testing }
221
219
MFTSet >> hasLoad [
222
220
@@ -266,6 +264,18 @@
266
264
]
267
265
268
266
{ #category : #accessing }
267
Added:
MFTSet >> number [
268
Added:
269
Added:
^ number
270
Added:
]
271
Added:
272
Added:
{ #category : #accessing }
273
Added:
MFTSet >> number: anInteger [
274
Added:
275
Added:
number := anInteger
276
Added:
]
277
Added:
278
Added:
{ #category : #accessing }
269
279
MFTSet >> reps [
270
280
271
281
^ reps
@@ -299,30 +309,6 @@
299
309
MFTSet >> rpe: anInteger [
300
310
301
311
rpe := anInteger
302
Removed:
]
303
Removed:
304
Removed:
{ #category : #accessing }
305
Removed:
MFTSet >> setGroup [
306
Removed:
307
Removed:
^ setGroup
308
Removed:
]
309
Removed:
310
Removed:
{ #category : #accessing }
311
Removed:
MFTSet >> setGroup: anInteger [
312
Removed:
313
Removed:
setGroup := anInteger
314
Removed:
]
315
Removed:
316
Removed:
{ #category : #accessing }
317
Removed:
MFTSet >> setNumber [
318
Removed:
319
Removed:
^ setNumber
320
Removed:
]
321
Removed:
322
Removed:
{ #category : #accessing }
323
Removed:
MFTSet >> setNumber: anInteger [
324
Removed:
325
Removed:
setNumber := anInteger
326
312
]
327
313
328
314
{ #category : #'as yet unclassified' }
src/MyFitnessTracker/MFTSetGroup.class.st
@@ -2,19 +2,33 @@
2
2
#name : #MFTSetGroup,
3
3
#superclass : #Object,
4
4
#instVars : [
5
Added:
'id',
5
6
'sets'
6
7
],
7
8
#category : #'MyFitnessTracker-Model'
8
9
}
9
10
10
11
{ #category : #accessing }
11
Removed:
MFTSetGroup class >> sets: aMFTSetCollection [
12
Added:
MFTSetGroup class >> id: anInteger sets: aMFTSetCollection [
12
13
13
14
^ self new
15
Added:
id: anInteger;
14
16
sets: aMFTSetCollection;
15
17
yourself
16
18
]
17
19
20
Added:
{ #category : #accessing }
21
Added:
MFTSetGroup >> id [
22
Added:
23
Added:
^ id
24
Added:
]
25
Added:
26
Added:
{ #category : #accessing }
27
Added:
MFTSetGroup >> id: anObject [
28
Added:
29
Added:
id := anObject
30
Added:
]
31
Added:
18
32
{ #category : #initialization }
19
33
MFTSetGroup >> initialize [
20
34
@@ -22,6 +36,24 @@
22
36
sets := OrderedCollection new
23
37
]
24
38
39
Added:
{ #category : #testing }
40
Added:
MFTSetGroup >> isGiantset [
41
Added:
42
Added:
^ self uniqueExercisesInSets >= 4
43
Added:
]
44
Added:
45
Added:
{ #category : #testing }
46
Added:
MFTSetGroup >> isSuperset [
47
Added:
48
Added:
^ self uniqueExercisesInSets = 2
49
Added:
]
50
Added:
51
Added:
{ #category : #testing }
52
Added:
MFTSetGroup >> isTriset [
53
Added:
54
Added:
^ self uniqueExercisesInSets = 3
55
Added:
]
56
Added:
25
57
{ #category : #accessing }
26
58
MFTSetGroup >> sets [
27
59
@@ -32,4 +64,30 @@
32
64
MFTSetGroup >> sets: anObject [
33
65
34
66
sets := anObject
67
Added:
]
68
Added:
69
Added:
{ #category : #initialization }
70
Added:
MFTSetGroup >> type [
71
Added:
72
Added:
self isSuperset ifTrue: [
73
Added:
| ex1 ex2 |
74
Added:
ex1 := sets first exercise primaryMuscleGroupId.
75
Added:
ex2 := sets second exercise primaryMuscleGroupId.
76
Added:
ex1 = ex2 ifTrue: [ ^ 'agonist superset' ].
77
Added:
(MFTMuscleGroup antagonistIds includes: {
78
Added:
ex1.
79
Added:
ex2 } asSet) ifTrue: [ ^ 'antagonist superset' ].
80
Added:
^ 'superset' ].
81
Added:
self isTriset ifTrue: [ ^ 'tri-set' ].
82
Added:
self isGiantset ifTrue: [ ^ 'giant set' ].
83
Added:
^ 'regular set'
84
Added:
]
85
Added:
86
Added:
{ #category : #testing }
87
Added:
MFTSetGroup >> uniqueExercisesInSets [
88
Added:
"I answer the amount of unique exercises in all sets."
89
Added:
90
Added:
| uniqueExerciseIds |
91
Added:
uniqueExerciseIds := (sets collect: #exerciseId) asSet.
92
Added:
^ uniqueExerciseIds size
35
93
]
src/MyFitnessTracker/MFTSetsDialog.class.st
@@ -25,8 +25,8 @@
25
25
(MFTSetDialog new heading: 'Set #' , setsSize asString).
26
26
set ifNil: [ ^ self ].
27
27
set
28
Removed:
setNumber: setsSize;
29
Removed:
setGroup: setsSize.
28
Added:
number: setsSize;
29
Added:
group: setsSize.
30
30
sets add: set
31
31
]
32
32
@@ -108,7 +108,7 @@
108
108
beSmall;
109
109
callback: [ sets add: set afterIndex: (sets indexOf: set) ];
110
110
with: 'Duplicate' ].
111
Removed:
html text: set setNumber asString , ' ' , set setGroup asString ].
111
Added:
html text: set number asString , ' ' , set group asString ].
112
112
html tableData: set exercise englishName.
113
113
html tableData: set reps.
114
114
renderLoad ifTrue: [ html tableData: set load ].
src/MyFitnessTracker/MFTWorkout.class.st
@@ -241,7 +241,11 @@
241
241
{ #category : #accessing }
242
242
MFTWorkout >> setGroups [
243
243
244
Removed:
^ sets groupedBy: #setGroup
244
Added:
| setGroups |
245
Added:
setGroups := OrderedCollection new.
246
Added:
(sets groupedBy: #group) keysAndValuesDo: [ :groupId :group |
247
Added:
setGroups add: (MFTSetGroup id: groupId sets: group) ].
248
Added:
^ setGroups
245
249
]
246
250
247
251
{ #category : #accessing }
@@ -251,9 +255,9 @@
251
255
]
252
256
253
257
{ #category : #accessing }
254
Removed:
MFTWorkout >> sets: anObject [
258
Added:
MFTWorkout >> sets: aMFTSetCollection [
255
259
256
Removed:
sets := anObject
260
Added:
sets := aMFTSetCollection
257
261
]
258
262
259
263
{ #category : #accessing }