WEBVTT 00:01.820 --> 00:02.560 Welcome back. 00:03.320 --> 00:08.510 Previously, you had learned how to create the lock parser program in this lecture, you're going to 00:08.510 --> 00:10.820 learn how to enhance it using tracks. 00:11.450 --> 00:12.260 Let's get started. 00:13.610 --> 00:19.730 In this lecture, most of the time, I'll be moving to variables into Azraq, and I love fixing the 00:19.730 --> 00:24.260 errors so that you understand how to add a track to an existing project. 00:25.010 --> 00:27.560 OK, let's start by declaring a strike type. 00:27.740 --> 00:29.090 I'm going to name it parser. 00:29.540 --> 00:33.020 This track will store details about the log parsing. 00:33.230 --> 00:33.830 For now. 00:33.840 --> 00:34.760 Just leave it here. 00:35.060 --> 00:37.100 Now, let's take a look at these variables. 00:37.380 --> 00:43.250 I'm going to add them to the track as fields so that in the upcoming sections it will be easier to work 00:43.250 --> 00:44.040 on this project. 00:44.330 --> 00:47.250 First, I'm going to cut the first variable from here. 00:47.720 --> 00:49.830 Now I'm going to pass it into the truck. 00:50.230 --> 00:51.720 Of course, there are errors. 00:51.770 --> 00:53.450 Let's fix them one by one. 00:54.110 --> 00:56.540 The first error is about the same variable. 00:57.350 --> 00:59.100 It hasn't been declared yet. 00:59.570 --> 01:02.900 Let's create a new instance of the parsers track. 01:03.140 --> 01:06.890 So now I'm going to move the make function into the struct literal. 01:07.520 --> 01:14.120 I just need to change the equals sign to a column here to make function returns be a new map and I use 01:14.120 --> 01:15.860 it to initialize the Sonfield. 01:16.580 --> 01:18.910 OK, now let's take a look at the next error. 01:19.670 --> 01:23.230 It says the sum is not defined easy to fix. 01:23.240 --> 01:25.520 Let's type that in front of it. 01:26.150 --> 01:29.990 This fixes the error because there is a sonfield in the parser struck. 01:30.260 --> 01:31.970 The next error is the same. 01:32.000 --> 01:33.690 Let's fix it in the same way. 01:33.830 --> 01:35.750 Now let's take a look at the next error. 01:36.030 --> 01:37.310 Again, the same error. 01:37.430 --> 01:39.410 Let's do the same thing also in here. 01:39.950 --> 01:40.540 All right. 01:40.550 --> 01:41.620 No more errors. 01:41.900 --> 01:43.070 The program works. 01:43.070 --> 01:43.420 Good. 01:43.670 --> 01:44.420 Let's go up. 01:46.080 --> 01:48.780 Let's move the first variable into the strike type. 01:50.290 --> 01:51.460 Let's fix the errors. 01:52.350 --> 01:55.000 Let's quickly select all the domain variables. 01:55.350 --> 02:00.340 Now I'm going to get them from the parser instead, the program still works good. 02:00.360 --> 02:01.250 Let's go up again. 02:02.400 --> 02:05.340 Now, let's move the first variable into this truck. 02:06.240 --> 02:07.440 Time to fix errors. 02:08.380 --> 02:12.920 I'm going to put that in front of the variable to get it from the strike value. 02:13.240 --> 02:16.260 Let's also get this one from the strike value as well. 02:17.560 --> 02:19.270 Good, I didn't break anything. 02:19.630 --> 02:23.610 Let's go up one last time and move the last variable into the structure. 02:24.720 --> 02:28.460 I'm going to select all the variables and I'm going to get them from the struck again. 02:30.960 --> 02:31.980 Cool, it works. 02:33.740 --> 02:34.740 So far, so good. 02:34.940 --> 02:41.870 The variables were declared in the main function, skop, now they're in this truck, so as a side benefit, 02:41.900 --> 02:45.600 they won't clutter the namespace of the main function anymore. 02:46.130 --> 02:50.020 So now it's clear that they are related because they are in the same truck. 02:50.300 --> 02:51.590 There is a good proverb. 02:51.590 --> 02:56.510 It says, make the zero value useful here except the Matfield. 02:56.540 --> 02:58.600 I make the zero value useful here. 02:59.090 --> 03:04.430 As you can see, I do not need to initialize the rest of the fields as they are fine with their zero 03:04.430 --> 03:04.940 values. 03:05.600 --> 03:07.340 Now let's take a look at the log file. 03:07.640 --> 03:12.180 You know, the log file contains the domain name and the number of visits for that domain. 03:12.770 --> 03:16.990 Let's also represent this concept in the code right above the track. 03:17.000 --> 03:18.380 I'm going to declare another one. 03:18.890 --> 03:20.540 Now I'm going to add to fields. 03:20.690 --> 03:22.820 Domain name is a string widgets. 03:22.820 --> 03:28.400 As in the results, track will stored visits for a domain in the feature. 03:28.400 --> 03:32.240 You can add more metrics in it if you need to, such as unique visits. 03:32.240 --> 03:38.510 And so, as you can see, it is better to represent concepts using extracts because they allow us to 03:38.510 --> 03:41.360 make our programs more flexible and extendible. 03:42.080 --> 03:44.920 You might ask why I didn't use a map instead. 03:45.230 --> 03:46.160 Well, I could. 03:46.670 --> 03:48.620 However, a shrug is more obvious. 03:48.800 --> 03:50.960 You can see its fields directly. 03:51.440 --> 03:56.600 If I was using a map, you wouldn't know anything about its content without printing it. 03:56.990 --> 03:59.220 For now, I'll continue using a track. 04:00.070 --> 04:05.760 OK, now, instead of tracking the number of visits using an integer, let's track it using the results 04:05.820 --> 04:06.200 track. 04:06.870 --> 04:08.020 Of course there are errors. 04:08.030 --> 04:10.280 Now let's fix the first one. 04:10.430 --> 04:13.220 I'm going to change the element type of the map to result. 04:13.550 --> 04:18.130 OK, here comes the interesting part, because the next error is more subtle. 04:18.500 --> 04:21.570 It says you cannot increase the results track. 04:21.890 --> 04:24.670 You know, this court returns a result value. 04:24.920 --> 04:26.270 Let's take a look at the fields. 04:26.480 --> 04:28.520 Let's select the visits fields. 04:29.270 --> 04:31.130 However, it doesn't fix the error. 04:31.130 --> 04:31.790 But why? 04:33.070 --> 04:39.790 Well, you can only change and addressable value, but the map element is not an addressable value. 04:40.300 --> 04:43.600 I'll talk more about this in the Pointers section later, by the way. 04:43.840 --> 04:45.010 So what is the solution? 04:45.310 --> 04:47.140 Well, it is quite simple, actually. 04:47.320 --> 04:51.470 You just need to create a new copy of the results and assign it to the map. 04:51.850 --> 04:56.110 Remember, the copy contains the last line from the log file. 04:56.320 --> 05:01.690 OK, let's get the total number of visits for the domain so far, and I'm going to add the total number 05:01.690 --> 05:02.920 of visits to the copy. 05:03.430 --> 05:06.480 OK, lastly, I'm going to assign the copy to the map. 05:07.030 --> 05:11.350 So now the map element contains the total number of visits for the domain. 05:13.620 --> 05:17.130 It brings the truck values instead of the total number of visits. 05:18.330 --> 05:25.770 So let's go the first I'm going to change the name of this variable to make its intentions clear, next, 05:25.770 --> 05:29.740 I'm going to print the total number of visits per domain by getting it from the strike. 05:29.970 --> 05:30.270 So. 05:31.310 --> 05:36.050 Now, it works excellent, by the way, I can type this code more concisely. 05:36.260 --> 05:38.480 I'm going to assign it to the map directly. 05:40.580 --> 05:41.080 It works. 05:41.790 --> 05:43.330 All right, that's all for now. 05:43.380 --> 05:44.370 See in the next picture.