Client - display stats according to first day of week - fix #23

This commit is contained in:
Sam 2019-08-31 17:56:10 +02:00
parent eb81c63714
commit 1dd7c0d8af
6 changed files with 31 additions and 12 deletions

View File

@ -7,6 +7,7 @@
* [#4](https://github.com/SamR1/Fittrackee/issues/4) - Show points on the map when mouse over the chart
* [#14](https://github.com/SamR1/Fittrackee/issues/14) - Display segments informations
* [#21](https://github.com/SamR1/Fittrackee/issues/21) - Document the API
* [#23](https://github.com/SamR1/Fittrackee/issues/23) - The user can choose the first day of the week
* [#36](https://github.com/SamR1/Fittrackee/issues/36) - Disable user registration
* [#33](https://github.com/SamR1/Fittrackee/issues/33) - Add file size limit on file upload
@ -14,7 +15,7 @@
* [#34](https://github.com/SamR1/Fittrackee/issues/34) - Weather is not displayed anymore
In this release 5 issue were closed.
In this release 7 issue were closed.
## Version 0.2.0 - Statistics (2019/07/07)

View File

@ -7,6 +7,7 @@
* [#4](https://github.com/SamR1/Fittrackee/issues/4) - Show points on the map when mouse over the chart
* [#14](https://github.com/SamR1/Fittrackee/issues/14) - Display segments informations
* [#21](https://github.com/SamR1/Fittrackee/issues/21) - Document the API
* [#23](https://github.com/SamR1/Fittrackee/issues/23) - The user can choose the first day of the week
* [#36](https://github.com/SamR1/Fittrackee/issues/36) - Disable user registration
* [#33](https://github.com/SamR1/Fittrackee/issues/33) - Add file size limit on file upload
@ -14,7 +15,7 @@
* [#34](https://github.com/SamR1/Fittrackee/issues/34) - Weather is not displayed anymore
In this release 5 issue were closed.
In this release 7 issue were closed.
## Version 0.2.0 - Statistics (2019/07/07)

View File

@ -158,6 +158,7 @@
<li><p><a class="reference external" href="https://github.com/SamR1/Fittrackee/issues/4">#4</a> - Show points on the map when mouse over the chart</p></li>
<li><p><a class="reference external" href="https://github.com/SamR1/Fittrackee/issues/14">#14</a> - Display segments informations</p></li>
<li><p><a class="reference external" href="https://github.com/SamR1/Fittrackee/issues/21">#21</a> - Document the API</p></li>
<li><p><a class="reference external" href="https://github.com/SamR1/Fittrackee/issues/23">#23</a> - The user can choose the first day of the week</p></li>
<li><p><a class="reference external" href="https://github.com/SamR1/Fittrackee/issues/36">#36</a> - Disable user registration</p></li>
<li><p><a class="reference external" href="https://github.com/SamR1/Fittrackee/issues/33">#33</a> - Add file size limit on file upload</p></li>
</ul>
@ -167,7 +168,7 @@
<ul class="simple">
<li><p><a class="reference external" href="https://github.com/SamR1/Fittrackee/issues/34">#34</a> - Weather is not displayed anymore</p></li>
</ul>
<p>In this release 5 issue were closed.</p>
<p>In this release 7 issue were closed.</p>
</div>
</div>
<div class="section" id="version-0-2-0-statistics-2019-07-07">

File diff suppressed because one or more lines are too long

View File

@ -22,7 +22,11 @@ class Statistics extends React.PureComponent {
updateData() {
if (this.props.user.id) {
this.props.loadActivities(this.props.user.id, this.props.statsParams)
this.props.loadActivities(
this.props.user.id,
this.props.user.weekm,
this.props.statsParams
)
}
}
@ -33,11 +37,18 @@ class Statistics extends React.PureComponent {
statistics,
statsParams,
displayEmpty,
user,
} = this.props
if (!displayEmpty && Object.keys(statistics).length === 0) {
return 'No workouts'
}
const stats = formatStats(statistics, sports, statsParams, displayedSports)
const stats = formatStats(
statistics,
sports,
statsParams,
displayedSports,
user.weekm
)
return <StatsChart sports={sports} stats={stats} />
}
}
@ -49,12 +60,17 @@ export default connect(
user: state.user,
}),
dispatch => ({
loadActivities: (userId, data) => {
loadActivities: (userId, weekm, data) => {
const dateFormat = 'yyyy-MM-dd'
// depends on user config (first day of week)
const time =
data.duration === 'week'
? `${data.duration}${weekm ? 'm' : ''}`
: data.duration
const params = {
from: format(data.start, dateFormat),
to: format(data.end, dateFormat),
time: data.duration,
time: time,
}
dispatch(getStats(userId, data.type, params))
},

View File

@ -53,10 +53,10 @@ const dateIncrement = (duration, day) => {
}
}
const startDate = (duration, day) => {
const startDate = (duration, day, weekm) => {
switch (duration) {
case 'week':
return startOfWeek(day)
return startOfWeek(day, { weekStartsOn: weekm ? 1 : 0 })
case 'year':
return startOfYear(day)
case 'month':
@ -65,13 +65,13 @@ const startDate = (duration, day) => {
}
}
export const formatStats = (stats, sports, params, displayedSports) => {
export const formatStats = (stats, sports, params, displayedSports, weekm) => {
const nbActivitiesStats = []
const distanceStats = []
const durationStats = []
for (
let day = startDate(params.duration, params.start);
let day = startDate(params.duration, params.start, weekm);
day <= params.end;
day = dateIncrement(params.duration, day)
) {