-
Notifications
You must be signed in to change notification settings - Fork 2
/
WorkoutSummaryViewController.m
133 lines (109 loc) · 4.73 KB
/
WorkoutSummaryViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//
// WorkoutSummaryViewController.m
// Tom Tutorial
//
// Created by Jen Liu on 11/12/13.
// Copyright (c) 2013 MIT PPAT Team Jonathan. All rights reserved.
//
#import "WorkoutSummaryViewController.h"
#import <AVFoundation/AVFoundation.h>
#import "Workout.h"
#import "AppDelegate.h"
#import "SpeakableTime.h"
@interface WorkoutSummaryViewController ()
@end
@implementation WorkoutSummaryViewController
@synthesize workout, savedSender;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
NSLog(@"workout time: %@", self.workout.totalTime);
self.totalTime.text = [NSString stringWithFormat: @"Total time: %@", [self.workout getDisplayTime]];
self.totalTime.accessibilityLabel = [NSString stringWithFormat: @"Total time: %@", [self.workout getSpokenTime]];
// Accounts for when the heart rate monitor did not calculate an average heart rate.
NSString *heartRateText = @"Heart rate monitor was not connected.";
if (self.workout.avgHeartRate > 0) {
heartRateText = [NSString stringWithFormat: @"Average Heart Rate: %@", [self.workout getDisplayHR]];
}
self.heartRate.text = heartRateText;
self.heartRate.accessibilityLabel = heartRateText;
// Accounts for when the settings have not been set for the person and no heart rate has been calculated.
NSString *calorieText = @"";
/*
Based on http://fitnowtraining.com/2012/01/formula-for-calories-burned/
Male-> Calories Burned = [(Age x 0.2017) + (Weight x 0.09036) + (Heart Rate x 0.6309) -- 55.0969] x Time / 4.184.
Female-> Calories Burned = [(Age x 0.074) -- (Weight x 0.05741) + (Heart Rate x 0.4472) -- 20.4022] x Time / 4.184.
*/
// Set the values to Jonathan's attribute.
NSInteger age = 58;
NSString *gender = @"Male";
NSInteger weight = 156;
double calculatedCaloriesBurned = 0;
double minutes = [self.workout getTimeInMinutes];
if (self.workout.avgHeartRate > 0 ) {
if ([gender isEqualToString:@"Male"]) {
NSLog(@"Time portion: %f",minutes* 0.6307);
//NSLog(@")([self.workout getHRValue] * 0.6309) - 55.0969) * [self.workout getMinutes] / 4.184
calculatedCaloriesBurned = ((age * 0.2017) + (weight * 0.09036) + ([self.workout getHRValue] * 0.6309) - 55.0969) * minutes / 4.184;
NSLog(@"%f", calculatedCaloriesBurned);
}
else if ([gender isEqualToString:@"Female"]) {
calculatedCaloriesBurned = ((age * 0.074) - (weight * 0.05741) + ([self.workout getHRValue] * 0.4472) - 20.4022) * minutes/ 4.184;
}
calorieText = [NSString stringWithFormat:@"Total Calories Burned: %0.1f", calculatedCaloriesBurned];
}
self.caloriesBurned.text = calorieText;
self.caloriesBurned.accessibilityLabel = calorieText;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)onSave
{
AVSpeechSynthesizer *av = [[AVSpeechSynthesizer alloc] init];
AVSpeechUtterance *utterance = [[AVSpeechUtterance alloc]initWithString:@"Workout Saved"];
[av speakUtterance:utterance];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"saveSegue"])
{
[self onSave];
}
}
- (IBAction)deleteWorkout:(id)sender
{
self.savedSender = sender;
UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"Delete Workout Confirmation"
message:@"Do you want to delete this workout?"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"Definitely Delete Workout",@"Cancel", nil];
[message show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0) {
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSManagedObjectContext* context = appDelegate.managedObjectContext;
[context deleteObject:workout];
AVSpeechSynthesizer *av = [[AVSpeechSynthesizer alloc] init];
AVSpeechUtterance *endUtterance = [[AVSpeechUtterance alloc]initWithString:@"Workout Deleted"];
[av speakUtterance:endUtterance];
[self performSegueWithIdentifier:@"Home" sender:self.savedSender];
} else {
// do nothing
}
}
@end