mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-10 17:11:56 +01:00
[Huawei] Fix PR #3742, add workout frequency and altitude
This commit is contained in:
parent
2d32822ff8
commit
83fd09939f
@ -45,7 +45,7 @@ public class GBDaoGenerator {
|
|||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
final Schema schema = new Schema(72, MAIN_PACKAGE + ".entities");
|
final Schema schema = new Schema(73, MAIN_PACKAGE + ".entities");
|
||||||
|
|
||||||
Entity userAttributes = addUserAttributes(schema);
|
Entity userAttributes = addUserAttributes(schema);
|
||||||
Entity user = addUserInfo(schema, userAttributes);
|
Entity user = addUserInfo(schema, userAttributes);
|
||||||
@ -1170,6 +1170,9 @@ public class GBDaoGenerator {
|
|||||||
workoutDataSample.addShortProperty("calories").notNull();
|
workoutDataSample.addShortProperty("calories").notNull();
|
||||||
workoutDataSample.addShortProperty("cyclingPower").notNull();
|
workoutDataSample.addShortProperty("cyclingPower").notNull();
|
||||||
|
|
||||||
|
workoutDataSample.addShortProperty("frequency").notNull();
|
||||||
|
workoutDataSample.addIntProperty("altitude");
|
||||||
|
|
||||||
return workoutDataSample;
|
return workoutDataSample;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,43 @@
|
|||||||
|
/* Copyright (C) 2024 Martin.JM
|
||||||
|
|
||||||
|
This file is part of Gadgetbridge.
|
||||||
|
|
||||||
|
Gadgetbridge is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU Affero General Public License as published
|
||||||
|
by the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
Gadgetbridge is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Affero General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Affero General Public License
|
||||||
|
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
||||||
|
package nodomain.freeyourgadget.gadgetbridge.database.schema;
|
||||||
|
|
||||||
|
import android.database.sqlite.SQLiteDatabase;
|
||||||
|
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.database.DBUpdateScript;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.entities.HuaweiWorkoutDataSampleDao;
|
||||||
|
|
||||||
|
public class GadgetbridgeUpdate_73 implements DBUpdateScript {
|
||||||
|
@Override
|
||||||
|
public void upgradeSchema(final SQLiteDatabase db) {
|
||||||
|
if (!DBHelper.existsColumn(HuaweiWorkoutDataSampleDao.TABLENAME, HuaweiWorkoutDataSampleDao.Properties.Frequency.columnName, db)) {
|
||||||
|
final String statement = "ALTER TABLE " + HuaweiWorkoutDataSampleDao.TABLENAME + " ADD COLUMN \""
|
||||||
|
+ HuaweiWorkoutDataSampleDao.Properties.Frequency.columnName + "\" INTEGER NOT NULL DEFAULT -1";
|
||||||
|
db.execSQL(statement);
|
||||||
|
}
|
||||||
|
if (!DBHelper.existsColumn(HuaweiWorkoutDataSampleDao.TABLENAME, HuaweiWorkoutDataSampleDao.Properties.Altitude.columnName, db)) {
|
||||||
|
final String statement = "ALTER TABLE " + HuaweiWorkoutDataSampleDao.TABLENAME + " ADD COLUMN \""
|
||||||
|
+ HuaweiWorkoutDataSampleDao.Properties.Altitude.columnName + "\" INTEGER DEFAULT NULL";
|
||||||
|
db.execSQL(statement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void downgradeSchema(final SQLiteDatabase db) {
|
||||||
|
}
|
||||||
|
}
|
@ -241,6 +241,8 @@ public class Workout {
|
|||||||
|
|
||||||
public short calories = -1;
|
public short calories = -1;
|
||||||
public short cyclingPower = -1;
|
public short cyclingPower = -1;
|
||||||
|
public short frequency = -1;
|
||||||
|
public Integer altitude = null;
|
||||||
|
|
||||||
public int timestamp = -1; // Calculated timestamp for this data point
|
public int timestamp = -1; // Calculated timestamp for this data point
|
||||||
|
|
||||||
@ -264,6 +266,8 @@ public class Workout {
|
|||||||
", strokeRate=" + strokeRate +
|
", strokeRate=" + strokeRate +
|
||||||
", calories=" + calories +
|
", calories=" + calories +
|
||||||
", cyclingPower=" + cyclingPower +
|
", cyclingPower=" + cyclingPower +
|
||||||
|
", frequency=" + frequency +
|
||||||
|
", altitude=" + altitude +
|
||||||
", timestamp=" + timestamp +
|
", timestamp=" + timestamp +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
@ -372,6 +376,9 @@ public class Workout {
|
|||||||
case 4:
|
case 4:
|
||||||
data.strokeRate = buf.getShort();
|
data.strokeRate = buf.getShort();
|
||||||
break;
|
break;
|
||||||
|
case 5:
|
||||||
|
data.altitude = buf.getInt();
|
||||||
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
// Inner data, parsing into data
|
// Inner data, parsing into data
|
||||||
// TODO: function for readability?
|
// TODO: function for readability?
|
||||||
@ -419,6 +426,9 @@ public class Workout {
|
|||||||
data.calories = buf.getShort();
|
data.calories = buf.getShort();
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
|
data.frequency = buf.getShort();
|
||||||
|
break;
|
||||||
|
case 9:
|
||||||
data.cyclingPower = buf.getShort();
|
data.cyclingPower = buf.getShort();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -1515,7 +1515,9 @@ public class HuaweiSupportProvider {
|
|||||||
data.strokeRate,
|
data.strokeRate,
|
||||||
unknown,
|
unknown,
|
||||||
data.calories,
|
data.calories,
|
||||||
data.cyclingPower
|
data.cyclingPower,
|
||||||
|
data.frequency,
|
||||||
|
data.altitude
|
||||||
);
|
);
|
||||||
dao.insertOrReplace(dataSample);
|
dao.insertOrReplace(dataSample);
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,9 @@ public class HuaweiWorkoutGbParser {
|
|||||||
responseData.strokeRate,
|
responseData.strokeRate,
|
||||||
dataErrorHex,
|
dataErrorHex,
|
||||||
responseData.calories,
|
responseData.calories,
|
||||||
responseData.cyclingPower
|
responseData.cyclingPower,
|
||||||
|
responseData.frequency,
|
||||||
|
responseData.altitude
|
||||||
);
|
);
|
||||||
|
|
||||||
dbHandler.getDaoSession().getHuaweiWorkoutDataSampleDao().insertOrReplace(dataSample);
|
dbHandler.getDaoSession().getHuaweiWorkoutDataSampleDao().insertOrReplace(dataSample);
|
||||||
@ -308,6 +310,13 @@ public class HuaweiWorkoutGbParser {
|
|||||||
int maxCyclingPower = 0;
|
int maxCyclingPower = 0;
|
||||||
int cyclingPower = 0;
|
int cyclingPower = 0;
|
||||||
int cyclingPowerCount = 0;
|
int cyclingPowerCount = 0;
|
||||||
|
int avgAltitude = 0;
|
||||||
|
int altitudeCount = 0;
|
||||||
|
int minAltitude = 0;
|
||||||
|
int maxAltitude = 0;
|
||||||
|
Integer previousAlt = null;
|
||||||
|
int sumAltitudeUp = 0;
|
||||||
|
int sumAltitudeDown = 0;
|
||||||
for (HuaweiWorkoutDataSample dataSample : dataSamples) {
|
for (HuaweiWorkoutDataSample dataSample : dataSamples) {
|
||||||
if (dataSample.getSpeed() != -1) {
|
if (dataSample.getSpeed() != -1) {
|
||||||
speed += dataSample.getSpeed();
|
speed += dataSample.getSpeed();
|
||||||
@ -391,6 +400,22 @@ public class HuaweiWorkoutGbParser {
|
|||||||
if (cp < minCyclingPower)
|
if (cp < minCyclingPower)
|
||||||
minCyclingPower = cp;
|
minCyclingPower = cp;
|
||||||
}
|
}
|
||||||
|
if (dataSample.getAltitude() != null) {
|
||||||
|
int alt = dataSample.getAltitude();
|
||||||
|
avgAltitude += alt;
|
||||||
|
altitudeCount += 1;
|
||||||
|
if (alt > maxAltitude)
|
||||||
|
maxAltitude = alt;
|
||||||
|
if (alt < minAltitude)
|
||||||
|
minAltitude = alt;
|
||||||
|
if (previousAlt != null) {
|
||||||
|
if (alt > previousAlt)
|
||||||
|
sumAltitudeUp += alt - previousAlt;
|
||||||
|
else if (alt < previousAlt)
|
||||||
|
sumAltitudeDown += previousAlt - alt;
|
||||||
|
}
|
||||||
|
previousAlt = alt;
|
||||||
|
}
|
||||||
if (dataSample.getDataErrorHex() != null)
|
if (dataSample.getDataErrorHex() != null)
|
||||||
unknownData = true;
|
unknownData = true;
|
||||||
}
|
}
|
||||||
@ -420,6 +445,8 @@ public class HuaweiWorkoutGbParser {
|
|||||||
heartRate = heartRate / heartRateCount;
|
heartRate = heartRate / heartRateCount;
|
||||||
if (cyclingPowerCount > 0)
|
if (cyclingPowerCount > 0)
|
||||||
cyclingPower = cyclingPower / cyclingPowerCount;
|
cyclingPower = cyclingPower / cyclingPowerCount;
|
||||||
|
if (altitudeCount > 0)
|
||||||
|
avgAltitude = avgAltitude / altitudeCount;
|
||||||
|
|
||||||
if (speedCount > 0) {
|
if (speedCount > 0) {
|
||||||
JSONObject speedJson = new JSONObject();
|
JSONObject speedJson = new JSONObject();
|
||||||
@ -578,6 +605,33 @@ public class HuaweiWorkoutGbParser {
|
|||||||
maxCyclingPowerJson.put("unit", "");
|
maxCyclingPowerJson.put("unit", "");
|
||||||
jsonObject.put(ActivitySummaryEntries.CYCLING_POWER_MAX, maxCyclingPowerJson);
|
jsonObject.put(ActivitySummaryEntries.CYCLING_POWER_MAX, maxCyclingPowerJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (altitudeCount > 0) {
|
||||||
|
JSONObject avgAltitudeJson = new JSONObject();
|
||||||
|
avgAltitudeJson.put("value", avgAltitude);
|
||||||
|
avgAltitudeJson.put("unit", "");
|
||||||
|
jsonObject.put(ActivitySummaryEntries.ALTITUDE_AVG, avgAltitudeJson);
|
||||||
|
|
||||||
|
JSONObject minAltitudeJson = new JSONObject();
|
||||||
|
minAltitudeJson.put("value", minAltitude);
|
||||||
|
minAltitudeJson.put("unit", "");
|
||||||
|
jsonObject.put(ActivitySummaryEntries.ALTITUDE_MIN, minAltitudeJson);
|
||||||
|
|
||||||
|
JSONObject maxAltitudeJson = new JSONObject();
|
||||||
|
maxAltitudeJson.put("value", maxAltitude);
|
||||||
|
maxAltitudeJson.put("unit", "");
|
||||||
|
jsonObject.put(ActivitySummaryEntries.ALTITUDE_MAX, maxAltitudeJson);
|
||||||
|
|
||||||
|
JSONObject sumUpAltitudeJson = new JSONObject();
|
||||||
|
sumUpAltitudeJson.put("value", sumAltitudeUp);
|
||||||
|
sumUpAltitudeJson.put("unit", "");
|
||||||
|
jsonObject.put(ActivitySummaryEntries.ELEVATION_GAIN, sumUpAltitudeJson);
|
||||||
|
|
||||||
|
JSONObject sumDownAltitudeJson = new JSONObject();
|
||||||
|
sumDownAltitudeJson.put("value", sumAltitudeDown);
|
||||||
|
sumDownAltitudeJson.put("unit", "");
|
||||||
|
jsonObject.put(ActivitySummaryEntries.ELEVATION_LOSS, sumDownAltitudeJson);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try (CloseableListIterator<HuaweiWorkoutPaceSample> it = qbPace.build().listIterator()) {
|
try (CloseableListIterator<HuaweiWorkoutPaceSample> it = qbPace.build().listIterator()) {
|
||||||
|
@ -259,6 +259,14 @@ public class TestWorkout {
|
|||||||
byte backFootLanding2 = 0x26;
|
byte backFootLanding2 = 0x26;
|
||||||
byte eversionAngle2 = 0x27;
|
byte eversionAngle2 = 0x27;
|
||||||
|
|
||||||
|
// TODO: Add:
|
||||||
|
// - swolf
|
||||||
|
// - stoke rate
|
||||||
|
// - calories
|
||||||
|
// - cycling power
|
||||||
|
// - frequency
|
||||||
|
// - altitude
|
||||||
|
|
||||||
ByteBuffer headerBuf = ByteBuffer.allocate(14);
|
ByteBuffer headerBuf = ByteBuffer.allocate(14);
|
||||||
headerBuf.putShort(workoutNumber);
|
headerBuf.putShort(workoutNumber);
|
||||||
headerBuf.putShort(dataNumber);
|
headerBuf.putShort(dataNumber);
|
||||||
|
Loading…
Reference in New Issue
Block a user