def personalworkoutchart(request): user = request.user.username #when there is a post - render the request chart for the user if request.POST: form = graphrequestform(request.POST) if form.is_valid(): data = form.cleaned_data monthint = int(data['month']) titlestring = 'Workouts for the Month of %s' % calendar.month_name[monthint] #set output based on workout chart style requested (weight style) if data['style'] == 'Weights Workout': #set chartit values workoutdata = \ DataPool( series = [{'options': { 'source': Workout.objects.filter(username=user, weights_type='CHEST', month=data['month'] )}, 'terms': [ {'day_chest': 'day'}, {'Chest Weight': 'weight'}]}, {'options': { 'source': Workout.objects.filter(username=user, weights_type='LEGS', month=data['month'] )}, 'terms': [ {'day_legs': 'day'}, {'Legs Weight': 'weight'}]}, {'options': { 'source': Workout.objects.filter(username=user, weights_type='BACK', month=data['month'] )}, 'terms': [ {'day_back': 'day'}, {'Back Weight': 'weight'}]}, ]) #more chartit valued cht = Chart( datasource = workoutdata, series_options = [{'options':{ 'type': 'column', 'stacking': False}, 'terms': { 'day_chest': [ 'Chest Weight'], 'day_legs': [ 'Legs Weight'], 'day_back': [ 'Back Weight'], }}], chart_options = {'title': { 'text': titlestring }, 'xAxis': { 'title': { 'text': 'Weights by Day'}}}) return render_to_response('chart.html', {'workoutchart':cht}) #set workout type based on cardio type else: #set chartit values workoutdata = \ DataPool( series = [{'options': { 'source': Workout.objects.filter(username=user, cardio_type='TREADMILL', month = data['month'] )}, 'terms': [ {'day_treadmill': 'day'}, {'Treadmill Duration': 'time'}]}, {'options': { 'source': Workout.objects.filter(username=user, cardio_type='STAIRS', month = data['month'] )}, 'terms': [ {'day_stairs': 'day'}, {'Stairs Duration': 'time'}]}, {'options': { 'source': Workout.objects.filter(username=user, cardio_type='ROWING', month = data['month'] )}, 'terms': [ {'day_rowing': 'day'}, {'Rowing Duration': 'time'}]}, ]) cht = Chart( datasource = workoutdata, series_options = [{'options':{ 'type': 'column', 'stacking':False}, 'terms': { 'day_treadmill': [ 'Treadmill Duration'], 'day_stairs': [ 'Stairs Duration' ], 'day_rowing': [ 'Rowing Duration' ], }}], chart_options = {'title': { 'text': titlestring}, 'xAxis': { 'title': { 'text': 'Workout Duration by Day'}}}) return render_to_response('chart.html', {'workoutchart':cht}) #if the user didn't post, set the form else: form = graphrequestform() args = {} args.update(csrf(request)) args['form'] = form return render_to_response('requestworkout.html', args)
def myProfile(request): user = request.user.username args = {} args['profile'] = Profile.objects.get(username=user) args['user_auth'] = User.objects.get(username=user) args['my_chest_workouts'] = Workout.objects.filter(username=user, weights_type='CHEST').count() args['my_legs_workouts'] = Workout.objects.filter(username=user, weights_type='LEGS').count() args['my_back_workouts'] = Workout.objects.filter(username=user, weights_type='BACK').count() args['my_treadmill_workouts'] = Workout.objects.filter(username=user, cardio_type='TREADMILL').count() args['my_stairs_workouts'] = Workout.objects.filter(username=user, cardio_type='STAIRS').count() args['my_rowing_workouts'] = Workout.objects.filter(username=user, cardio_type='ROWING').count() today = datetime.date.today() form = graphrequestform() args.update(csrf(request)) args['chartform'] = form weightworkoutdata = \ DataPool( series = [{'options': { 'source': Workout.objects.filter(username=user, weights_type='CHEST', month=today.month )}, 'terms': [ {'day_chest': 'day'}, {'Chest Weight': 'weight'}]}, {'options': { 'source': Workout.objects.filter(username=user, weights_type='LEGS', month=today.month )}, 'terms': [ {'day_legs': 'day'}, {'Legs Weight': 'weight'}]}, {'options': { 'source': Workout.objects.filter(username=user, weights_type='BACK', month=today.month )}, 'terms': [ {'day_back': 'day'}, {'Back Weight': 'weight'}]}, ]) weightworkoutchart = Chart( datasource = weightworkoutdata, series_options = [{'options':{ 'type': 'column', 'stacking': False}, 'terms': { 'day_chest': [ 'Chest Weight'], 'day_legs': [ 'Legs Weight'], 'day_back': [ 'Back Weight'], }}], chart_options = {'title': { 'text': ' '}, 'xAxis': { 'title': { 'text': 'Weights by Day'}}}) cardioworkoutdata = \ DataPool( series = [{'options': { 'source': Workout.objects.filter(username=user, cardio_type='TREADMILL', month = today.month )}, 'terms': [ {'day_treadmill': 'day'}, {'Treadmill Duration': 'time'}]}, {'options': { 'source': Workout.objects.filter(username=user, cardio_type='STAIRS', month = today.month )}, 'terms': [ {'day_stairs': 'day'}, {'Stairs Duration': 'time'}]}, {'options': { 'source': Workout.objects.filter(username=user, cardio_type='ROWING', month = today.month )}, 'terms': [ {'day_rowing': 'day'}, {'Rowing Duration': 'time'}]}, ]) cardioworkoutchart = Chart( datasource = cardioworkoutdata, series_options = [{'options':{ 'type': 'column', 'stacking':False}, 'terms': { 'day_treadmill': [ 'Treadmill Duration'], 'day_stairs': [ 'Stairs Duration'], 'day_rowing': [ 'Rowing Duration'], }}], chart_options = {'title': { 'text': ' '}, 'xAxis': { 'title': { 'text': 'Workout Duration by Day'}}}) charts = [cardioworkoutchart, weightworkoutchart] args['charts'] = charts args['cur_month'] = today.strftime('%B') # Profile Image hash signer = Signer() img_hash = signer.sign('p-img-' + user) args['img_hash'] = img_hash return render_to_response('profiles-index.html', args)
def personalworkoutchart(request): user = request.user.username #when there is a post - render the request chart for the user if request.POST: form = graphrequestform(request.POST) if form.is_valid(): data = form.cleaned_data monthint = int(data['month']) titlestring = 'Workouts for the Month of %s' % calendar.month_name[ monthint] #set output based on workout chart style requested (weight style) if data['style'] == 'Weights Workout': #set chartit values workoutdata = \ DataPool( series = [{'options': { 'source': Workout.objects.filter(username=user, weights_type='CHEST', month=data['month'] )}, 'terms': [ {'day_chest': 'day'}, {'Chest Weight': 'weight'}]}, {'options': { 'source': Workout.objects.filter(username=user, weights_type='LEGS', month=data['month'] )}, 'terms': [ {'day_legs': 'day'}, {'Legs Weight': 'weight'}]}, {'options': { 'source': Workout.objects.filter(username=user, weights_type='BACK', month=data['month'] )}, 'terms': [ {'day_back': 'day'}, {'Back Weight': 'weight'}]}, ]) #more chartit valued cht = Chart(datasource=workoutdata, series_options=[{ 'options': { 'type': 'column', 'stacking': False }, 'terms': { 'day_chest': ['Chest Weight'], 'day_legs': ['Legs Weight'], 'day_back': ['Back Weight'], } }], chart_options={ 'title': { 'text': titlestring }, 'xAxis': { 'title': { 'text': 'Weights by Day' } } }) return render_to_response('chart.html', {'workoutchart': cht}) #set workout type based on cardio type else: #set chartit values workoutdata = \ DataPool( series = [{'options': { 'source': Workout.objects.filter(username=user, cardio_type='TREADMILL', month = data['month'] )}, 'terms': [ {'day_treadmill': 'day'}, {'Treadmill Duration': 'time'}]}, {'options': { 'source': Workout.objects.filter(username=user, cardio_type='STAIRS', month = data['month'] )}, 'terms': [ {'day_stairs': 'day'}, {'Stairs Duration': 'time'}]}, {'options': { 'source': Workout.objects.filter(username=user, cardio_type='ROWING', month = data['month'] )}, 'terms': [ {'day_rowing': 'day'}, {'Rowing Duration': 'time'}]}, ]) cht = Chart(datasource=workoutdata, series_options=[{ 'options': { 'type': 'column', 'stacking': False }, 'terms': { 'day_treadmill': ['Treadmill Duration'], 'day_stairs': ['Stairs Duration'], 'day_rowing': ['Rowing Duration'], } }], chart_options={ 'title': { 'text': titlestring }, 'xAxis': { 'title': { 'text': 'Workout Duration by Day' } } }) return render_to_response('chart.html', {'workoutchart': cht}) #if the user didn't post, set the form else: form = graphrequestform() args = {} args.update(csrf(request)) args['form'] = form return render_to_response('requestworkout.html', args)