1
00:00:06,180 --> 00:00:13,350
HEY WHAT'S UP GUYS I'M Jacob whatso with deps slopes dot com and in the last lesson we got our duration

2
00:00:13,350 --> 00:00:20,610
label working off of just formatting seconds to show you know hours minutes and seconds so that's really

3
00:00:20,610 --> 00:00:21,350
cool.

4
00:00:21,540 --> 00:00:27,150
And in this one now we're going to get our pace working and then we'll have all the data we need to

5
00:00:27,150 --> 00:00:31,630
finally set up our role models so that's really exciting.

6
00:00:31,650 --> 00:00:36,990
But first before we get started let's open up terminal and I'm going to just create a new branch get

7
00:00:36,990 --> 00:00:41,130
check out Desch be lesson 9.

8
00:00:41,660 --> 00:00:42,650
Right.

9
00:00:42,990 --> 00:00:44,700
And that is good.

10
00:00:44,700 --> 00:00:46,320
Whoops.

11
00:00:46,530 --> 00:00:46,940
OK.

12
00:00:46,950 --> 00:00:52,940
So underneath our update counter function we're going to create a function for pace.

13
00:00:52,950 --> 00:00:56,900
And this is just going to be called calculate calculate pace.

14
00:00:56,910 --> 00:00:57,560
Okay.

15
00:00:57,900 --> 00:01:02,670
And we'll just opening and closing brackets that.

16
00:01:02,760 --> 00:01:05,970
Okay so what do we need to calculate our pace.

17
00:01:05,970 --> 00:01:11,350
We need time and we need distance right so time divided by distance would be your pace.

18
00:01:11,580 --> 00:01:13,780
So let's go ahead and create a function.

19
00:01:14,040 --> 00:01:20,240
We want to pass in time and it's going to be in seconds for us so we can just use our counter and that'll

20
00:01:20,250 --> 00:01:21,980
be of type Integer.

21
00:01:22,530 --> 00:01:24,700
And then we need distance as well.

22
00:01:24,720 --> 00:01:28,370
And that will be miles since we already have that.

23
00:01:28,380 --> 00:01:30,200
And that will be of type double.

24
00:01:30,480 --> 00:01:30,900
Okay.

25
00:01:30,900 --> 00:01:38,030
And then we're going to return a string so we can just simply update our label with this function right.

26
00:01:38,040 --> 00:01:44,760
One thing we're going to need though is we need a pace variable and we want that variable assessable

27
00:01:44,760 --> 00:01:48,980
up here with our distance and counter.

28
00:01:49,730 --> 00:01:55,440
So just so basically when we create our relm object after the runs done we're going to need these three

29
00:01:55,440 --> 00:01:56,220
items.

30
00:01:56,220 --> 00:01:58,850
So let's just make a VAR.

31
00:01:59,610 --> 00:02:05,030
And that is going to be pace and it is also going to be an integer so just equals zero.

32
00:02:06,140 --> 00:02:10,630
And basically when we create our own object we're going to need these three things.

33
00:02:10,670 --> 00:02:19,750
So down here we can just update our pace with just dividing seconds by Miles Right.

34
00:02:19,760 --> 00:02:22,240
So let's just go ahead and do.

35
00:02:22,240 --> 00:02:27,660
Pace equals second.

36
00:02:28,890 --> 00:02:30,080
I should say seconds.

37
00:02:30,110 --> 00:02:30,800
That's kind of weird.

38
00:02:30,800 --> 00:02:32,580
So seconds.

39
00:02:32,870 --> 00:02:35,350
And then just divide this by miles.

40
00:02:37,630 --> 00:02:47,770
And it's going to yell at us because Miles is a double right.

41
00:02:48,120 --> 00:02:54,430
So we need to cast our seconds as a double for now.

42
00:02:54,660 --> 00:02:56,500
So that will work there.

43
00:02:56,760 --> 00:03:01,730
And then it's going to yell at us because pace is an integer which is also fine.

44
00:03:01,740 --> 00:03:04,540
We just are going to cast this as an integer.

45
00:03:04,540 --> 00:03:11,460
Now now that the math is done and it's just going to kind of it's going to force some round in if you

46
00:03:11,460 --> 00:03:15,810
don't like the way it's round and you can always format it a little further.

47
00:03:15,810 --> 00:03:21,660
But for for all our purposes right now this is going to be pretty accurate.

48
00:03:21,660 --> 00:03:26,870
The way this is and then we can just simply return pace dot.

49
00:03:26,910 --> 00:03:30,370
And then we can call our format time duration to string.

50
00:03:30,810 --> 00:03:35,340
And now we have our pace getting returned in the format that we want.

51
00:03:35,340 --> 00:03:37,020
So that's really cool.

52
00:03:37,080 --> 00:03:43,260
And now where would we update our pace down here where we're updating locations is a great spot to do

53
00:03:43,260 --> 00:03:45,040
it right.

54
00:03:45,120 --> 00:03:53,460
So if we underneath our distance label or we're set in that we just want to before we update pace we

55
00:03:53,460 --> 00:04:00,070
don't want our pace to update if things are zeroes and like negative numbers for whatever reason.

56
00:04:00,300 --> 00:04:02,820
Because obviously that means our pases zero.

57
00:04:02,820 --> 00:04:04,220
So let's just do a quick check.

58
00:04:04,230 --> 00:04:06,140
This will stop things from crashing.

59
00:04:06,330 --> 00:04:20,550
So if our counter is greater than zero and if run distance oh man if run if and if run distance is also

60
00:04:20,550 --> 00:04:29,470
greater than zero then we want to call our pace so we'll just say pace label.

61
00:04:29,670 --> 00:04:30,390
Text

62
00:04:33,360 --> 00:04:43,130
equals calculate pace and now we'll just pass in our counter and we'll also pass in our run distance

63
00:04:47,250 --> 00:04:49,090
and I think that is it.

64
00:04:49,110 --> 00:04:56,900
Let's go ahead and run our app and we're going to see pace now.

65
00:04:56,950 --> 00:05:01,180
So we'll start Ron and

66
00:05:06,220 --> 00:05:08,360
doesn't look like it's working for us.

67
00:05:11,990 --> 00:05:12,600
Okay.

68
00:05:12,710 --> 00:05:16,630
So let's figure out figure out what we're doing wrong here.

69
00:05:18,030 --> 00:05:20,770
So if run distance is greater than zero.

70
00:05:20,790 --> 00:05:21,510
That's right.

71
00:05:21,510 --> 00:05:27,750
If counter is greater than zero we want to calculate our pace let's go look at our pace function one

72
00:05:27,750 --> 00:05:31,260
more time all right.

73
00:05:31,760 --> 00:05:36,240
Divide in our seconds by miles which that is correct.

74
00:05:36,510 --> 00:05:41,680
And it I just want to just do a print statement here

75
00:05:45,270 --> 00:05:48,940
pace and we'll pass in our variable pace.

76
00:05:49,050 --> 00:05:53,130
Just let's see if we have something come in and let's run this again.

77
00:05:55,500 --> 00:05:57,210
And let's start this Ron

78
00:06:01,090 --> 00:06:02,680
pases zero.

79
00:06:02,810 --> 00:06:03,530
Okay.

80
00:06:05,090 --> 00:06:08,800
Pases 0 Okay.

81
00:06:08,820 --> 00:06:18,420
So something is going on with our well our counter's work in let's just see here.

82
00:06:18,430 --> 00:06:19,620
So our counter

83
00:06:23,130 --> 00:06:33,100
are run distance is increasing but our pace is not liking what we're doing up here.

84
00:06:33,110 --> 00:06:35,000
So let's figure this out.

85
00:06:41,530 --> 00:06:49,620
What if we just do this and we're just going to return a empty string for now.

86
00:06:56,170 --> 00:07:00,850
Make this a double for now as I want to see if our

87
00:07:03,890 --> 00:07:07,500
casting here is screwing anything up let's run it one more time.

88
00:07:11,610 --> 00:07:12,050
OK.

89
00:07:12,050 --> 00:07:13,100
There we go.

90
00:07:17,440 --> 00:07:18,900
Oh you know what's happening.

91
00:07:18,910 --> 00:07:22,380
We don't want to pass in Miles.

92
00:07:23,710 --> 00:07:25,240
Let's hear

93
00:07:30,840 --> 00:07:30,950
it.

94
00:07:31,050 --> 00:07:35,390
We do want to pass and Miles so we're not passing in Miles that's the problem.

95
00:07:35,590 --> 00:07:41,950
So I just threw in run distance and run distances in meters right now so we're dividing it by a huge

96
00:07:41,950 --> 00:07:42,550
number.

97
00:07:42,550 --> 00:07:48,250
And we had to call our meters to Miles function or extension that we created.

98
00:07:48,340 --> 00:07:52,190
So meters 10 miles to two decimal places is great.

99
00:07:52,450 --> 00:07:57,130
All right up here we can now return this to the way it was

100
00:08:01,410 --> 00:08:09,520
cast this as an integer again return pace dot pases a double.

101
00:08:09,520 --> 00:08:14,700
Now we have to change that back to an integer.

102
00:08:14,730 --> 00:08:20,530
OK so pace dat format time duration to string.

103
00:08:21,000 --> 00:08:24,240
OK let's run this again and everything should work.

104
00:08:24,240 --> 00:08:31,320
We just were dividing by way too big of number since we forgot to convert it back to Miles.

105
00:08:31,490 --> 00:08:32,830
And let's start our run

106
00:08:35,640 --> 00:08:37,250
and there we go we have a pace.

107
00:08:37,260 --> 00:08:39,120
So obviously three minutes is crazy.

108
00:08:39,120 --> 00:08:40,280
That makes more sense.

109
00:08:40,290 --> 00:08:41,250
It takes a little bit.

110
00:08:41,250 --> 00:08:45,080
It is average.

111
00:08:45,110 --> 00:08:47,040
So as you start running.

112
00:08:47,060 --> 00:08:53,150
So our average pace is now seven minutes and 46 seconds which is pretty good.

113
00:08:53,210 --> 00:08:58,160
We have our duration counter going and our distance so we're pretty awesome.

114
00:08:58,160 --> 00:09:05,390
Now we just got to get our pause button working because our button works and we're almost ready to set

115
00:09:05,390 --> 00:09:15,650
up relm So in the next lesson we will get that pause button work in and we will also change the pause

116
00:09:15,650 --> 00:09:19,840
button from pause to play depending on what state we're in.

117
00:09:19,880 --> 00:09:26,630
And then after that I think we'll go we'll move on to getting our role models set up so we can actually

118
00:09:26,630 --> 00:09:30,050
save our data instead of like right now we're stuck.

119
00:09:30,050 --> 00:09:33,300
We can only see our current run if we end that run we lose our data.

120
00:09:33,470 --> 00:09:36,270
So I will see you guys in the next lesson.
