Client - display stats according to first day of week - fix #23
This commit is contained in:
		@@ -7,6 +7,7 @@
 | 
				
			|||||||
* [#4](https://github.com/SamR1/Fittrackee/issues/4) - Show points on the map when mouse over the chart
 | 
					* [#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
 | 
					* [#14](https://github.com/SamR1/Fittrackee/issues/14) - Display segments informations
 | 
				
			||||||
* [#21](https://github.com/SamR1/Fittrackee/issues/21) - Document the API
 | 
					* [#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
 | 
					* [#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
 | 
					* [#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 
 | 
					* [#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)
 | 
					## Version 0.2.0 - Statistics (2019/07/07)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,6 +7,7 @@
 | 
				
			|||||||
* [#4](https://github.com/SamR1/Fittrackee/issues/4) - Show points on the map when mouse over the chart
 | 
					* [#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
 | 
					* [#14](https://github.com/SamR1/Fittrackee/issues/14) - Display segments informations
 | 
				
			||||||
* [#21](https://github.com/SamR1/Fittrackee/issues/21) - Document the API
 | 
					* [#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
 | 
					* [#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
 | 
					* [#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 
 | 
					* [#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)
 | 
					## Version 0.2.0 - Statistics (2019/07/07)
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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/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/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/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/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>
 | 
					<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>
 | 
					</ul>
 | 
				
			||||||
@@ -167,7 +168,7 @@
 | 
				
			|||||||
<ul class="simple">
 | 
					<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>
 | 
					<li><p><a class="reference external" href="https://github.com/SamR1/Fittrackee/issues/34">#34</a> - Weather is not displayed anymore</p></li>
 | 
				
			||||||
</ul>
 | 
					</ul>
 | 
				
			||||||
<p>In this release 5 issue were closed.</p>
 | 
					<p>In this release 7 issue were closed.</p>
 | 
				
			||||||
</div>
 | 
					</div>
 | 
				
			||||||
</div>
 | 
					</div>
 | 
				
			||||||
<div class="section" id="version-0-2-0-statistics-2019-07-07">
 | 
					<div class="section" id="version-0-2-0-statistics-2019-07-07">
 | 
				
			||||||
 
 | 
				
			|||||||
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							@@ -22,7 +22,11 @@ class Statistics extends React.PureComponent {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  updateData() {
 | 
					  updateData() {
 | 
				
			||||||
    if (this.props.user.id) {
 | 
					    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,
 | 
					      statistics,
 | 
				
			||||||
      statsParams,
 | 
					      statsParams,
 | 
				
			||||||
      displayEmpty,
 | 
					      displayEmpty,
 | 
				
			||||||
 | 
					      user,
 | 
				
			||||||
    } = this.props
 | 
					    } = this.props
 | 
				
			||||||
    if (!displayEmpty && Object.keys(statistics).length === 0) {
 | 
					    if (!displayEmpty && Object.keys(statistics).length === 0) {
 | 
				
			||||||
      return 'No workouts'
 | 
					      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} />
 | 
					    return <StatsChart sports={sports} stats={stats} />
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -49,12 +60,17 @@ export default connect(
 | 
				
			|||||||
    user: state.user,
 | 
					    user: state.user,
 | 
				
			||||||
  }),
 | 
					  }),
 | 
				
			||||||
  dispatch => ({
 | 
					  dispatch => ({
 | 
				
			||||||
    loadActivities: (userId, data) => {
 | 
					    loadActivities: (userId, weekm, data) => {
 | 
				
			||||||
      const dateFormat = 'yyyy-MM-dd'
 | 
					      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 = {
 | 
					      const params = {
 | 
				
			||||||
        from: format(data.start, dateFormat),
 | 
					        from: format(data.start, dateFormat),
 | 
				
			||||||
        to: format(data.end, dateFormat),
 | 
					        to: format(data.end, dateFormat),
 | 
				
			||||||
        time: data.duration,
 | 
					        time: time,
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      dispatch(getStats(userId, data.type, params))
 | 
					      dispatch(getStats(userId, data.type, params))
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -53,10 +53,10 @@ const dateIncrement = (duration, day) => {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const startDate = (duration, day) => {
 | 
					const startDate = (duration, day, weekm) => {
 | 
				
			||||||
  switch (duration) {
 | 
					  switch (duration) {
 | 
				
			||||||
    case 'week':
 | 
					    case 'week':
 | 
				
			||||||
      return startOfWeek(day)
 | 
					      return startOfWeek(day, { weekStartsOn: weekm ? 1 : 0 })
 | 
				
			||||||
    case 'year':
 | 
					    case 'year':
 | 
				
			||||||
      return startOfYear(day)
 | 
					      return startOfYear(day)
 | 
				
			||||||
    case 'month':
 | 
					    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 nbActivitiesStats = []
 | 
				
			||||||
  const distanceStats = []
 | 
					  const distanceStats = []
 | 
				
			||||||
  const durationStats = []
 | 
					  const durationStats = []
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  for (
 | 
					  for (
 | 
				
			||||||
    let day = startDate(params.duration, params.start);
 | 
					    let day = startDate(params.duration, params.start, weekm);
 | 
				
			||||||
    day <= params.end;
 | 
					    day <= params.end;
 | 
				
			||||||
    day = dateIncrement(params.duration, day)
 | 
					    day = dateIncrement(params.duration, day)
 | 
				
			||||||
  ) {
 | 
					  ) {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user