API: add date for weeks statistics

This commit is contained in:
Sam 2018-06-06 13:45:39 +02:00
parent 3621bf87d2
commit 0128985664
2 changed files with 33 additions and 25 deletions

View File

@ -1,4 +1,4 @@
from datetime import datetime from datetime import datetime, timedelta
from flask import Blueprint, jsonify, request from flask import Blueprint, jsonify, request
from mpwo_api import appLog from mpwo_api import appLog
@ -67,9 +67,17 @@ def get_activities(user_id, type):
else: else:
if time == 'week': if time == 'week':
time_period = datetime.strftime(activity.activity_date, "%Y-W%U") # noqa activity_date = activity.activity_date - timedelta(
days=activity.activity_date.isoweekday()
)
time_period = datetime.strftime(activity_date,
"%Y-%m-%d_W%U")
elif time == 'weekm': # week start Monday elif time == 'weekm': # week start Monday
time_period = datetime.strftime(activity.activity_date, "%Y-W%W") # noqa activity_date = activity.activity_date - timedelta(
days=activity.activity_date.weekday()
)
time_period = datetime.strftime(activity_date,
"%Y-%m-%d_W%W")
elif time == 'month': elif time == 'month':
time_period = datetime.strftime(activity.activity_date, "%Y-%m") # noqa time_period = datetime.strftime(activity.activity_date, "%Y-%m") # noqa
elif time == 'year' or not time: elif time == 'year' or not time:

View File

@ -468,7 +468,7 @@ def test_get_stats_by_week_all_activities(
assert 'success' in data['status'] assert 'success' in data['status']
assert data['data']['statistics'] == \ assert data['data']['statistics'] == \
{ {
'2017-W12': '2017-03-19_W12':
{ {
'1': '1':
{ {
@ -477,7 +477,7 @@ def test_get_stats_by_week_all_activities(
'total_duration': 1024 'total_duration': 1024
} }
}, },
'2017-W22': '2017-05-28_W22':
{ {
'1': '1':
{ {
@ -486,7 +486,7 @@ def test_get_stats_by_week_all_activities(
'total_duration': 3456 'total_duration': 3456
} }
}, },
'2018-W00': '2017-12-31_W53':
{ {
'1': '1':
{ {
@ -495,7 +495,16 @@ def test_get_stats_by_week_all_activities(
'total_duration': 1024 'total_duration': 1024
} }
}, },
'2018-W13': '2018-02-18_W07':
{
'1':
{
'nb_activities': 2,
'total_distance': 11.0,
'total_duration': 1600
}
},
'2018-03-25_W12':
{ {
'1': '1':
{ {
@ -510,16 +519,7 @@ def test_get_stats_by_week_all_activities(
'total_duration': 6000 'total_duration': 6000
} }
}, },
'2018-W07': '2018-05-06_W18':
{
'1':
{
'nb_activities': 2,
'total_distance': 11.0,
'total_duration': 1600
}
},
'2018-W18':
{ {
'1': '1':
{ {
@ -558,7 +558,7 @@ def test_get_stats_by_week_all_activities_week_13(
assert 'success' in data['status'] assert 'success' in data['status']
assert data['data']['statistics'] == \ assert data['data']['statistics'] == \
{ {
'2018-W13': '2018-03-25_W12':
{ {
'1': '1':
{ {
@ -603,7 +603,7 @@ def test_get_stats_by_weekm_all_activities(
assert 'success' in data['status'] assert 'success' in data['status']
assert data['data']['statistics'] == \ assert data['data']['statistics'] == \
{ {
'2017-W12': '2017-03-20_W12':
{ {
'1': '1':
{ {
@ -612,7 +612,7 @@ def test_get_stats_by_weekm_all_activities(
'total_duration': 1024 'total_duration': 1024
} }
}, },
'2017-W22': '2017-05-29_W22':
{ {
'1': '1':
{ {
@ -621,7 +621,7 @@ def test_get_stats_by_weekm_all_activities(
'total_duration': 3456 'total_duration': 3456
} }
}, },
'2018-W01': '2018-01-01_W01':
{ {
'1': '1':
{ {
@ -630,7 +630,7 @@ def test_get_stats_by_weekm_all_activities(
'total_duration': 1024 'total_duration': 1024
} }
}, },
'2018-W08': '2018-02-19_W08':
{ {
'1': '1':
{ {
@ -639,7 +639,7 @@ def test_get_stats_by_weekm_all_activities(
'total_duration': 1600 'total_duration': 1600
} }
}, },
'2018-W13': '2018-03-26_W13':
{ {
'1': '1':
{ {
@ -654,7 +654,7 @@ def test_get_stats_by_weekm_all_activities(
'total_duration': 6000 'total_duration': 6000
} }
}, },
'2018-W19': '2018-05-07_W19':
{ {
'1': '1':
{ {
@ -693,7 +693,7 @@ def test_get_stats_by_weekm_all_activities_week_13(
assert 'success' in data['status'] assert 'success' in data['status']
assert data['data']['statistics'] == \ assert data['data']['statistics'] == \
{ {
'2018-W13': '2018-03-26_W13':
{ {
'1': '1':
{ {