View raw

1 " 2 I represent a workout logged against a prescription. 3 " 4 Class { 5 #name : 'MFTWorkoutLog', 6 #superclass : 'MFTObject', 7 #instVars : [ 8 'prescription', 9 'start', 10 'finish', 11 'setGroups' 12 ], 13 #category : 'MyFitnessTracker-Core-Logging', 14 #package : 'MyFitnessTracker-Core', 15 #tag : 'Logging' 16 } 17 18 { #category : 'accessing' } 19 MFTWorkoutLog class >> forPrescription: aMFTWorkoutPrescription [ 20 21 | workoutLog | 22 workoutLog := self new. 23 workoutLog prescription: aMFTWorkoutPrescription. 24 workoutLog setGroups: 25 (aMFTWorkoutPrescription setGroups collect: [ :each | 26 MFTSetGroupLog forPrescription: each ]). 27 ^ workoutLog 28 ] 29 30 { #category : 'accessing' } 31 MFTWorkoutLog >> addSetGroup: aMFTSetGroupLog [ 32 33 setGroups addLast: aMFTSetGroupLog 34 ] 35 36 { #category : 'initialization' } 37 MFTWorkoutLog >> canonicalName [ 38 39 prescription ifNil: [ ^ 'no prescription' ]. 40 ^ prescription canonicalName , ' log' 41 ] 42 43 { #category : 'as yet unclassified' } 44 MFTWorkoutLog >> duration [ 45 46 start ifNil: [ ^ Duration zero ]. 47 finish ifNil: [ ^ DateAndTime now - start ]. 48 ^ finish - start 49 ] 50 51 { #category : 'as yet unclassified' } 52 MFTWorkoutLog >> exercises [ 53 54 ^ self sets collect: #exercise 55 ] 56 57 { #category : 'accessing' } 58 MFTWorkoutLog >> finish [ 59 60 ^ finish 61 ] 62 63 { #category : 'accessing' } 64 MFTWorkoutLog >> finish: aDateAndTime [ 65 66 finish := aDateAndTime 67 ] 68 69 { #category : 'accessing' } 70 MFTWorkoutLog >> finishDate: aDate [ 71 72 | time | 73 time := finish ifNotNil: [ finish asTime ] ifNil: [ start asTime ]. 74 finish := DateAndTime date: aDate time: time 75 ] 76 77 { #category : 'accessing' } 78 MFTWorkoutLog >> finishNow [ 79 80 finish := DateAndTime now 81 ] 82 83 { #category : 'accessing' } 84 MFTWorkoutLog >> finishTime: aTime [ 85 86 | date | 87 date := finish ifNotNil: [ finish asDate ] ifNil: [ start asDate ]. 88 finish := DateAndTime date: date time: aTime 89 ] 90 91 { #category : 'initialization' } 92 MFTWorkoutLog >> initialize [ 93 94 super initialize. 95 setGroups := OrderedCollection new 96 ] 97 98 { #category : 'as yet unclassified' } 99 MFTWorkoutLog >> intensityFactor [ 100 101 | weightedIntensity totalVolume | 102 setGroups ifEmpty: [ ^ 0 ]. 103 104 totalVolume := self volume. 105 totalVolume = 0 ifTrue: [ ^ 0 ]. 106 107 weightedIntensity := setGroups sum: [ :each | 108 each intensityFactor * each volume ]. 109 ^ (weightedIntensity / totalVolume) asFloat round: 1 110 ] 111 112 { #category : 'testing' } 113 MFTWorkoutLog >> isCompletelyLogged [ 114 115 ^ setGroups allSatisfy: #isCompletelyLogged 116 ] 117 118 { #category : 'accessing' } 119 MFTWorkoutLog >> prescription [ 120 121 ^ prescription 122 ] 123 124 { #category : 'accessing' } 125 MFTWorkoutLog >> prescription: aMFTWorkoutPrescription [ 126 127 prescription := aMFTWorkoutPrescription 128 ] 129 130 { #category : 'accessing' } 131 MFTWorkoutLog >> removeSetGroup: aMFTSetGroupLog [ 132 133 setGroups remove: aMFTSetGroupLog 134 ] 135 136 { #category : 'accessing' } 137 MFTWorkoutLog >> setForPrescription: aMFTSetPrescription [ 138 139 ^ self sets 140 detect: [ :set | set prescription = aMFTSetPrescription ] 141 ifNone: [ 142 self error: 'Unknown set prescription for this workout log.' ] 143 ] 144 145 { #category : 'initialization' } 146 MFTWorkoutLog >> setGroups [ 147 148 ^ setGroups 149 ] 150 151 { #category : 'as yet unclassified' } 152 MFTWorkoutLog >> setGroups: aMFTSetGroupLogCollection [ 153 154 setGroups := aMFTSetGroupLogCollection asOrderedCollection 155 ] 156 157 { #category : 'accessing' } 158 MFTWorkoutLog >> setLogForPrescription: aMFTSetPrescription [ 159 160 | groupLog | 161 groupLog := self setGroupLogForPrescription: 162 (self prescription setGroups detect: [ :eachGroup | 163 eachGroup sets includes: aMFTSetPrescription ]). 164 ^ groupLog setLogForPrescription: aMFTSetPrescription 165 ] 166 167 { #category : 'as yet unclassified' } 168 MFTWorkoutLog >> sets [ 169 170 ^ setGroups flatCollect: #sets 171 ] 172 173 { #category : 'accessing' } 174 MFTWorkoutLog >> start [ 175 176 ^ start 177 ] 178 179 { #category : 'accessing' } 180 MFTWorkoutLog >> start: aDateAndTime [ 181 182 start := aDateAndTime 183 ] 184 185 { #category : 'accessing' } 186 MFTWorkoutLog >> startDate: aDate [ 187 188 | time | 189 time := start ifNotNil: [ start asTime ] ifNil: [ Time now ]. 190 start := DateAndTime date: aDate time: time 191 ] 192 193 { #category : 'accessing' } 194 MFTWorkoutLog >> startNow [ 195 196 start := DateAndTime now 197 ] 198 199 { #category : 'accessing' } 200 MFTWorkoutLog >> startTime: aTime [ 201 202 | date | 203 date := start ifNotNil: [ start asDate ] ifNil: [ Date today ]. 204 start := DateAndTime date: date time: aTime 205 ] 206 207 { #category : 'accessing' } 208 MFTWorkoutLog >> volume [ 209 210 ^ setGroups sum: #volume 211 ] 212