forked from upstream-mirrors/OpenTracks
Change code style.
This commit is contained in:
@@ -129,19 +129,18 @@ limitations under the License.
|
|||||||
android:id="@+id/stats_longitude"
|
android:id="@+id/stats_longitude"
|
||||||
layout="@layout/stats_small_item" />
|
layout="@layout/stats_small_item" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
<!-- Row 7: calorie horizontal line -->
|
||||||
<!-- Row 7: calories horizontal line -->
|
|
||||||
<View
|
<View
|
||||||
android:id="@+id/stats_calories_horizontal_line"
|
android:id="@+id/stats_calorie_horizontal_line"
|
||||||
style="@style/StatsHorizontalLine" />
|
style="@style/StatsHorizontalLine" />
|
||||||
<!-- Row 7: calories -->
|
<!-- Row 7: calorie -->
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/stats_calories_container"
|
android:id="@+id/stats_calorie_container"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_width="match_parent" >
|
android:layout_width="match_parent" >
|
||||||
<!-- Calories value -->
|
<!-- Calories value -->
|
||||||
<include
|
<include
|
||||||
android:id="@+id/stats_calories"
|
android:id="@+id/stats_calorie"
|
||||||
layout="@layout/stats_small_item" />
|
layout="@layout/stats_small_item" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</merge>
|
</merge>
|
||||||
@@ -2111,9 +2111,11 @@ limitations under the License.
|
|||||||
Character limit: ~23 (1 line)">
|
Character limit: ~23 (1 line)">
|
||||||
Elevation
|
Elevation
|
||||||
</string>
|
</string>
|
||||||
<string name="stats_calories"
|
<string name="stats_calorie"
|
||||||
translation_description="In the 'Stats' page, the calories expediture of track.">
|
translation_description="In the 'Stats' page, the calorie expediture of track.
|
||||||
Calories expediture
|
|
||||||
|
Character limit: ~23 (1 line)">
|
||||||
|
Calorie expediture
|
||||||
</string>
|
</string>
|
||||||
<string name="stats_fastest_pace"
|
<string name="stats_fastest_pace"
|
||||||
translation_description="In the 'Stats' page, the fastest pace.">
|
translation_description="In the 'Stats' page, the fastest pace.">
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ public class MyTracksProvider extends ContentProvider {
|
|||||||
|
|
||||||
if (oldVersion <= 22) {
|
if (oldVersion <= 22) {
|
||||||
Log.w(TAG, "Upgrade DB: Adding track calories column.");
|
Log.w(TAG, "Upgrade DB: Adding track calories column.");
|
||||||
db.execSQL("ALTER TABLE " + TracksColumns.TABLE_NAME + " ADD " + TracksColumns.CALORIES
|
db.execSQL("ALTER TABLE " + TracksColumns.TABLE_NAME + " ADD " + TracksColumns.CALORIE
|
||||||
+ " INTEGER");
|
+ " INTEGER");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -193,9 +193,10 @@ public class TripStatisticsUpdater {
|
|||||||
// TODO 1: How to get the value of weight.
|
// TODO 1: How to get the value of weight.
|
||||||
// TODO 2: How to get the value of ActivityType.
|
// TODO 2: How to get the value of ActivityType.
|
||||||
|
|
||||||
double value = CalorieUtils.getCalories(lastMovingLocation, location,
|
// Update calorie
|
||||||
|
double calorie = CalorieUtils.getCalories(lastMovingLocation, location,
|
||||||
gradeBuffer.getAverage(), 65, ActivityType.FOOT);
|
gradeBuffer.getAverage(), 65, ActivityType.FOOT);
|
||||||
currentSegment.addCaloticExpenditure(value);
|
currentSegment.addCalorie(calorie);
|
||||||
|
|
||||||
lastLocation = location;
|
lastLocation = location;
|
||||||
lastMovingLocation = location;
|
lastMovingLocation = location;
|
||||||
|
|||||||
@@ -39,11 +39,16 @@ public class CalorieUtils {
|
|||||||
*/
|
*/
|
||||||
private static final double VO2H_TO_KCAL = 5;
|
private static final double VO2H_TO_KCAL = 5;
|
||||||
|
|
||||||
|
private static final double MILLISECOND_TO_SECOND = 1000.0;
|
||||||
|
private static final double MILLILITER_TO_LITER = 1000.0;
|
||||||
|
private static final double SECOND_TO_MINUTE = 60.0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Changes 4.5 miles per hour to meters per minutes.
|
* Changes 4.5 miles per hour to meters per minutes.
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static final double CRTICAL_SPEED_RUNNING = 4.5 * UnitConversions.MI_TO_KM * 1000 / 60;
|
static final double CRTICAL_SPEED_RUNNING = 4.5 * UnitConversions.MI_TO_KM * 1000
|
||||||
|
/ SECOND_TO_MINUTE;
|
||||||
|
|
||||||
public enum ActivityType {
|
public enum ActivityType {
|
||||||
CYCLING, FOOT
|
CYCLING, FOOT
|
||||||
@@ -56,7 +61,7 @@ public class CalorieUtils {
|
|||||||
*
|
*
|
||||||
* @param speed is calculated in meters per minute (m/min)
|
* @param speed is calculated in meters per minute (m/min)
|
||||||
* @param grade
|
* @param grade
|
||||||
* @return the VO2 value in ml/kg/min
|
* @return the VO2 value in ml/kg/min.
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static double calculateWalkingVO2(double speed, double grade) {
|
static double calculateWalkingVO2(double speed, double grade) {
|
||||||
@@ -75,7 +80,7 @@ public class CalorieUtils {
|
|||||||
*
|
*
|
||||||
* @param speed is calculated in meters per minute (m/min)
|
* @param speed is calculated in meters per minute (m/min)
|
||||||
* @param grade
|
* @param grade
|
||||||
* @return the VO2 value in ml/kg/min
|
* @return the VO2 value in ml/kg/min.
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static double calculateRunningVO2(double speed, double grade) {
|
static double calculateRunningVO2(double speed, double grade) {
|
||||||
@@ -108,13 +113,13 @@ public class CalorieUtils {
|
|||||||
* @param grade the grade to calculate
|
* @param grade the grade to calculate
|
||||||
* @param weight of rider plus bike
|
* @param weight of rider plus bike
|
||||||
* @param timeUsed how many times used in second
|
* @param timeUsed how many times used in second
|
||||||
* @return the power value watts(Joule/second)
|
* @return the power value watts(Joule/second).
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static double calculateCyclingCalories(double speed, double grade, int weight, double timeUsed) {
|
static double calculateCyclingCalories(double speed, double grade, int weight, double timeUsed) {
|
||||||
// Get the Power.
|
// Get the Power
|
||||||
double power = 9.8 * weight * speed * (0.0053 + grade) + 0.185 * (speed * speed * speed);
|
double power = 9.8 * weight * speed * (0.0053 + grade) + 0.185 * (speed * speed * speed);
|
||||||
// Get the calories.
|
// Get the calories
|
||||||
return power * timeUsed / UnitConversions.KCAL_TO_J;
|
return power * timeUsed / UnitConversions.KCAL_TO_J;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,16 +130,16 @@ public class CalorieUtils {
|
|||||||
* @param stop the stop location
|
* @param stop the stop location
|
||||||
* @param grade the grade to calculate
|
* @param grade the grade to calculate
|
||||||
* @param weight the weight of user
|
* @param weight the weight of user
|
||||||
* @return the calories expenditure between the start and stop location
|
* @return the calories expenditure between the start and stop location.
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static double calculateExpenditureCycling(Location start, Location stop, double grade, int weight) {
|
static double calculateExpenditureCycling(Location start, Location stop, double grade, int weight) {
|
||||||
// Seconds.
|
// Gets time in seconds
|
||||||
double time = (double) (stop.getTime() - start.getTime()) / 1000;
|
double time = (double) (stop.getTime() - start.getTime()) / MILLISECOND_TO_SECOND;
|
||||||
// Meter per second.
|
// Meters per second
|
||||||
double speed = (start.getSpeed() + stop.getSpeed()) / 2;
|
double speed = (start.getSpeed() + stop.getSpeed()) / 2.0;
|
||||||
if (grade < 0) {
|
if (grade < 0) {
|
||||||
grade = 0;
|
grade = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return calculateCyclingCalories(speed, grade, weight, time);
|
return calculateCyclingCalories(speed, grade, weight, time);
|
||||||
@@ -147,45 +152,39 @@ public class CalorieUtils {
|
|||||||
* @param stop the stop location
|
* @param stop the stop location
|
||||||
* @param grade the grade to calculate
|
* @param grade the grade to calculate
|
||||||
* @param weight the weight of user
|
* @param weight the weight of user
|
||||||
* @return the calories expenditure between the start and stop location
|
* @return the calories expenditure between the start and stop location.
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static double calculateExpenditureFoot(Location start, Location stop, double grade, int weight) {
|
static double calculateExpenditureFoot(Location start, Location stop, double grade, int weight) {
|
||||||
// Meter per minute.
|
// Meters per minute
|
||||||
double speed = (start.getSpeed() + stop.getSpeed()) * 60 / 2;
|
double averageSpeed = (start.getSpeed() + stop.getSpeed()) * SECOND_TO_MINUTE / 2.0;
|
||||||
// Get VO2
|
// Get VO2
|
||||||
double VO2 = getVO2(speed, grade);
|
double VO2 = getVO2(averageSpeed, grade);
|
||||||
// Seconds.
|
// Seconds
|
||||||
double time = (double) (stop.getTime() - start.getTime()) / 1000;
|
double time = (double) (stop.getTime() - start.getTime()) / MILLISECOND_TO_SECOND;
|
||||||
// Change mL/kg/min to mL/kg.
|
// Change mL/kg/min to mL/kg
|
||||||
double VO2All = VO2 * time / 60;
|
double VO2All_mL = VO2 * time / SECOND_TO_MINUTE;
|
||||||
// Change mL/kg to L/kg.
|
// Change mL/kg to L/kg
|
||||||
VO2All = VO2All / 1000;
|
double VO2All_L = VO2All_mL / MILLILITER_TO_LITER;
|
||||||
// Get the calorie.
|
// Get the calorie
|
||||||
return VO2All * weight * VO2H_TO_KCAL;
|
return VO2All_L * weight * VO2H_TO_KCAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the VO2 value.
|
* Gets the VO2 value.
|
||||||
*
|
*
|
||||||
* @param start the start location
|
* @param speed in meters per minute
|
||||||
* @param stop the stop location
|
|
||||||
* @param grade the grade to calculate
|
* @param grade the grade to calculate
|
||||||
* @return the VO2 value
|
* @return the VO2 value.
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static double getVO2(double speed, double grade) {
|
static double getVO2(double speed, double grade) {
|
||||||
if (grade < 0) {
|
if (grade < 0) {
|
||||||
grade = 0;
|
grade = 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
double VO2 = 0;
|
return speed > CRTICAL_SPEED_RUNNING ? calculateRunningVO2(speed, grade) : calculateWalkingVO2(
|
||||||
if (speed > CRTICAL_SPEED_RUNNING) {
|
speed, grade);
|
||||||
VO2 = calculateRunningVO2(speed, grade);
|
|
||||||
} else {
|
|
||||||
VO2 = calculateWalkingVO2(speed, grade);
|
|
||||||
}
|
|
||||||
return VO2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -196,7 +195,7 @@ public class CalorieUtils {
|
|||||||
* @param grade the grade to calculate
|
* @param grade the grade to calculate
|
||||||
* @param weight the weight of user
|
* @param weight the weight of user
|
||||||
* @param activityType can be foot or cycling
|
* @param activityType can be foot or cycling
|
||||||
* @return the calories expenditure between the start and stop location
|
* @return the calories expenditure between the start and stop location.
|
||||||
*/
|
*/
|
||||||
public static double getCalories(Location start, Location stop, double grade, int weight,
|
public static double getCalories(Location start, Location stop, double grade, int weight,
|
||||||
ActivityType activityType) {
|
ActivityType activityType) {
|
||||||
|
|||||||
@@ -177,8 +177,8 @@ public class StatsUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set calories
|
// Set calories
|
||||||
double calories = tripStatistics == null ? Double.NaN : tripStatistics.getCaloricExpenditure();
|
double calories = tripStatistics == null ? Double.NaN : tripStatistics.getCalorie();
|
||||||
setCalories(activity, R.id.stats_calories, R.string.stats_calories, calories);
|
setCalorie(activity, R.id.stats_calorie, R.string.stats_calorie, calories);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -322,18 +322,15 @@ public class StatsUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets calories.
|
* Sets calorie.
|
||||||
*
|
*
|
||||||
* @param activity the activity
|
* @param activity the activity
|
||||||
* @param itemId the item id
|
* @param itemId the item id
|
||||||
* @param speedLabelId the speed label id
|
* @param labelId the calorie label id
|
||||||
* @param paceLabelId the pace label id
|
* @param calorie the value of calorie
|
||||||
* @param speed the speed in meters per second
|
|
||||||
* @param metricUnits true if metric units
|
|
||||||
* @param reportSpeed true if report speed
|
|
||||||
*/
|
*/
|
||||||
private static void setCalories(Activity activity, int itemId, int labelId, double calories) {
|
private static void setCalorie(Activity activity, int itemId, int labelId, double calorie) {
|
||||||
setItem(activity, itemId, labelId,
|
setItem(activity, itemId, labelId,
|
||||||
String.format(Locale.getDefault(), CALORIES_FORMAT, calories), "");
|
String.format(Locale.getDefault(), CALORIES_FORMAT, calorie), null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+3
-3
@@ -87,7 +87,7 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
|
|||||||
int modifiedTimeIndex = cursor.getColumnIndexOrThrow(TracksColumns.MODIFIEDTIME);
|
int modifiedTimeIndex = cursor.getColumnIndexOrThrow(TracksColumns.MODIFIEDTIME);
|
||||||
int sharedWithMeIndex = cursor.getColumnIndexOrThrow(TracksColumns.SHAREDWITHME);
|
int sharedWithMeIndex = cursor.getColumnIndexOrThrow(TracksColumns.SHAREDWITHME);
|
||||||
int sharedOwnerIndex = cursor.getColumnIndexOrThrow(TracksColumns.SHAREDOWNER);
|
int sharedOwnerIndex = cursor.getColumnIndexOrThrow(TracksColumns.SHAREDOWNER);
|
||||||
int caloriesIndex = cursor.getColumnIndexOrThrow(TracksColumns.CALORIES);
|
int caloriesIndex = cursor.getColumnIndexOrThrow(TracksColumns.CALORIE);
|
||||||
|
|
||||||
Track track = new Track();
|
Track track = new Track();
|
||||||
TripStatistics tripStatistics = track.getTripStatistics();
|
TripStatistics tripStatistics = track.getTripStatistics();
|
||||||
@@ -154,7 +154,7 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
|
|||||||
tripStatistics.setMaxGrade(cursor.getFloat(maxGradeIndex));
|
tripStatistics.setMaxGrade(cursor.getFloat(maxGradeIndex));
|
||||||
}
|
}
|
||||||
if (!cursor.isNull(caloriesIndex)) {
|
if (!cursor.isNull(caloriesIndex)) {
|
||||||
tripStatistics.setCaloricExpenditure(cursor.getFloat(caloriesIndex));
|
tripStatistics.setCalorie(cursor.getFloat(caloriesIndex));
|
||||||
}
|
}
|
||||||
if (!cursor.isNull(iconIndex)) {
|
if (!cursor.isNull(iconIndex)) {
|
||||||
track.setIcon(cursor.getString(iconIndex));
|
track.setIcon(cursor.getString(iconIndex));
|
||||||
@@ -320,7 +320,7 @@ public class MyTracksProviderUtilsImpl implements MyTracksProviderUtils {
|
|||||||
values.put(TracksColumns.MODIFIEDTIME, track.getModifiedTime());
|
values.put(TracksColumns.MODIFIEDTIME, track.getModifiedTime());
|
||||||
values.put(TracksColumns.SHAREDWITHME, track.isSharedWithMe());
|
values.put(TracksColumns.SHAREDWITHME, track.isSharedWithMe());
|
||||||
values.put(TracksColumns.SHAREDOWNER, track.getSharedOwner());
|
values.put(TracksColumns.SHAREDOWNER, track.getSharedOwner());
|
||||||
values.put(TracksColumns.CALORIES, tripStatistics.getCaloricExpenditure());
|
values.put(TracksColumns.CALORIE, tripStatistics.getCalorie());
|
||||||
|
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,7 +66,6 @@ public interface TracksColumns extends BaseColumns {
|
|||||||
public static final String MINLON = "minlon"; // minimum longitude
|
public static final String MINLON = "minlon"; // minimum longitude
|
||||||
public static final String MAXLON = "maxlon"; // maximum longitude
|
public static final String MAXLON = "maxlon"; // maximum longitude
|
||||||
public static final String AVGSPEED = "avgspeed"; // average speed
|
public static final String AVGSPEED = "avgspeed"; // average speed
|
||||||
public static final String CALORIES = "calories"; // calories
|
|
||||||
|
|
||||||
// average moving speed
|
// average moving speed
|
||||||
public static final String AVGMOVINGSPEED = "avgmovingspeed";
|
public static final String AVGMOVINGSPEED = "avgmovingspeed";
|
||||||
@@ -89,6 +88,9 @@ public interface TracksColumns extends BaseColumns {
|
|||||||
|
|
||||||
// The owner of the shared with me track
|
// The owner of the shared with me track
|
||||||
public static final String SHAREDOWNER = "sharedOwner";
|
public static final String SHAREDOWNER = "sharedOwner";
|
||||||
|
|
||||||
|
// Calorie expenditure of the track
|
||||||
|
public static final String CALORIE = "calories";
|
||||||
|
|
||||||
public static final String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + " (" // table
|
public static final String CREATE_TABLE = "CREATE TABLE " + TABLE_NAME + " (" // table
|
||||||
+ _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " // id
|
+ _ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " // id
|
||||||
@@ -122,7 +124,7 @@ public interface TracksColumns extends BaseColumns {
|
|||||||
+ MODIFIEDTIME + " INTEGER, " // modified time
|
+ MODIFIEDTIME + " INTEGER, " // modified time
|
||||||
+ SHAREDWITHME + " INTEGER, " // shared with me
|
+ SHAREDWITHME + " INTEGER, " // shared with me
|
||||||
+ SHAREDOWNER + " STRING, " // shared owner
|
+ SHAREDOWNER + " STRING, " // shared owner
|
||||||
+ CALORIES + " INTEGER);"; // calories
|
+ CALORIE + " INTEGER);"; // calories
|
||||||
|
|
||||||
public static final String[] COLUMNS = { _ID, // id
|
public static final String[] COLUMNS = { _ID, // id
|
||||||
NAME, // name
|
NAME, // name
|
||||||
@@ -155,7 +157,7 @@ public interface TracksColumns extends BaseColumns {
|
|||||||
MODIFIEDTIME, // modified time
|
MODIFIEDTIME, // modified time
|
||||||
SHAREDWITHME, // shared with me
|
SHAREDWITHME, // shared with me
|
||||||
SHAREDOWNER,// shared owner
|
SHAREDOWNER,// shared owner
|
||||||
CALORIES }; // calories
|
CALORIE }; // calories
|
||||||
|
|
||||||
public static final byte[] COLUMN_TYPES = { ContentTypeIds.LONG_TYPE_ID, // id
|
public static final byte[] COLUMN_TYPES = { ContentTypeIds.LONG_TYPE_ID, // id
|
||||||
ContentTypeIds.STRING_TYPE_ID, // name
|
ContentTypeIds.STRING_TYPE_ID, // name
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ public class TripStatistics implements Parcelable {
|
|||||||
private final ExtremityMonitor gradeExtremities = new ExtremityMonitor();
|
private final ExtremityMonitor gradeExtremities = new ExtremityMonitor();
|
||||||
|
|
||||||
// The calorie expenditure of current track.
|
// The calorie expenditure of current track.
|
||||||
private double caloricExpenditure = 0;
|
private double calorie = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default constructor.
|
* Default constructor.
|
||||||
@@ -89,7 +89,7 @@ public class TripStatistics implements Parcelable {
|
|||||||
other.elevationExtremities.getMin(), other.elevationExtremities.getMax());
|
other.elevationExtremities.getMin(), other.elevationExtremities.getMax());
|
||||||
totalElevationGain = other.totalElevationGain;
|
totalElevationGain = other.totalElevationGain;
|
||||||
gradeExtremities.set(other.gradeExtremities.getMin(), other.gradeExtremities.getMax());
|
gradeExtremities.set(other.gradeExtremities.getMin(), other.gradeExtremities.getMax());
|
||||||
caloricExpenditure = other.caloricExpenditure;
|
calorie = other.calorie;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -122,7 +122,7 @@ public class TripStatistics implements Parcelable {
|
|||||||
gradeExtremities.update(other.gradeExtremities.getMin());
|
gradeExtremities.update(other.gradeExtremities.getMin());
|
||||||
gradeExtremities.update(other.gradeExtremities.getMax());
|
gradeExtremities.update(other.gradeExtremities.getMax());
|
||||||
}
|
}
|
||||||
caloricExpenditure += other.caloricExpenditure;
|
calorie += other.calorie;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -493,7 +493,8 @@ public class TripStatistics implements Parcelable {
|
|||||||
+ "; Max Longitude: " + getRightDegrees() + "; Max Speed: " + getMaxSpeed()
|
+ "; Max Longitude: " + getRightDegrees() + "; Max Speed: " + getMaxSpeed()
|
||||||
+ "; Min Elevation: " + getMinElevation() + "; Max Elevation: " + getMaxElevation()
|
+ "; Min Elevation: " + getMinElevation() + "; Max Elevation: " + getMaxElevation()
|
||||||
+ "; Elevation Gain: " + getTotalElevationGain() + "; Min Grade: " + getMinGrade()
|
+ "; Elevation Gain: " + getTotalElevationGain() + "; Min Grade: " + getMinGrade()
|
||||||
+ "; Max Grade: " + getMaxGrade() + "}";
|
+ "; Max Grade: " + getMaxGrade() + "; Calorie expenditure: " + getCalorie()
|
||||||
|
+ "}";
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -529,6 +530,9 @@ public class TripStatistics implements Parcelable {
|
|||||||
double minGrade = source.readDouble();
|
double minGrade = source.readDouble();
|
||||||
double maxGrade = source.readDouble();
|
double maxGrade = source.readDouble();
|
||||||
data.gradeExtremities.set(minGrade, maxGrade);
|
data.gradeExtremities.set(minGrade, maxGrade);
|
||||||
|
|
||||||
|
double calorie = source.readDouble();
|
||||||
|
data.setCalorie(calorie);
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
@@ -566,28 +570,29 @@ public class TripStatistics implements Parcelable {
|
|||||||
dest.writeDouble(totalElevationGain);
|
dest.writeDouble(totalElevationGain);
|
||||||
dest.writeDouble(gradeExtremities.getMin());
|
dest.writeDouble(gradeExtremities.getMin());
|
||||||
dest.writeDouble(gradeExtremities.getMax());
|
dest.writeDouble(gradeExtremities.getMax());
|
||||||
|
dest.writeDouble(calorie);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds calories value.
|
* Adds calorie value.
|
||||||
*
|
*
|
||||||
* @param calories
|
* @param calorieAdded
|
||||||
*/
|
*/
|
||||||
public void addCaloticExpenditure(double calories) {
|
public void addCalorie(double calorieAdded) {
|
||||||
caloricExpenditure = caloricExpenditure + calories;
|
this.calorie += calorieAdded;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets calories value.
|
* Sets calorie value.
|
||||||
*/
|
*/
|
||||||
public void setCaloricExpenditure(double value) {
|
public void setCalorie(double newCalorie) {
|
||||||
caloricExpenditure = value;
|
calorie = newCalorie;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets calories value.
|
* Gets calories value.
|
||||||
*/
|
*/
|
||||||
public double getCaloricExpenditure() {
|
public double getCalorie() {
|
||||||
return caloricExpenditure;
|
return calorie;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -67,6 +67,7 @@ public class TripStatisticsTest extends TestCase {
|
|||||||
statistics.setMinGrade(-25.0); // Resulting min grade
|
statistics.setMinGrade(-25.0); // Resulting min grade
|
||||||
statistics2.setMaxGrade(35.0); // Resulting max grade
|
statistics2.setMaxGrade(35.0); // Resulting max grade
|
||||||
statistics2.setMinGrade(0.0);
|
statistics2.setMinGrade(0.0);
|
||||||
|
statistics2.setCalorie(50.0);
|
||||||
|
|
||||||
// Resulting bounds: -10000, 35000, 30000, -40000
|
// Resulting bounds: -10000, 35000, 30000, -40000
|
||||||
statistics.setBounds(-10000, 20000, 30000, -40000);
|
statistics.setBounds(-10000, 20000, 30000, -40000);
|
||||||
@@ -89,6 +90,7 @@ public class TripStatisticsTest extends TestCase {
|
|||||||
assertEquals(3575.0, statistics.getMaxElevation());
|
assertEquals(3575.0, statistics.getMaxElevation());
|
||||||
assertEquals(-25.0, statistics.getMinGrade());
|
assertEquals(-25.0, statistics.getMinGrade());
|
||||||
assertEquals(35.0, statistics.getMaxGrade());
|
assertEquals(35.0, statistics.getMaxGrade());
|
||||||
|
assertEquals(50.0, statistics.getCalorie());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testGetAverageSpeed() {
|
public void testGetAverageSpeed() {
|
||||||
|
|||||||
@@ -29,14 +29,15 @@ public class CalorieUtilsTest extends TestCase {
|
|||||||
|
|
||||||
Location start = new Location(LocationManager.GPS_PROVIDER);
|
Location start = new Location(LocationManager.GPS_PROVIDER);
|
||||||
Location stop = new Location(LocationManager.GPS_PROVIDER);
|
Location stop = new Location(LocationManager.GPS_PROVIDER);
|
||||||
private double grade = 10;
|
private double grade = 10.0;
|
||||||
private int weight = 20;
|
private int weight = 20;
|
||||||
|
private final long TIME_INTERVAL = 1000l;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
// Make the time interval is not 0.
|
// Make the time interval is not 0
|
||||||
stop.setTime(start.getTime() + 1000);
|
stop.setTime(start.getTime() + TIME_INTERVAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -53,9 +54,11 @@ public class CalorieUtilsTest extends TestCase {
|
|||||||
* Checks whether using foot calculation equation while grade is negative.
|
* Checks whether using foot calculation equation while grade is negative.
|
||||||
*/
|
*/
|
||||||
public void testGetCalories_footNegativeGrade() {
|
public void testGetCalories_footNegativeGrade() {
|
||||||
double actual = CalorieUtils.getCalories(start, stop, -5, weight,
|
double actualGrade = -5;
|
||||||
|
double expectGrade = 0;
|
||||||
|
double actual = CalorieUtils.getCalories(start, stop, actualGrade, weight,
|
||||||
CalorieUtils.ActivityType.FOOT);
|
CalorieUtils.ActivityType.FOOT);
|
||||||
double expected = CalorieUtils.calculateExpenditureFoot(start, stop, 0, weight);
|
double expected = CalorieUtils.calculateExpenditureFoot(start, stop, expectGrade, weight);
|
||||||
assertEquals(expected, actual);
|
assertEquals(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,9 +86,11 @@ public class CalorieUtilsTest extends TestCase {
|
|||||||
* Checks using walking VO2 equation.
|
* Checks using walking VO2 equation.
|
||||||
*/
|
*/
|
||||||
public void testGetVO2_walking() {
|
public void testGetVO2_walking() {
|
||||||
double actual = CalorieUtils.getVO2(CalorieUtils.CRTICAL_SPEED_RUNNING / 2, grade);
|
// Test at half the critical speed
|
||||||
double expected = CalorieUtils.calculateWalkingVO2(CalorieUtils.CRTICAL_SPEED_RUNNING / 2,
|
double footSpeed = CalorieUtils.CRTICAL_SPEED_RUNNING / 2.0;
|
||||||
grade);
|
|
||||||
|
double actual = CalorieUtils.getVO2(footSpeed, grade);
|
||||||
|
double expected = CalorieUtils.calculateWalkingVO2(footSpeed, grade);
|
||||||
assertEquals(expected, actual);
|
assertEquals(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user