API & Client: fix
This commit is contained in:
parent
76b2d5aad2
commit
e7e0a20f89
@ -1,7 +1,7 @@
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
from fittrackee_api import appLog, db
|
||||
from flask import Blueprint, current_app, jsonify, request, send_file
|
||||
@ -41,8 +41,9 @@ def get_activities(auth_user_id):
|
||||
Activity.sport_id == sport_id if sport_id else True,
|
||||
Activity.activity_date >= datetime.strptime(date_from, '%Y-%m-%d')
|
||||
if date_from else True,
|
||||
Activity.activity_date <= datetime.strptime(date_to, '%Y-%m-%d')
|
||||
if date_to else True,
|
||||
Activity.activity_date < (
|
||||
datetime.strptime(date_to, '%Y-%m-%d') + timedelta(days=1)
|
||||
) if date_to else True,
|
||||
Activity.distance >= int(distance_from) if distance_from else True,
|
||||
Activity.distance <= int(distance_to) if distance_to else True,
|
||||
Activity.duration >= convert_in_duration(duration_from)
|
||||
|
@ -43,8 +43,9 @@ def get_activities(user_id, type):
|
||||
Activity.user_id == user_id,
|
||||
Activity.activity_date >= datetime.strptime(date_from, '%Y-%m-%d')
|
||||
if date_from else True,
|
||||
Activity.activity_date <= datetime.strptime(date_to, '%Y-%m-%d')
|
||||
if date_to else True,
|
||||
Activity.activity_date < (
|
||||
datetime.strptime(date_to, '%Y-%m-%d') + timedelta(days=1)
|
||||
) if date_to else True,
|
||||
Activity.sport_id == sport_id if sport_id else True,
|
||||
).order_by(
|
||||
Activity.activity_date.asc()
|
||||
|
@ -87,15 +87,18 @@ class User(db.Model):
|
||||
nb_activity = Activity.query.filter(
|
||||
Activity.user_id == self.id
|
||||
).count()
|
||||
sports = db.session.query(
|
||||
func.count(Activity.sport_id)
|
||||
).group_by(
|
||||
Activity.sport_id
|
||||
).all()
|
||||
total = db.session.query(
|
||||
func.sum(Activity.distance),
|
||||
func.sum(Activity.duration)
|
||||
).first()
|
||||
sports = []
|
||||
total = (None, None)
|
||||
if nb_activity > 0:
|
||||
sports = db.session.query(
|
||||
func.count(Activity.sport_id)
|
||||
).group_by(
|
||||
Activity.sport_id
|
||||
).all()
|
||||
total = db.session.query(
|
||||
func.sum(Activity.distance),
|
||||
func.sum(Activity.duration)
|
||||
).first()
|
||||
return {
|
||||
'id': self.id,
|
||||
'username': self.username,
|
||||
|
@ -135,9 +135,9 @@ export const getMoreActivities = params => dispatch => FitTrackeeGenericApi
|
||||
})
|
||||
.catch(error => dispatch(setError(`activities: ${error}`)))
|
||||
|
||||
export const getMonthActivities = (start, end) => dispatch =>
|
||||
export const getMonthActivities = (from, to) => dispatch =>
|
||||
FitTrackeeGenericApi
|
||||
.getData('activities', { start, end, order: 'asc', per_page: 100 })
|
||||
.getData('activities', { from, to, order: 'asc', per_page: 100 })
|
||||
.then(ret => {
|
||||
if (ret.status === 'success') {
|
||||
if (ret.data.activities.length > 0) {
|
||||
@ -146,8 +146,8 @@ export const getMonthActivities = (start, end) => dispatch =>
|
||||
ret.data.activities[i].activity_date
|
||||
)
|
||||
}
|
||||
dispatch(updateCalendar(ret.data.activities))
|
||||
}
|
||||
dispatch(updateCalendar(ret.data.activities))
|
||||
} else {
|
||||
dispatch(setError(`activities: ${ret.message}`))
|
||||
}
|
||||
|
@ -11,7 +11,10 @@ function FormWithoutGpx (props) {
|
||||
const { activity, onAddOrEdit, sports } = props
|
||||
let activityDate, activityTime, sportId = ''
|
||||
if (activity) {
|
||||
const activityDateTime = formatActivityDate(activity.activity_date)
|
||||
const activityDateTime = formatActivityDate(
|
||||
activity.activity_date,
|
||||
'YYYY-MM-DD'
|
||||
)
|
||||
activityDate = activityDateTime.activity_date
|
||||
activityTime = activityDateTime.activity_time
|
||||
sportId = activity.sport_id
|
||||
|
@ -302,7 +302,6 @@ input, textarea {
|
||||
height: 3em;
|
||||
border-right: 1px solid var(--border-color);
|
||||
overflow: hidden;
|
||||
cursor: pointer;
|
||||
background: var(--neutral-color);
|
||||
}
|
||||
|
||||
|
@ -128,8 +128,8 @@ export default connect(
|
||||
loadMonthActivities: (userId, start, end) => {
|
||||
const dateFormat = 'YYYY-MM-DD'
|
||||
const params = {
|
||||
start: format(start, dateFormat),
|
||||
end: format(end, dateFormat),
|
||||
from: format(start, dateFormat),
|
||||
to: format(end, dateFormat),
|
||||
time: 'week'
|
||||
}
|
||||
dispatch(getStats(userId, 'by_time', params))
|
||||
|
@ -3,6 +3,13 @@ import React from 'react'
|
||||
|
||||
export default function UserStatistics (props) {
|
||||
const { user } = props
|
||||
const days = user.totalDuration.match(/day/g)
|
||||
? `${user.totalDuration.split(',')[0]},`
|
||||
: '0 days,'
|
||||
let duration = user.totalDuration.match(/day/g)
|
||||
? user.totalDuration.split(', ')[1]
|
||||
: user.totalDuration
|
||||
duration = `${duration.split(':')[0]}h ${duration.split(':')[1]}min`
|
||||
return (
|
||||
<div className="row">
|
||||
<div className="col">
|
||||
@ -26,7 +33,7 @@ export default function UserStatistics (props) {
|
||||
</div>
|
||||
<div className="col-9 text-right">
|
||||
<div className="huge">
|
||||
{Math.round(user.totalDistance * 100) / 100}
|
||||
{Number(user.totalDistance).toFixed(2)}
|
||||
</div>
|
||||
<div>km</div>
|
||||
</div>
|
||||
@ -40,8 +47,8 @@ export default function UserStatistics (props) {
|
||||
<i className="fa fa-clock-o fa-3x fa-color" />
|
||||
</div>
|
||||
<div className="col-9 text-right">
|
||||
<div className="huge">{user.totalDuration}</div>
|
||||
<div>total duration</div>
|
||||
<div className="huge">{days}</div>
|
||||
<div>{duration}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -10,10 +10,19 @@ class Logout extends React.Component {
|
||||
}
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
<p className="App-center">
|
||||
You are now logged out.
|
||||
Click <Link to="/login">here</Link> to log back in.</p>
|
||||
<div className="container dashboard">
|
||||
<div className="row">
|
||||
<div className="col-2" />
|
||||
<div className="card col-8">
|
||||
<div className="card-body">
|
||||
<div className="text-center">
|
||||
You are now logged out.
|
||||
Click <Link to="/login">here</Link> to log back in.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="col-2" />
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
@ -63,11 +63,14 @@ export const getGeoJson = gpxContent => {
|
||||
return { jsonData }
|
||||
}
|
||||
|
||||
export const formatActivityDate = activityDateTime => {
|
||||
export const formatActivityDate = (activityDateTime, dateFormat = null) => {
|
||||
if (activityDateTime) {
|
||||
const dateTime = parse(activityDateTime)
|
||||
return {
|
||||
activity_date: format(dateTime, 'DD/MM/YYYY'),
|
||||
activity_date: format(
|
||||
dateTime,
|
||||
dateFormat ? dateFormat : 'DD/MM/YYYY'
|
||||
),
|
||||
activity_time: activityDateTime.match(/[0-2][0-9]:[0-5][0-9]/)[0]
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user