-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add schedule conversion; tidy up Creator class moving conversion out …
…into separate class
- Loading branch information
Showing
7 changed files
with
146 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
<exclude-output /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | ||
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" /> | ||
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" /> | ||
<sourceFolder url="file://$MODULE_DIR$/gen" isTestSource="false" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
<orderEntry type="library" name="fit" level="project" /> | ||
<orderEntry type="library" name="log4j-1.2.13" level="project" /> | ||
<orderEntry type="library" name="lombok" level="project" /> | ||
<orderEntry type="library" name="hamcrest-core-1.3" level="project" /> | ||
<orderEntry type="library" name="slf4j-api-1.7.22" level="project" /> | ||
<orderEntry type="library" name="antlr-4.5.3-complete" level="project" /> | ||
<orderEntry type="library" name="antlr-4.6-complete" level="project" /> | ||
<orderEntry type="library" name="backport-util-concurrent-3.1" level="project" /> | ||
<orderEntry type="library" name="groovy-all-2.1.1" level="project" /> | ||
<orderEntry type="library" name="poi-3.11-beta2-20140822" level="project" /> | ||
</component> | ||
</module> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/com/johnpickup/converter/WorkoutScheduleConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.johnpickup.converter; | ||
|
||
import com.johnpickup.garmin.schedule.*; | ||
import com.johnpickup.garmin.unit.PaceTarget; | ||
import com.johnpickup.parser.*; | ||
import com.johnpickup.parser.ScheduledWorkout; | ||
import com.johnpickup.parser.Workout; | ||
import lombok.Getter; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* Created by john on 12/01/2017. | ||
*/ | ||
public class WorkoutScheduleConverter { | ||
private Map<String, PaceTarget> namedPaces = new HashMap<>(); | ||
@Getter | ||
private List<com.johnpickup.garmin.workout.Workout> garminWorkouts = new ArrayList<>(); | ||
@Getter | ||
private TrainingSchedule trainingSchedule = new TrainingSchedule(); | ||
private Map<Workout, com.johnpickup.garmin.workout.Workout> workoutMap = new HashMap<>(); | ||
|
||
public WorkoutScheduleConverter() { | ||
PaceNameConverter namedPaceConverter = new PaceNameConverter(namedPaces); | ||
PaceConverterFactory.getInstance().register(namedPaceConverter, PaceName.class); | ||
} | ||
|
||
public void convert(WorkoutSchedule workoutSchedule) { | ||
init(); | ||
for (Map.Entry<String, Pace> namedPace : workoutSchedule.getPaces().entrySet()) { | ||
Pace pace = namedPace.getValue(); | ||
namedPaces.put(namedPace.getKey(), PaceConverterFactory.getInstance().getPaceConverter(pace).convert(pace)); | ||
} | ||
|
||
WorkoutConverter workoutConverter = new WorkoutConverter(); | ||
|
||
for (Map.Entry<String, Workout> workoutEntry : workoutSchedule.getWorkouts().entrySet()) { | ||
com.johnpickup.garmin.workout.Workout garminWorkout = workoutConverter.convert(workoutEntry.getValue()); | ||
garminWorkout.setName(workoutEntry.getKey()); | ||
garminWorkouts.add(garminWorkout); | ||
workoutMap.put(workoutEntry.getValue(), garminWorkout); | ||
} | ||
|
||
for (ScheduledWorkout scheduledWorkout: workoutSchedule.getSchedule()) { | ||
Workout workout = scheduledWorkout.getWorkout(); | ||
com.johnpickup.garmin.workout.Workout garminWorkout = workoutMap.get(workout); | ||
com.johnpickup.garmin.schedule.ScheduledWorkout garminScheduledWorkout = new com.johnpickup.garmin.schedule.ScheduledWorkout(garminWorkout, scheduledWorkout.getDate()); | ||
trainingSchedule.addScheduledWorkout(garminScheduledWorkout); | ||
} | ||
|
||
} | ||
|
||
private void init() { | ||
namedPaces.clear(); | ||
garminWorkouts.clear(); | ||
workoutMap.clear(); | ||
trainingSchedule.clear(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.johnpickup.garmin; | ||
|
||
import com.garmin.fit.FileEncoder; | ||
import com.garmin.fit.Fit; | ||
import com.johnpickup.garmin.fit.FitGenerator; | ||
|
||
/** | ||
* Class that can save output from a FitGenerator to a fie | ||
*/ | ||
public class WorkoutSaver { | ||
|
||
public void save(FitGenerator fitGenerator, String filename) { | ||
FileEncoder encode = new FileEncoder( new java.io.File(filename), Fit.ProtocolVersion.V1_0); | ||
encode.write(fitGenerator.generate()); | ||
encode.close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters