View raw

1 " 2 I represent a logged set group attached to a prescribed set group. 3 4 I own the logged sets and any execution-specific group data such as notes. 5 " 6 Class { 7 #name : 'MFTSetGroupLog', 8 #superclass : 'MFTObject', 9 #instVars : [ 10 'prescription', 11 'sets', 12 'notes' 13 ], 14 #category : 'MyFitnessTracker-Core-Logging', 15 #package : 'MyFitnessTracker-Core', 16 #tag : 'Logging' 17 } 18 19 { #category : 'accessing' } 20 MFTSetGroupLog class >> forPrescription: aMFTSetGroupPrescription [ 21 22 ^ self new 23 prescription: aMFTSetGroupPrescription; 24 sets: (aMFTSetGroupPrescription sets collect: [ :each | 25 MFTSetLog forPrescription: each ]) 26 ] 27 28 { #category : 'initialization' } 29 MFTSetGroupLog >> addSet: aMFTSetLog [ 30 31 sets addLast: aMFTSetLog 32 ] 33 34 { #category : 'initialization' } 35 MFTSetGroupLog >> addSet: aMFTSetLog1 before: aMFTsetLog2 [ 36 37 sets add: aMFTSetLog1 before: aMFTsetLog2 38 ] 39 40 { #category : 'initialization' } 41 MFTSetGroupLog >> canonicalName [ 42 43 ^ prescription 44 ifNil: [ 'prescriptionless set group' ] 45 ifNotNil: [ prescription canonicalName ] 46 ] 47 48 { #category : 'accessing' } 49 MFTSetGroupLog >> indexOfSet: aMFTSetLog [ 50 51 ^ sets indexOf: aMFTSetLog 52 ] 53 54 { #category : 'initialization' } 55 MFTSetGroupLog >> initialize [ 56 57 super initialize. 58 sets := OrderedCollection new. 59 notes := String new 60 ] 61 62 { #category : 'as yet unclassified' } 63 MFTSetGroupLog >> intensityFactor [ 64 65 | weightedIntensity totalVolume | 66 sets ifEmpty: [ ^ 0 ]. 67 68 totalVolume := self volume. 69 totalVolume = 0 ifTrue: [ ^ 0 ]. 70 71 weightedIntensity := sets sum: [ :each | 72 each intensityFactor * each volume ]. 73 ^ (weightedIntensity / totalVolume) asFloat round: 1 74 ] 75 76 { #category : 'initialization' } 77 MFTSetGroupLog >> isCompletelyLogged [ 78 79 ^ sets allSatisfy: #isLogged 80 ] 81 82 { #category : 'initialization' } 83 MFTSetGroupLog >> notes [ 84 85 ^ notes 86 ] 87 88 { #category : 'initialization' } 89 MFTSetGroupLog >> notes: aString [ 90 91 notes := aString 92 ] 93 94 { #category : 'initialization' } 95 MFTSetGroupLog >> prescription [ 96 97 ^ prescription 98 ] 99 100 { #category : 'initialization' } 101 MFTSetGroupLog >> prescription: aMFTSetGroupPrescription [ 102 103 prescription := aMFTSetGroupPrescription 104 ] 105 106 { #category : 'removing' } 107 MFTSetGroupLog >> removeSet: aMFTSetLog [ 108 109 sets remove: aMFTSetLog 110 ] 111 112 { #category : 'initialization' } 113 MFTSetGroupLog >> setLogForPrescription: aMFTSetPrescription [ 114 115 ^ sets 116 detect: [ :each | each prescription == aMFTSetPrescription ] 117 ifNone: [ self error: 'Unknown set prescription for this group.' ] 118 ] 119 120 { #category : 'initialization' } 121 MFTSetGroupLog >> sets [ 122 123 ^ sets 124 ] 125 126 { #category : 'initialization' } 127 MFTSetGroupLog >> sets: aMFTSetLogCollection [ 128 129 sets := aMFTSetLogCollection 130 ] 131 132 { #category : 'as yet unclassified' } 133 MFTSetGroupLog >> setsGroupedByExercise [ 134 135 ^ sets groupedBy: #exercise 136 ] 137 138 { #category : 'testing' } 139 MFTSetGroupLog >> uniqueExercisesInSets [ 140 141 ^ prescription uniqueExercisesInSets 142 ] 143 144 { #category : 'initialization' } 145 MFTSetGroupLog >> volume [ 146 147 ^ sets sum: #volume 148 ] 149