Identify common endurance sports names for endurance athletes

including translations
To ensure consistency in zones assigment and sync.
Other sports can be added as usual.
[publish binaries]
This commit is contained in:
Alejandro Martinez
2021-06-01 20:25:58 -03:00
parent 0ba409a192
commit a5043d1b59
3 changed files with 39 additions and 20 deletions

View File

@@ -328,20 +328,18 @@ Strava::writeFile(QByteArray &data, QString remotename, RideFile *ride)
: QVariant("form-data; name=\"activity_type\""));
// Map some known sports and default to ride for anything else
QString sport = ride->getTag("Sport", "");
QString subSport = ride->getTag("SubSport", "");
if (ride->isRun())
activityTypePart.setBody("run");
activityTypePart.setBody("Run");
else if (ride->isSwim())
activityTypePart.setBody("swim");
else if (sport == "Rowing")
activityTypePart.setBody("Swim");
else if (ride->sport() == "Row")
activityTypePart.setBody("Rowing");
else if (sport == "XC Ski" || sport == "Cross country skiing")
activityTypePart.setBody("BackcountrySki");
else if (sport == "Strength" || subSport == "strength_training")
else if (ride->sport() == "Ski")
activityTypePart.setBody("NordicSki");
else if (ride->sport() == "Gym")
activityTypePart.setBody("WeightTraining");
else
activityTypePart.setBody("ride");
activityTypePart.setBody("Ride");
multiPart->append(activityTypePart);
QHttpPart activityNamePart;
@@ -896,6 +894,9 @@ Strava::prepareResponse(QByteArray* data)
if (stype.endsWith("Ride")) ride->setTag("Sport", "Bike");
else if (stype.endsWith("Run")) ride->setTag("Sport", "Run");
else if (stype.endsWith("Swim")) ride->setTag("Sport", "Swim");
else if (stype.endsWith("Rowing")) ride->setTag("Sport", "Row");
else if (stype.endsWith("Ski")) ride->setTag("Sport", "Ski");
else if (stype.startsWith("Weight")) ride->setTag("Sport", "Gym");
else ride->setTag("Sport", stype);
// Set SubSport to preserve the original when Sport was mapped
if (stype != ride->getTag("Sport", "")) ride->setTag("SubSport", stype);

View File

@@ -215,13 +215,31 @@ RideFile::wprimeData()
QString
RideFile::sportTag(QString sport)
{
// Run, Bike and Swim are standarized, all others are up to the user
if (sport == "Bike" || sport == tr("Bike")) return "Bike";
if (sport == "Run" || sport == tr("Run")) return "Run";
if (sport == "Swim" || sport == tr("Swim")) return "Swim";
if (sport == "Row" || sport == tr("Row") ||
sport == "Rowing" || sport == tr("Rowing")) return "Row";
return sport;
// Some sports are standarized, all others are up to the user
static const QHash<QString, QString> sports = {
{ tr("Bike"), "Bike" },
{ "Biking", "Bike" }, { tr("Biking"), "Bike" },
{ "Cycle", "Bike" }, { tr("Cycle"), "Bike" },
{ "Cycling", "Bike" }, { tr("Cycling"), "Bike" },
{ tr("Run"), "Run" },
{ "Running", "Run" }, { tr("Running"), "Run" },
{ tr("Swim"), "Swim" },
{ "Swimming", "Swim" }, { tr("Swimming"), "Swim" },
{ tr("Row"), "Row" },
{ "Rowing", "Row" }, { tr("Rowing"), "Row" },
{ tr("Ski"), "Ski" },
{ "XC Ski", "Ski" }, { tr("XC Ski"), "Ski" },
{ "Cross Country Skiiing", "Ski" }, { tr("Cross Countr Skiing"), "Ski" },
{ tr("Gym"), "Gym" },
{ "Strength", "Gym" }, { tr("Strength"), "Gym" },
};
return sports.value(sport, sport);
}
QString
@@ -240,7 +258,7 @@ RideFile::isBike() const
// for now we just look at Sport and default to Bike when Sport is not
// set and isRun and isSwim are false
return (sportTag(getTag("Sport", "")) == "Bike") ||
(getTag("Sport","") == "" && !isRun() && !isSwim());
(getTag("Sport","").isEmpty() && !isRun() && !isSwim());
}
bool
@@ -249,7 +267,7 @@ RideFile::isRun() const
// for now we just look at Sport and if there are any
// running specific data series in the data when Sport is not set
return (sportTag(getTag("Sport", "")) == "Run") ||
(getTag("Sport","") == "" && (areDataPresent()->rvert || areDataPresent()->rcad || areDataPresent()->rcontact));
(getTag("Sport","").isEmpty() && (areDataPresent()->rvert || areDataPresent()->rcad || areDataPresent()->rcontact));
}
bool
@@ -257,7 +275,7 @@ RideFile::isSwim() const
{
// for now we just look at Sport or presence of length data for lap swims
return (sportTag(getTag("Sport", "")) == "Swim") ||
(getTag("Sport","") == "" && xdata_.value("SWIM", NULL) != NULL);
(getTag("Sport","").isEmpty() && xdata_.value("SWIM", NULL) != NULL);
}
bool

View File

@@ -50,7 +50,7 @@
<fieldtab>"Workout"</fieldtab>
<fieldname>"Sport"</fieldname>
<fieldtype>2</fieldtype>
<fieldvalues>"Bike,Run,Swim,Row"</fieldvalues>
<fieldvalues>"Bike,Run,Swim,Row,Ski,Gym"</fieldvalues>
<fielddiary>1</fielddiary>
</field>
<field>