|
1
|
|
|
package com.osomapps.pt.admin.program; |
|
2
|
|
|
|
|
3
|
|
|
import com.osomapps.pt.dictionary.DictionaryName; |
|
4
|
|
|
import com.osomapps.pt.dictionary.DictionaryService; |
|
5
|
|
|
import com.osomapps.pt.exercises.Exercise; |
|
6
|
|
|
import com.osomapps.pt.exercises.ExerciseRepository; |
|
7
|
|
|
import com.osomapps.pt.programs.InProgram; |
|
8
|
|
|
import com.osomapps.pt.programs.InProgramRepository; |
|
9
|
|
|
import com.osomapps.pt.programs.InWarmupWorkoutItem; |
|
10
|
|
|
import com.osomapps.pt.programs.InWarmupWorkoutItemRepository; |
|
11
|
|
|
import com.osomapps.pt.programs.InWorkout; |
|
12
|
|
|
import com.osomapps.pt.programs.InWorkoutItem; |
|
13
|
|
|
import com.osomapps.pt.programs.InWorkoutItemSet; |
|
14
|
|
|
import com.osomapps.pt.programs.InWorkoutRepository; |
|
15
|
|
|
import com.osomapps.pt.programs.ParseExercise; |
|
16
|
|
|
import com.osomapps.pt.programs.ParseProgram; |
|
17
|
|
|
import com.osomapps.pt.programs.ParseProgramRepository; |
|
18
|
|
|
import com.osomapps.pt.programs.ParseRound; |
|
19
|
|
|
import com.osomapps.pt.programs.ParseWorkout; |
|
20
|
|
|
import com.osomapps.pt.programs.ParseWorkoutItem; |
|
21
|
|
|
import com.osomapps.pt.programs.ParseWorkoutItemSet; |
|
22
|
|
|
import com.osomapps.pt.reportworkout.InWorkoutItemRepository; |
|
23
|
|
|
import com.osomapps.pt.reportworkout.InWorkoutItemSetRepository; |
|
24
|
|
|
import com.osomapps.pt.token.InUser; |
|
25
|
|
|
import com.osomapps.pt.token.InUserGoal; |
|
26
|
|
|
import java.util.ArrayList; |
|
27
|
|
|
import java.util.Arrays; |
|
28
|
|
|
import java.util.Collections; |
|
29
|
|
|
import java.util.List; |
|
30
|
|
|
import java.util.Objects; |
|
31
|
|
|
import java.util.Optional; |
|
32
|
|
|
import java.util.concurrent.atomic.AtomicInteger; |
|
33
|
|
|
import java.util.stream.Collectors; |
|
34
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
35
|
|
|
import org.springframework.data.domain.Sort; |
|
36
|
|
|
import org.springframework.stereotype.Service; |
|
37
|
|
|
|
|
38
|
|
|
@Slf4j |
|
39
|
|
|
@Service |
|
40
|
|
|
public class AdminProgramAssignService { |
|
41
|
|
|
|
|
42
|
|
|
private final InProgramRepository inProgramRepository; |
|
43
|
|
|
private final InWorkoutRepository inWorkoutRepository; |
|
44
|
|
|
private final InWorkoutItemRepository inWorkoutItemRepository; |
|
45
|
|
|
private final InWorkoutItemSetRepository inWorkoutItemSetRepository; |
|
46
|
|
|
private final ParseProgramRepository parseProgramRepository; |
|
47
|
|
|
private final InWarmupWorkoutItemRepository inWarmupWorkoutItemRepository; |
|
48
|
|
|
private final DictionaryService dictionaryService; |
|
49
|
|
|
private final ExerciseRepository exerciseRepository; |
|
50
|
|
|
|
|
51
|
|
|
AdminProgramAssignService( |
|
|
|
|
|
|
52
|
|
|
InProgramRepository inProgramRepository, |
|
53
|
|
|
InWorkoutRepository inWorkoutRepository, |
|
54
|
|
|
InWorkoutItemRepository inWorkoutItemRepository, |
|
55
|
|
|
InWorkoutItemSetRepository inWorkoutItemSetRepository, |
|
56
|
|
|
ParseProgramRepository parseProgramRepository, |
|
57
|
|
|
InWarmupWorkoutItemRepository inWarmupWorkoutItemRepository, |
|
58
|
|
|
DictionaryService dictionaryService, |
|
59
|
|
|
ExerciseRepository exerciseRepository) { |
|
60
|
|
|
this.inProgramRepository = inProgramRepository; |
|
61
|
|
|
this.inWorkoutRepository = inWorkoutRepository; |
|
62
|
|
|
this.inWorkoutItemRepository = inWorkoutItemRepository; |
|
63
|
|
|
this.inWorkoutItemSetRepository = inWorkoutItemSetRepository; |
|
64
|
|
|
this.parseProgramRepository = parseProgramRepository; |
|
65
|
|
|
this.inWarmupWorkoutItemRepository = inWarmupWorkoutItemRepository; |
|
66
|
|
|
this.dictionaryService = dictionaryService; |
|
67
|
|
|
this.exerciseRepository = exerciseRepository; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
public InUser assign(InUser inUser) { |
|
71
|
|
|
|
|
72
|
|
|
List<ParseProgram> parsePrograms = |
|
73
|
|
|
parseProgramRepository.findAll(Sort.by(Sort.Direction.DESC, "id")); |
|
74
|
|
|
if (parsePrograms.isEmpty()) { |
|
75
|
|
|
log.warn("There are no programs found."); |
|
76
|
|
|
return inUser; |
|
77
|
|
|
} |
|
78
|
|
|
Optional<Integer> userGroup = getUserGroup(inUser); |
|
79
|
|
|
if (!userGroup.isPresent()) { |
|
80
|
|
|
log.warn( |
|
81
|
|
|
"User group not recognized, level - {}, gender - {}", |
|
82
|
|
|
inUser.getD_level(), |
|
83
|
|
|
inUser.getD_sex()); |
|
84
|
|
|
return inUser; |
|
85
|
|
|
} |
|
86
|
|
|
if (inUser.getInUserGoals().isEmpty()) { |
|
87
|
|
|
log.warn("Cannot create program for user without goals."); |
|
88
|
|
|
return inUser; |
|
89
|
|
|
} |
|
90
|
|
|
List<ParseRound> parseRounds = |
|
91
|
|
|
getRoundsGorGoalAndUserGroup( |
|
92
|
|
|
parsePrograms, inUser.getInUserGoals().get(0), userGroup.get()); |
|
93
|
|
|
final List<ParseWorkout> parseWorkouts; |
|
94
|
|
|
final List<String> goalNames = new ArrayList<>(); |
|
95
|
|
|
if (!parseRounds.isEmpty()) { |
|
96
|
|
|
goalNames.add(parseRounds.get(0).getParseUserGroup().getParseGoal().getName()); |
|
97
|
|
|
} |
|
98
|
|
|
if (inUser.getInUserGoals().size() > 1) { |
|
99
|
|
|
List<ParseRound> parseRounds2 = |
|
100
|
|
|
getRoundsGorGoalAndUserGroup( |
|
101
|
|
|
parsePrograms, inUser.getInUserGoals().get(1), userGroup.get()); |
|
102
|
|
|
parseWorkouts = |
|
103
|
|
|
mergeLists(getParseWorkouts(parseRounds), getParseWorkouts(parseRounds2)); |
|
104
|
|
|
if (!parseRounds2.isEmpty()) { |
|
105
|
|
|
goalNames.add(parseRounds2.get(0).getParseUserGroup().getParseGoal().getName()); |
|
106
|
|
|
} |
|
107
|
|
|
} else { |
|
108
|
|
|
parseWorkouts = getParseWorkouts(parseRounds); |
|
109
|
|
|
} |
|
110
|
|
|
final AtomicInteger index = new AtomicInteger(-1); |
|
111
|
|
|
final InProgram inProgram = |
|
112
|
|
|
new InProgram() |
|
113
|
|
|
.setName("Test program for user " + inUser.getId()) |
|
114
|
|
|
.setCurrent_workout_index(getCurrentWorkoutIndex(inUser, parseWorkouts)) |
|
115
|
|
|
.setInWorkouts( |
|
116
|
|
|
parseWorkouts.stream() |
|
117
|
|
|
.map( |
|
118
|
|
|
parseWorkout -> |
|
119
|
|
|
new InWorkout() |
|
120
|
|
|
.setD_workout_name( |
|
121
|
|
|
parseWorkout.getName()) |
|
122
|
|
|
.setWorkout_index( |
|
123
|
|
|
index.incrementAndGet()) |
|
124
|
|
|
.setPart_name( |
|
125
|
|
|
parseWorkout |
|
126
|
|
|
.getParsePart() |
|
127
|
|
|
.getName()) |
|
128
|
|
|
.setGoal_index( |
|
129
|
|
|
goalNames.indexOf( |
|
130
|
|
|
parseWorkout |
|
131
|
|
|
.getParsePart() |
|
132
|
|
|
.getParseRound() |
|
133
|
|
|
.getParseUserGroup() |
|
134
|
|
|
.getParseGoal() |
|
135
|
|
|
.getName())) |
|
136
|
|
|
.setInWarmupWorkoutItems( |
|
137
|
|
|
parseWorkout |
|
138
|
|
|
.getParseWarmupWorkoutItems() |
|
139
|
|
|
.stream() |
|
140
|
|
|
.map( |
|
141
|
|
|
parseWarmupWorkoutItem -> |
|
142
|
|
|
new InWarmupWorkoutItem() |
|
143
|
|
|
.setD_exercise_name( |
|
144
|
|
|
parseWarmupWorkoutItem |
|
145
|
|
|
.getName()) |
|
146
|
|
|
.setExercise_id( |
|
147
|
|
|
parseWarmupWorkoutItem |
|
148
|
|
|
.getExercise_id()) |
|
149
|
|
|
.setTime_in_sec( |
|
150
|
|
|
minToSec( |
|
151
|
|
|
parseWarmupWorkoutItem |
|
152
|
|
|
.getTime_in_min())) |
|
153
|
|
|
.setSpeed( |
|
154
|
|
|
parseWarmupWorkoutItem |
|
155
|
|
|
.getSpeed()) |
|
156
|
|
|
.setIncline( |
|
157
|
|
|
parseWarmupWorkoutItem |
|
158
|
|
|
.getIncline())) |
|
159
|
|
|
.collect( |
|
160
|
|
|
Collectors |
|
161
|
|
|
.toList())) |
|
162
|
|
|
.setInWorkoutItems( |
|
163
|
|
|
parseWorkout |
|
164
|
|
|
.getParseWorkoutItems() |
|
165
|
|
|
.stream() |
|
166
|
|
|
.map( |
|
167
|
|
|
parseWorkoutItem -> |
|
168
|
|
|
new InWorkoutItem() |
|
169
|
|
|
.setD_exercise_name( |
|
170
|
|
|
parseWorkoutItem |
|
171
|
|
|
.getName()) |
|
172
|
|
|
.setExercise_id( |
|
173
|
|
|
parseWorkoutItem |
|
174
|
|
|
.getExercise_id()) |
|
175
|
|
|
.setD_exercise_type( |
|
176
|
|
|
getExerciseType( |
|
177
|
|
|
parseWorkoutItem)) |
|
178
|
|
|
.setInWorkoutItemSets( |
|
179
|
|
|
parseWorkoutItem |
|
180
|
|
|
.getParseWorkoutItemSets() |
|
181
|
|
|
.stream() |
|
182
|
|
|
.map( |
|
183
|
|
|
parseWorkoutItemSet -> |
|
184
|
|
|
generateInWorkoutItemSet( |
|
185
|
|
|
parseWorkoutItemSet, |
|
186
|
|
|
parsePrograms |
|
187
|
|
|
.get( |
|
188
|
|
|
0) |
|
189
|
|
|
.getParseExercises(), |
|
190
|
|
|
inUser |
|
191
|
|
|
.getWeight())) |
|
192
|
|
|
.collect( |
|
193
|
|
|
Collectors |
|
194
|
|
|
.toList())) |
|
195
|
|
|
.setInWorkoutItemReports( |
|
196
|
|
|
Collections |
|
197
|
|
|
.emptyList())) |
|
198
|
|
|
.collect( |
|
199
|
|
|
Collectors |
|
200
|
|
|
.toList()))) |
|
201
|
|
|
.collect(Collectors.toList())); |
|
202
|
|
|
inProgram.setInUser(inUser); |
|
203
|
|
|
inProgram |
|
204
|
|
|
.getInWorkouts() |
|
205
|
|
|
.forEach( |
|
206
|
|
|
inWorkout -> { |
|
207
|
|
|
inWorkout.setInProgram(inProgram); |
|
208
|
|
|
inWorkout |
|
209
|
|
|
.getInWarmupWorkoutItems() |
|
210
|
|
|
.forEach( |
|
211
|
|
|
inWarmupWorkoutItem -> { |
|
|
|
|
|
|
212
|
|
|
inWarmupWorkoutItem.setInWorkout(inWorkout); |
|
213
|
|
|
}); |
|
214
|
|
|
inWorkout |
|
215
|
|
|
.getInWorkoutItems() |
|
216
|
|
|
.forEach( |
|
217
|
|
|
inWorkoutItem -> { |
|
218
|
|
|
inWorkoutItem.setInWorkout(inWorkout); |
|
219
|
|
|
inWorkoutItem |
|
220
|
|
|
.getInWorkoutItemSets() |
|
221
|
|
|
.forEach( |
|
222
|
|
|
inWorkoutItemSet -> { |
|
|
|
|
|
|
223
|
|
|
inWorkoutItemSet |
|
224
|
|
|
.setInWorkoutItem( |
|
225
|
|
|
inWorkoutItem); |
|
226
|
|
|
}); |
|
227
|
|
|
}); |
|
228
|
|
|
}); |
|
229
|
|
|
inProgramRepository.save(inProgram); |
|
230
|
|
|
inWorkoutRepository.saveAll(inProgram.getInWorkouts()); |
|
231
|
|
|
inProgram |
|
232
|
|
|
.getInWorkouts() |
|
233
|
|
|
.forEach( |
|
234
|
|
|
inWorkout -> { |
|
235
|
|
|
inWarmupWorkoutItemRepository.saveAll( |
|
236
|
|
|
inWorkout.getInWarmupWorkoutItems()); |
|
237
|
|
|
inWorkoutItemRepository.saveAll(inWorkout.getInWorkoutItems()); |
|
238
|
|
|
inWorkout |
|
239
|
|
|
.getInWorkoutItems() |
|
240
|
|
|
.forEach( |
|
241
|
|
|
inWorkoutItem -> { |
|
|
|
|
|
|
242
|
|
|
inWorkoutItemSetRepository.saveAll( |
|
243
|
|
|
inWorkoutItem.getInWorkoutItemSets()); |
|
244
|
|
|
}); |
|
245
|
|
|
}); |
|
246
|
|
|
return inUser; |
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
|
|
int getCurrentWorkoutIndex(InUser inUser, List<ParseWorkout> parseWorkouts) { |
|
250
|
|
|
if (inUser.getInPrograms() == null || inUser.getInPrograms().isEmpty()) { |
|
251
|
|
|
return 0; |
|
252
|
|
|
} |
|
253
|
|
|
final InProgram inProgram = inUser.getInPrograms().get(inUser.getInPrograms().size() - 1); |
|
254
|
|
|
if (parseWorkouts.isEmpty() || parseWorkouts.size() != inProgram.getInWorkouts().size()) { |
|
255
|
|
|
return 0; |
|
256
|
|
|
} |
|
257
|
|
|
final InWorkout inWorkout = |
|
258
|
|
|
inProgram.getInWorkouts().get(inProgram.getCurrent_workout_index()); |
|
259
|
|
|
if (parseWorkouts |
|
260
|
|
|
.get(inProgram.getCurrent_workout_index()) |
|
261
|
|
|
.getName() |
|
262
|
|
|
.equals(inWorkout.getD_workout_name())) { |
|
263
|
|
|
return inProgram.getCurrent_workout_index(); |
|
264
|
|
|
} |
|
265
|
|
|
return 0; |
|
266
|
|
|
} |
|
267
|
|
|
|
|
268
|
|
|
private InWorkoutItemSet generateInWorkoutItemSet( |
|
269
|
|
|
ParseWorkoutItemSet parseWorkoutItemSet, |
|
270
|
|
|
List<ParseExercise> parseExercises, |
|
271
|
|
|
Float userWeight) { |
|
272
|
|
|
Optional<ParseExercise> parseExercise = |
|
273
|
|
|
parseExercises.stream() |
|
274
|
|
|
.filter( |
|
275
|
|
|
exercise -> |
|
276
|
|
|
Objects.equals( |
|
277
|
|
|
exercise.getExercise_id(), |
|
278
|
|
|
parseWorkoutItemSet |
|
279
|
|
|
.getParseWorkoutItem() |
|
280
|
|
|
.getExercise_id())) |
|
281
|
|
|
.findFirst(); |
|
282
|
|
|
Integer userGroup = |
|
283
|
|
|
Integer.parseInt( |
|
284
|
|
|
parseWorkoutItemSet |
|
285
|
|
|
.getParseWorkoutItem() |
|
286
|
|
|
.getParseWorkout() |
|
287
|
|
|
.getParsePart() |
|
288
|
|
|
.getParseRound() |
|
289
|
|
|
.getParseUserGroup() |
|
290
|
|
|
.getName()); |
|
291
|
|
|
final Integer exercise_percent; |
|
292
|
|
|
if (parseExercise.isPresent()) { |
|
293
|
|
|
switch (userGroup) { |
|
294
|
|
|
case 1: |
|
295
|
|
|
exercise_percent = parseExercise.get().getUser_group_1_percent(); |
|
296
|
|
|
break; |
|
297
|
|
|
case 2: |
|
298
|
|
|
exercise_percent = parseExercise.get().getUser_group_2_percent(); |
|
299
|
|
|
break; |
|
300
|
|
|
case 3: |
|
301
|
|
|
exercise_percent = parseExercise.get().getUser_group_3_percent(); |
|
302
|
|
|
break; |
|
303
|
|
|
case 4: |
|
304
|
|
|
exercise_percent = parseExercise.get().getUser_group_4_percent(); |
|
305
|
|
|
break; |
|
306
|
|
|
default: |
|
307
|
|
|
exercise_percent = 100; |
|
308
|
|
|
} |
|
309
|
|
|
} else { |
|
310
|
|
|
exercise_percent = 100; |
|
311
|
|
|
} |
|
312
|
|
|
final String exerciseBasis = |
|
313
|
|
|
parseExercise.isPresent() ? parseExercise.get().getBasis_for_calculations() : ""; |
|
314
|
|
|
final Integer exerciseWeightPercent = |
|
315
|
|
|
Arrays.asList("Weight", "Time").contains(exerciseBasis) ? exercise_percent : null; |
|
316
|
|
|
final Integer exerciseRepetitionsPercent = |
|
317
|
|
|
"Reps".equals(exerciseBasis) ? exercise_percent : null; |
|
318
|
|
|
final Integer exerciseTimePercent = "Time".equals(exerciseBasis) ? exercise_percent : null; |
|
319
|
|
|
final Integer exerciseSpeedPercent = |
|
320
|
|
|
"Speed".equals(exerciseBasis) ? exercise_percent : null; |
|
321
|
|
|
return new InWorkoutItemSet() |
|
322
|
|
|
.setExercise_repetitions_percent(exerciseRepetitionsPercent) |
|
323
|
|
|
.setGoal_repetitions(parseWorkoutItemSet.getRepetitions()) |
|
324
|
|
|
.setRepetitions(parseWorkoutItemSet.getRepetitions()) |
|
325
|
|
|
.setRepetitions_to_failure(parseWorkoutItemSet.getRepetitions_to_failure()) |
|
326
|
|
|
.setExercise_weight_percent(exerciseWeightPercent) |
|
327
|
|
|
.setGoal_weight_coef(parseWorkoutItemSet.getWeight()) |
|
328
|
|
|
.setWeight( |
|
329
|
|
|
generateWeight( |
|
330
|
|
|
parseWorkoutItemSet.getWeight(), |
|
331
|
|
|
exerciseWeightPercent, |
|
332
|
|
|
getWeightForUserGroup(userWeight, userGroup))) |
|
333
|
|
|
.setBodyweight(parseWorkoutItemSet.getBodyweight()) |
|
334
|
|
|
.setExercise_time_percent(exerciseTimePercent) |
|
335
|
|
|
.setGoal_time_in_sec(minToSec(parseWorkoutItemSet.getTime_in_min())) |
|
336
|
|
|
.setTime_in_sec(minToSec(parseWorkoutItemSet.getTime_in_min())) |
|
337
|
|
|
.setExercise_speed_percent(exerciseSpeedPercent) |
|
338
|
|
|
.setGoal_speed(parseWorkoutItemSet.getSpeed()) |
|
339
|
|
|
.setSpeed(parseWorkoutItemSet.getSpeed()) |
|
340
|
|
|
.setIncline(parseWorkoutItemSet.getIncline()) |
|
341
|
|
|
.setResistance(parseWorkoutItemSet.getResistance()) |
|
342
|
|
|
.setExercise_basis(exerciseBasis); |
|
343
|
|
|
} |
|
344
|
|
|
|
|
345
|
|
|
Float getWeightForUserGroup(Float userWeight, Integer userGroup) { |
|
346
|
|
|
if (userWeight == null) { |
|
347
|
|
|
return null; |
|
348
|
|
|
} |
|
349
|
|
|
switch (userGroup) { |
|
350
|
|
|
case 1: |
|
351
|
|
|
case 2: |
|
352
|
|
|
return Math.min(100F, userWeight); |
|
353
|
|
|
case 3: |
|
354
|
|
|
case 4: |
|
355
|
|
|
return Math.min(75F, userWeight); |
|
356
|
|
|
default: |
|
357
|
|
|
return userWeight; |
|
358
|
|
|
} |
|
359
|
|
|
} |
|
360
|
|
|
|
|
361
|
|
|
private Float generateWeight( |
|
362
|
|
|
Float goalWeightCoef, Integer exerciseWeightPercent, Float userWeight) { |
|
363
|
|
|
if (goalWeightCoef != null && exerciseWeightPercent != null && userWeight != null) { |
|
364
|
|
|
return roundToEven(userWeight * goalWeightCoef * exerciseWeightPercent / 100); |
|
365
|
|
|
} |
|
366
|
|
|
return goalWeightCoef; |
|
367
|
|
|
} |
|
368
|
|
|
|
|
369
|
|
|
float roundToEven(Float floatValue) { |
|
370
|
|
|
return floatValue.intValue() - floatValue.intValue() % 2; |
|
|
|
|
|
|
371
|
|
|
} |
|
372
|
|
|
|
|
373
|
|
|
private Integer minToSec(Float value) { |
|
374
|
|
|
return value == null ? null : Float.valueOf(value * 60).intValue(); |
|
|
|
|
|
|
375
|
|
|
} |
|
376
|
|
|
|
|
377
|
|
|
private List<ParseRound> getRoundsGorGoalAndUserGroup( |
|
378
|
|
|
List<ParseProgram> parsePrograms, InUserGoal inUserGoal, Integer userGroup) { |
|
379
|
|
|
final List<ParseRound> parseRounds = new ArrayList<>(); |
|
380
|
|
|
parsePrograms |
|
381
|
|
|
.get(0) |
|
382
|
|
|
.getParseGoals() |
|
383
|
|
|
.forEach( |
|
384
|
|
|
parseGoal -> { |
|
385
|
|
|
boolean nameFound = |
|
386
|
|
|
getOnlySymbols(parseGoal.getName()) |
|
387
|
|
|
.equalsIgnoreCase( |
|
388
|
|
|
getOnlySymbols(getGoalName(inUserGoal))); |
|
389
|
|
|
if (nameFound) { |
|
390
|
|
|
final List<ParseRound> localParseRounds = new ArrayList<>(); |
|
391
|
|
|
parseGoal |
|
392
|
|
|
.getParseUserGroups() |
|
393
|
|
|
.forEach( |
|
394
|
|
|
parseUserGroup -> { |
|
395
|
|
|
if (parseUserGroup |
|
396
|
|
|
.getName() |
|
397
|
|
|
.equals("" + userGroup)) { |
|
398
|
|
|
localParseRounds.addAll( |
|
399
|
|
|
parseUserGroup.getParseRounds()); |
|
400
|
|
|
} |
|
401
|
|
|
}); |
|
402
|
|
|
parseRounds.addAll( |
|
403
|
|
|
multiplyLists(localParseRounds, parseGoal.getLoops())); |
|
404
|
|
|
} |
|
405
|
|
|
}); |
|
406
|
|
|
return parseRounds; |
|
407
|
|
|
} |
|
408
|
|
|
|
|
409
|
|
|
List<ParseRound> multiplyLists(List<ParseRound> parseRounds, Integer loops) { |
|
410
|
|
|
if (loops == null) { |
|
411
|
|
|
return parseRounds; |
|
412
|
|
|
} |
|
413
|
|
|
final List<ParseRound> result = new ArrayList<>(parseRounds.size() * loops); |
|
414
|
|
|
parseRounds.forEach( |
|
415
|
|
|
parseRound -> { |
|
416
|
|
|
for (int index = 0; index < loops; index += 1) { |
|
417
|
|
|
result.add(parseRound); |
|
418
|
|
|
} |
|
419
|
|
|
}); |
|
420
|
|
|
return result; |
|
421
|
|
|
} |
|
422
|
|
|
|
|
423
|
|
|
private String getOnlySymbols(String value) { |
|
424
|
|
|
return value.replace("on a specific distance", "") |
|
425
|
|
|
.replace("ednurance", "endurance") |
|
426
|
|
|
.replaceAll("[\\s\\.\\,]+", ""); |
|
427
|
|
|
} |
|
428
|
|
|
|
|
429
|
|
|
private String getGoalName(InUserGoal inUserGoal) { |
|
430
|
|
|
return Arrays.asList( |
|
431
|
|
|
dictionaryService.getEnValue( |
|
432
|
|
|
DictionaryName.goal_title, inUserGoal.getD_goal_title(), null), |
|
433
|
|
|
dictionaryService.getEnValue( |
|
434
|
|
|
DictionaryName.goal_title_2, inUserGoal.getD_goal_title_2(), null)) |
|
435
|
|
|
.stream() |
|
436
|
|
|
.filter(Objects::nonNull) |
|
437
|
|
|
.collect(Collectors.joining(", ")); |
|
438
|
|
|
} |
|
439
|
|
|
|
|
440
|
|
|
private List<ParseWorkout> getParseWorkouts(List<ParseRound> parseRounds) { |
|
441
|
|
|
final List<ParseWorkout> parseWorkouts = new ArrayList<>(); |
|
442
|
|
|
parseRounds.forEach( |
|
443
|
|
|
parseRound -> { |
|
|
|
|
|
|
444
|
|
|
parseRound |
|
445
|
|
|
.getParseParts() |
|
446
|
|
|
.forEach( |
|
447
|
|
|
parsePart -> { |
|
|
|
|
|
|
448
|
|
|
parsePart |
|
449
|
|
|
.getParseWorkouts() |
|
450
|
|
|
.forEach( |
|
451
|
|
|
parseWorkout -> { |
|
|
|
|
|
|
452
|
|
|
parseWorkouts.add(parseWorkout); |
|
453
|
|
|
}); |
|
454
|
|
|
}); |
|
455
|
|
|
}); |
|
456
|
|
|
return parseWorkouts; |
|
457
|
|
|
} |
|
458
|
|
|
|
|
459
|
|
|
List<ParseWorkout> mergeLists( |
|
460
|
|
|
List<ParseWorkout> parseWorkouts1, List<ParseWorkout> parseWorkouts2) { |
|
461
|
|
|
final List<ParseWorkout> parseWorkouts = new ArrayList<>(); |
|
462
|
|
|
for (int index = 0; |
|
463
|
|
|
index < Math.max(parseWorkouts1.size(), parseWorkouts2.size()); |
|
464
|
|
|
index += 1) { |
|
465
|
|
|
if (!parseWorkouts1.isEmpty()) { |
|
466
|
|
|
parseWorkouts.add(parseWorkouts1.get(index % parseWorkouts1.size())); |
|
467
|
|
|
} |
|
468
|
|
|
if (!parseWorkouts2.isEmpty()) { |
|
469
|
|
|
parseWorkouts.add(parseWorkouts2.get(index % parseWorkouts2.size())); |
|
470
|
|
|
} |
|
471
|
|
|
} |
|
472
|
|
|
return parseWorkouts; |
|
473
|
|
|
} |
|
474
|
|
|
|
|
475
|
|
|
String getExerciseType(ParseWorkoutItem parseWorkoutItem) { |
|
476
|
|
|
List<Exercise> exercises = |
|
477
|
|
|
exerciseRepository.findByExerciseId(parseWorkoutItem.getExercise_id()); |
|
478
|
|
|
if (exercises.isEmpty()) { |
|
479
|
|
|
return "OnRepetitions"; |
|
480
|
|
|
} |
|
481
|
|
|
if (exercises.get(0).getExerciseTypes().size() == 1) { |
|
482
|
|
|
return exercises.get(0).getExerciseTypes().get(0).getName(); |
|
483
|
|
|
} |
|
484
|
|
|
if (parseWorkoutItem.getParseWorkoutItemSets().stream() |
|
485
|
|
|
.filter(set -> set.getTime_in_min() != null) |
|
|
|
|
|
|
486
|
|
|
.findFirst() |
|
487
|
|
|
.isPresent()) { |
|
488
|
|
|
return "OnTime"; |
|
489
|
|
|
} |
|
490
|
|
|
return "OnRepetitions"; |
|
491
|
|
|
} |
|
492
|
|
|
|
|
493
|
|
|
enum Gender { |
|
494
|
|
|
male, |
|
495
|
|
|
female, |
|
496
|
|
|
unknown |
|
497
|
|
|
} |
|
498
|
|
|
|
|
499
|
|
|
enum Level { |
|
500
|
|
|
unexperienced, |
|
501
|
|
|
experienced, |
|
502
|
|
|
unknown |
|
503
|
|
|
} |
|
504
|
|
|
|
|
505
|
|
|
private Optional<Integer> getUserGroup(InUser inUser) { |
|
506
|
|
|
final Gender gender; |
|
507
|
|
|
if ("male".equalsIgnoreCase(inUser.getD_sex())) { |
|
508
|
|
|
gender = Gender.male; |
|
509
|
|
|
} else if ("female".equalsIgnoreCase(inUser.getD_sex())) { |
|
510
|
|
|
gender = Gender.female; |
|
511
|
|
|
} else { |
|
512
|
|
|
gender = Gender.unknown; |
|
513
|
|
|
} |
|
514
|
|
|
final Level level; |
|
515
|
|
|
if ("1".equalsIgnoreCase(inUser.getD_level())) { |
|
516
|
|
|
level = Level.unexperienced; |
|
517
|
|
|
} else if ("2".equalsIgnoreCase(inUser.getD_level())) { |
|
518
|
|
|
level = Level.experienced; |
|
519
|
|
|
} else { |
|
520
|
|
|
level = Level.unknown; |
|
521
|
|
|
} |
|
522
|
|
|
final Integer userGroup; |
|
523
|
|
|
if (gender == Gender.male && level == Level.experienced) { |
|
524
|
|
|
userGroup = 1; |
|
525
|
|
|
} else if (gender == Gender.male && level == Level.unexperienced) { |
|
526
|
|
|
userGroup = 2; |
|
527
|
|
|
} else if (gender == Gender.female && level == Level.experienced) { |
|
528
|
|
|
userGroup = 3; |
|
529
|
|
|
} else if (gender == Gender.female && level == Level.unexperienced) { |
|
530
|
|
|
userGroup = 4; |
|
531
|
|
|
} else { |
|
532
|
|
|
userGroup = null; |
|
533
|
|
|
} |
|
534
|
|
|
return Optional.ofNullable(userGroup); |
|
535
|
|
|
} |
|
536
|
|
|
} |
|
537
|
|
|
|