Skip to content

Commit

Permalink
Merge pull request #84 from paf38/master
Browse files Browse the repository at this point in the history
Add elevation into stats and dashboard and new sports
  • Loading branch information
SamR1 committed Sep 1, 2021
2 parents c944478 + 43fe9bd commit 62362fe
Show file tree
Hide file tree
Showing 16 changed files with 132 additions and 13 deletions.
20 changes: 20 additions & 0 deletions fittrackee/database_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,34 @@ def init_database(app: Flask) -> None:
sport.img = '/img/sports/mountain-biking.png'
sport.is_default = True
db.session.add(sport)
sport = Sport(label='Mountain Biking (Electric)')
sport.img = '/img/sports/electric-mountain-biking.png'
sport.is_default = True
db.session.add(sport)
sport = Sport(label='Running')
sport.img = '/img/sports/running.png'
sport.is_default = True
db.session.add(sport)
sport = Sport(label='Trail')
sport.img = '/img/sports/trail.png'
sport.is_default = True
db.session.add(sport)
sport = Sport(label='Walking')
sport.img = '/img/sports/walking.png'
sport.is_default = True
db.session.add(sport)
sport = Sport(label='Skiing (Alpine)')
sport.img = '/img/sports/alpine-skiing.png'
sport.is_default = True
db.session.add(sport)
sport = Sport(label='Skiing (Cross Country)')
sport.img = '/img/sports/cross-country-skiing.png'
sport.is_default = True
db.session.add(sport)
sport = Sport(label='Rowing')
sport.img = '/img/sports/rowing.png'
sport.is_default = True
db.session.add(sport)
db.session.commit()
_, db_app_config = init_config()
update_app_config_from_database(app, db_app_config)
Expand Down
21 changes: 19 additions & 2 deletions fittrackee/workouts/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ def get_workouts(
'nb_workouts': 0,
'total_distance': 0.0,
'total_duration': 0,
'total_ascent': 0.0,
'total_descent': 0.0,
}
workouts_list_by_sport[sport_id]['nb_workouts'] += 1
workouts_list_by_sport[sport_id]['total_distance'] += float(
Expand All @@ -75,6 +77,12 @@ def get_workouts(
workouts_list_by_sport[sport_id][
'total_duration'
] += convert_timedelta_to_integer(workout.moving)
workouts_list_by_sport[sport_id]['total_ascent'] += float(
workout.ascent
)
workouts_list_by_sport[sport_id]['total_descent'] += float(
workout.descent
)

# filter_type == 'by_time'
else:
Expand Down Expand Up @@ -110,6 +118,8 @@ def get_workouts(
'nb_workouts': 0,
'total_distance': 0.0,
'total_duration': 0,
'total_ascent': 0.0,
'total_descent': 0.0,
}
workouts_list_by_time[time_period][sport_id][
'nb_workouts'
Expand All @@ -119,8 +129,15 @@ def get_workouts(
] += float(workout.distance)
workouts_list_by_time[time_period][sport_id][
'total_duration'
] += convert_timedelta_to_integer(workout.moving)

] += convert_timedelta_to_integer(workout.moving)
if workout.ascent:
workouts_list_by_time[time_period][sport_id][
'total_ascent'
] += float(workout.ascent / 1000)
if workout.descent:
workouts_list_by_time[time_period][sport_id][
'total_descent'
] += float(workout.descent / 1000)
return {
'status': 'success',
'data': {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added fittrackee_client/public/img/sports/trail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions fittrackee_client/src/components/Common/Stats/StatsChart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,24 @@ export default class StatsCharts extends React.PureComponent {
/>
{t('statistics:duration')}
</label>
<label className="radioLabel col">
<input
type="radio"
name="ascent"
checked={displayedData === 'ascent'}
onChange={e => this.handleRadioChange(e)}
/>
{t('statistics:ascent')}
</label>
<label className="radioLabel col">
<input
type="radio"
name="descent"
checked={displayedData === 'descent'}
onChange={e => this.handleRadioChange(e)}
/>
{t('statistics:descent')}
</label>
<label className="radioLabel col">
<input
type="radio"
Expand Down
18 changes: 18 additions & 0 deletions fittrackee_client/src/components/Dashboard/WorkoutCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,25 @@ export default function WorkoutCard(props) {
)}
<i className="fa fa-road" aria-hidden="true" />{' '}
{t('workouts:Distance')}: {workout.distance} km
<br />
</p>
{workout.min_alt && workout.max_alt && (
<p>
<i className="fi-mountains custom-fa" />
{t('workouts:Min. altitude')}: {workout.min_alt}m
<br />
{t('workouts:Max. altitude')}: {workout.max_alt}m
<br />
</p>
)}
{workout.ascent && workout.descent && (
<p>
<i className="fa fa-location-arrow custom-fa" />
{t('workouts:Ascent')}: {workout.ascent}m
<br />
{t('workouts:Descent')}: {workout.descent}m
</p>
)}
</div>
</div>
</div>
Expand Down
14 changes: 14 additions & 0 deletions fittrackee_client/src/components/Workouts/WorkoutsList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export default class WorkoutsList extends React.PureComponent {
<th scope="col">{t('workouts:Duration')}</th>
<th scope="col">{t('workouts:Ave. speed')}</th>
<th scope="col">{t('workouts:Max. speed')}</th>
<th scope="col">{t('workouts:Ascent')}</th>
<th scope="col">{t('workouts:Descent')}</th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -85,6 +87,18 @@ export default class WorkoutsList extends React.PureComponent {
</span>
{workout.max_speed} km/h
</td>
<td className="text-right">
<span className="heading-span-absolute">
{t('workouts:Ascent')}
</span>
{workout.ascent} m
</td>
<td className="text-right">
<span className="heading-span-absolute">
{t('workouts:Descent')}
</span>
{workout.descent} m
</td>
</tr>
))}
</tbody>
Expand Down
7 changes: 6 additions & 1 deletion fittrackee_client/src/locales/en/sports.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
"Cycling (Transport)": "Cycling (Transport)",
"Hiking": "Hiking",
"Mountain Biking": "Mountain Biking",
"Mountain Biking (Electric)": "Mountain Biking (Electric)",
"Running": "Running",
"Walking": "Walking"
"Walking": "Walking",
"Trail" : "Trail",
"Skiing (Alpine)" : "Skiing (Alpine)",
"Skiing (Cross Country)" : "Skiing (Cross Country)",
"Rowing" : "Rowing"
}
2 changes: 2 additions & 0 deletions fittrackee_client/src/locales/en/statistics.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"workouts": "workouts",
"distance": "distance",
"duration": "duration",
"ascent": "ascent",
"descent": "descent",
"month": "month",
"Statistics": "Statistics",
"year": "year",
Expand Down
7 changes: 6 additions & 1 deletion fittrackee_client/src/locales/fr/sports.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
"Cycling (Transport)": "Vélo (Transport)",
"Hiking": "Randonnée",
"Mountain Biking": "VTT",
"Mountain Biking (Electric)": "VTT (Electrique)",
"Running": "Course",
"Walking": "Marche"
"Walking": "Marche",
"Trail" : "Trail",
"Skiing (Alpine)" : "Ski (Alpin)",
"Skiing (Cross Country)" : "Ski (Randonnée)",
"Rowing" : "Aviron"
}
2 changes: 2 additions & 0 deletions fittrackee_client/src/locales/fr/statistics.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
"workouts": "séances",
"distance": "distance",
"duration": "durée",
"ascent": "dénivelé+",
"descent": "dénivelé-",
"month": "mois",
"Statistics": "Statistiques",
"year": "année",
Expand Down
4 changes: 2 additions & 2 deletions fittrackee_client/src/locales/fr/workouts.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
"Add a workout": "Ajouter une séance",
"Are you sure you want to delete this workout?": "Etes-vous sûr de vouloir supprimer cette séance ?",
"Ave. speed": "Vitesse moyenne",
"Ascent": "Dénivelé positif",
"Ascent": "Dénivelé +",
"Average speed": "Vitesse moyenne",
"Chart": "Analyse",
"data from gpx, without any cleaning": "données issues du fichier gpx, sans correction",
"Date": "Date",
"Delete workout": "Supprimer l'séance",
"Descent": "Dénivelé négatif",
"Descent": "Dénivelé -",
"Distance": "Distance",
"distance": "distance",
"Duration": "Durée",
Expand Down
14 changes: 14 additions & 0 deletions fittrackee_client/src/utils/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ export const formatValue = (displayedData, value) =>
? `${value.toFixed(2)} km`
: displayedData === 'duration'
? formatDuration(value)
: displayedData === 'ascent'
? `${value.toFixed(2)} km`
: displayedData === 'descent'
? `${value.toFixed(2)} km`
: value

const dateIncrement = (duration, day) => {
Expand Down Expand Up @@ -69,6 +73,8 @@ export const formatStats = (stats, sports, params, displayedSports, weekm) => {
const nbWorkoutsStats = []
const distanceStats = []
const durationStats = []
const ascentStats = []
const descentStats = []

for (
let day = startDate(params.duration, params.start, weekm);
Expand All @@ -83,6 +89,8 @@ export const formatStats = (stats, sports, params, displayedSports, weekm) => {
const dataNbWorkouts = { date: xAxis }
const dataDistance = { date: xAxis }
const dataDuration = { date: xAxis }
const dataAscent = { date: xAxis }
const dataDescent = { date: xAxis }

if (stats[date]) {
Object.keys(stats[date])
Expand All @@ -94,17 +102,23 @@ export const formatStats = (stats, sports, params, displayedSports, weekm) => {
dataNbWorkouts[sportLabel] = stats[date][sportId].nb_workouts
dataDistance[sportLabel] = stats[date][sportId].total_distance
dataDuration[sportLabel] = stats[date][sportId].total_duration
dataAscent[sportLabel] = stats[date][sportId].total_ascent
dataDescent[sportLabel] = stats[date][sportId].total_descent
return null
})
}
nbWorkoutsStats.push(dataNbWorkouts)
distanceStats.push(dataDistance)
durationStats.push(dataDuration)
ascentStats.push(dataAscent)
descentStats.push(dataDescent)
}

return {
workouts: nbWorkoutsStats,
distance: distanceStats,
duration: durationStats,
ascent: ascentStats,
descent: descentStats,
}
}
18 changes: 11 additions & 7 deletions fittrackee_client/src/utils/workouts.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ import togeojson from '@mapbox/togeojson'
import { getDateWithTZ } from './index'

export const workoutColors = [
'#55a8a3',
'#98C3A9',
'#D0838A',
'#ECC77E',
'#926692',
'#929292',
'#428bca',
'#F94144',
'#F3722C',
'#F8961E',
'#F9844A',
'#F9C74F',
'#90BE6D',
'#43AA8B',
'#4D908E',
'#577590',
'#277DA1',
'#272DA1',
]

export const recordsLabels = [
Expand Down

0 comments on commit 62362fe

Please sign in to comment.