Skip to content

Commit

Permalink
Merge pull request #453 from jmlich/refactoring
Browse files Browse the repository at this point in the history
some refactoring
  • Loading branch information
piggz authored Jan 17, 2025
2 parents a1b3671 + 937ecd1 commit d041569
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 84 deletions.
63 changes: 23 additions & 40 deletions lib/src/amazfish.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,63 +2,46 @@

QString Amazfish::activityToString(Amazfish::ActivityType type)
{
if (type == Amazfish::ActivityType::NotMeasured) {
switch (type) {
case Amazfish::ActivityType::NotMeasured:
return "NotMeasured";
}
if (type == Amazfish::ActivityType::Unknown) {
case Amazfish::ActivityType::Unknown:
return "Unknown";
}
if (type == Amazfish::ActivityType::Activity) {
case Amazfish::ActivityType::Activity:
return "Activity";
}
if (type == Amazfish::ActivityType::LightSleep) {
case Amazfish::ActivityType::LightSleep:
return "LightSleep";
}
if (type == Amazfish::ActivityType::DeepSleep) {
case Amazfish::ActivityType::DeepSleep:
return "DeepSleep";
}
if (type == Amazfish::ActivityType::NotWorn) {
case Amazfish::ActivityType::NotWorn:
return "NotWorn";
}
if (type == Amazfish::ActivityType::Running) {
case Amazfish::ActivityType::Running:
return "Running";
}
if (type == Amazfish::ActivityType::Walking) {
case Amazfish::ActivityType::Walking:
return "Walking";
}
if (type == Amazfish::ActivityType::Swimming) {
case Amazfish::ActivityType::Swimming:
return "Swimming";
}
if (type == Amazfish::ActivityType::Cycling) {
case Amazfish::ActivityType::Cycling:
return "Cycling";
}
if (type == Amazfish::ActivityType::Treadmill) {
case Amazfish::ActivityType::Treadmill:
return "Treadmill";
}
if (type == Amazfish::ActivityType::Exercise) {
case Amazfish::ActivityType::Exercise:
return "Exercise";
}
if (type == Amazfish::ActivityType::OpenSwimming) {
case Amazfish::ActivityType::OpenSwimming:
return "Open Swimming";
}
if (type == Amazfish::ActivityType::IndoorCycling) {
case Amazfish::ActivityType::IndoorCycling:
return "Indoor Cycling";
}
if (type == Amazfish::ActivityType::EllipticalTrainer) {
return "Eliptical Trainer";
}
if (type == Amazfish::ActivityType::JumpRope) {
case Amazfish::ActivityType::EllipticalTrainer:
return "Elliptical Trainer";
case Amazfish::ActivityType::JumpRope:
return "Jump Rope";
}
if (type == Amazfish::ActivityType::Yoga) {
case Amazfish::ActivityType::Yoga:
return "Yoga";
}
if (type == Amazfish::ActivityType::TrailRunning) {
case Amazfish::ActivityType::TrailRunning:
return "Trail Running";
}
if (type == Amazfish::ActivityType::Skiing) {
case Amazfish::ActivityType::Skiing:
return "Skiing";
default:
return "Unknown";
}

return "Unknown";
}
39 changes: 20 additions & 19 deletions ui/qml/pages/HeartratePage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ PagePL {
title: qsTr("Heartrate")

property var day: new Date()
property var relaxed: 0
property var light: 0
property var intensive: 0
property var aerobic: 0
property var anerobic: 0
property var vo2max: 0
property var total: relaxed + light + intensive + aerobic + anerobic + vo2max
property var minhr: 0
property var maxhr: 0
property real relaxed: 0
property real light: 0
property real intensive: 0
property real aerobic: 0
property real anerobic: 0
property real vo2max: 0
property real total: relaxed + light + intensive + aerobic + anerobic + vo2max
property real minhr: 0
property real maxhr: 0

pageMenu: PageMenuPL {
DownloadDataMenuItem{}
Expand Down Expand Up @@ -164,28 +164,29 @@ PagePL {
minhr = 0;
maxhr = 0;
for (var i = 0; i < end; i++) {
if (points[i].y >= (maxHRforAge * 0.9)) {
var point = points[i];
if (point.y >= (maxHRforAge * 0.9)) {
vo2max++;
} else if (points[i].y >= (maxHRforAge * 0.8)) {
} else if (point.y >= (maxHRforAge * 0.8)) {
anerobic++;
} else if (points[i].y >= (maxHRforAge * 0.7)) {
} else if (point.y >= (maxHRforAge * 0.7)) {
aerobic++
} else if (points[i].y >= (maxHRforAge * 0.6)) {
} else if (point.y >= (maxHRforAge * 0.6)) {
intensive++;
} else if (points[i].y >= (maxHRforAge * 0.5)) {
} else if (point.y >= (maxHRforAge * 0.5)) {
light++;
} else {
relaxed++;
}
if (points[i].y > maxhr) {
maxhr = points[i].y;
if (point.y > maxhr) {
maxhr = point.y;
}
if (minhr == 0) {
minhr = points[i].y;
minhr = point.y;
}

if (points[i].y > 0 && points[i].y < minhr) {
minhr = points[i].y;
if (point.y > 0 && point.y < minhr) {
minhr = point.y;
}
}
console.log("relaxed:", relaxed);
Expand Down
3 changes: 1 addition & 2 deletions ui/qml/pages/SportsSummaryPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ PageListPL {
LabelPL
{
id: nameLabel
width: listItem
.width - dateLabel.width - 2*styler.themePaddingLarge
width: listItem.width - dateLabel.width - 2*styler.themePaddingLarge
anchors.top: parent.top
anchors.topMargin: styler.themePaddingMedium
anchors.left: workoutImage.right
Expand Down
52 changes: 29 additions & 23 deletions ui/src/sportsdatamodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,28 +32,33 @@ QHash<int, QByteArray> SportsDataModel::roleNames() const

QVariant SportsDataModel::data(const QModelIndex &index, int role) const
{
if (index.row() >= 0 && index.row() < m_data.length()) {
if (role == SportId) {
return m_data.at(index.row()).id;
} else if (role == SportName) {
return m_data.at(index.row()).name;
} else if (role == SportVersion) {
return m_data.at(index.row()).version;
} else if (role == SportStartDate) {
return m_data.at(index.row()).startDate;
} else if (role == SportEndDate) {
return m_data.at(index.row()).endDate;
} else if (role == SportKind) {
return m_data.at(index.row()).kind;
} else if (role == SportKindString) {
return Amazfish::activityToString((Amazfish::ActivityType)m_data.at(index.row()).kind);
} else if (role == SportBaseLongitude) {
return m_data.at(index.row()).baseLongitude;
} else if (role == SportBaseLatitude) {
return m_data.at(index.row()).baseLatitude;
} else if (role == SportBaseAltitude) {
return m_data.at(index.row()).baseAltitude;
}
if (index.row() < 0 || index.row() > m_data.length()) {
return QVariant();
}

const SportsData &item = m_data.at(index.row());

switch (role) {
case SportId:
return item.id;
case SportName:
return item.name;
case SportVersion:
return item.version;
case SportStartDate:
return item.startDate;
case SportEndDate:
return item.endDate;
case SportKind:
return item.kind;
case SportKindString:
return Amazfish::activityToString((Amazfish::ActivityType)item.kind);
case SportBaseLongitude:
return item.baseLongitude;
case SportBaseLatitude:
return item.baseLongitude;
case SportBaseAltitude:
return item.baseAltitude;
}
return QVariant();
}
Expand All @@ -68,8 +73,8 @@ void SportsDataModel::update()
{
beginResetModel();
QString qry = "SELECT id, name, version, start_timestamp_dt, end_timestamp_dt, kind, base_longitude, base_latitude, base_altitude, gpx FROM sports_data ORDER BY start_timestamp_dt DESC";

m_data.clear();

if (m_connection && m_connection->isDatabaseUsed()) {
KDbCursor *curs = m_connection->executeQuery(KDbEscapedString(qry));
if (curs) {
Expand All @@ -96,6 +101,7 @@ void SportsDataModel::update()
qDebug() << "Error executing query";
}
}

endResetModel();
}

Expand Down

0 comments on commit d041569

Please sign in to comment.