TLO, what's poppin? We are on Twitch. We are not live, but you can leave a like, comment, subscribe, turn on your post notification bells, man, let's continue to grow the family from Chicago to the UK. Your discretion is advised. I do not glorify sensationalize or condone any of the yack stories told in this. I am here simply to educate myself on others on the history and current state of issues around the world. This is intended for mature audiences only. Read this. Alright. Like I was saying. Don't forget we are partnered with the Blue Prep. You know, send a link to this one to be down in the description below. If you're looking for any of my old videos, it's over here on my Facebook. And don't forget we got the Patreon. I just did a video for Only Fools and Horses. That'll be up soon. And we started a new show this week. So, let's get into this though. This is from Skyboy, Skyboy. Let me subscribe to that like button. Shout out to my first responders for doing the same, hitting that like button on this video. Without y'all, man. Without that early push. Who knows, man. And just to keep you frank, man, I'm still, I don't know if I'm sick or I got allergies, but I don't know what it is, but it's bad. I don't have this a week straight now. Sick of it. The deadly war in Northwest London, CSB vs. SGB? Alright guys, I'm back with another one. I'm waiting for Millio Waters, the borough of Brent, home to some of London's most deadliest gangs. And at one point, the capital of gun crime. Today we'll be focusing on two particular sets, Stonebridge and Church Road. A war that has been active for almost two decades. I'll be touching slightly on the set's history. But rest assured I'll be focusing mainly on the mother string of violence between these two sets. The past history is a bit murky, and many people disagree on certain events. So, aspects of it is best to be left alone, especially when I can't verify certain dios. That's a fact. If you can't verify this, that's almost snitching. We get an unusual glimpse into why the war on drugs is failing. Jamaica is one of this country's closest friends and favored trading partners. We give Jamaica more USA than any other Caribbean country. We also export a voracious appetite for drugs. So, Jamaican organized crime is flooding this country with tons of cocaine and marijuana. And along with the drugs, Jamaican gangs, or posse's as they're called, have imported marijuana. And along with the drugs, Jamaican gangs, or posse's as they're called. Never heard it called that. I've never actually heard a group of people call the posse ever in my life, not one time. Called, have imported a brand of cruelty that's second to none. Now let's take it way back to the 90s. Winston Harris, aka Escobar and his fellow yardies relocated from Jamaica into New York City. They were known as the lock city crew. There was an American dream on the table, and everyone wanted a piece of it. They started distributing drugs in Queens. However, and everyone wanted a piece of it. They started distributing drugs in Queens. However, after several murders and drug related crimes, Escobar and his gang fled. I'm not gonna lie, I went to New York one time, right? A few years back. And this is how it was, honestly, almost. It was like people was on the street. It was some people on a set of steps with a bone box. People was jumping rope on the streets. I was like, wow. And I was in the hood. I was in Brooklyn or something. I forgot where I was. It was a hood though. And I was like, dang. Chicago, we could never do this. People do not be outside just kicking it like this. It was a beautiful thing to see for me at least. However, after several murders and drug related crimes, Escobar and his gang fled to London to avoid the FBI. One of the rare occasions where gang members understood when to stop rolling the dice. Once they touched down in London, they settled into Brent where they recruited members from all over the borough and imposed their violent style of dealing with issues, causing them to grow very quickly. Now onto the 2000s. A new generation of youngsters forming their own sets came into play. The Fugs of Stonebridge and the Church Road soldiers. The hatred between these two sets was so severe that innocents who lived in opposing estates would also be targeted. Kaiser Osmond, also known as Ozzy, a resident from the Stonebridge Park estate, was bullied by younger members of the Church Road soldiers in and outside of school. Despite Ozzy being a civilian, he and his family would often make reports to the police claiming to be a victim of the bullying.  They would surround his house armed with knives shouting these intimidating remarks regularly. One day, he was seen walking out of the community centre in the Church Road estate. A few members of the gang approached him, they began assaulting him and he was stabbed right in the chest. He died shortly after due to his injuries. Members were arrested some as young as 12 years old, where one member was charged with his manslaughter. In 2001, Shakar Anderson, a.k.a. Cash was a talented musician who was about to be signed by Danso artists and legend, Movado. He was a young man who had been a member of the Church Road and a member of the Church Road. He was a member of the Church Road and a member of the Church Road. He was a member of the Church Road and a member of the Church Road. In 2001, Shakar Anderson, a.k.a. Cash was a talented musician who was about to be signed by Danso artists and legend, Movado. One day, Cash got into a sticky situation with a Stonebridge member named Shorty. Unfortunately, the situation escalated and Shorty shot Cash at a point blank rage and robbed him. Cash almost died from his injuries but thankfully survived. Cash was left with nothing but classic movies and I love this movie. In 2002, famous UK rapper Dizzy Roscoe held an event at a nightclub to tackle guncrank. The irony is that Cash and Zeno both attended the event armed. Zeno being the older brother of Nines, a very important individual that will make a name for himself in the future. Also in attendance was Shorty, the man who almost took Cash's life a year prior as well as another Stonebridge member named... Who made this guest list? Who invited him? What was they on? The Endsman Cash spotted him and instantly Shorty shot him in the back of the head. Zeno also saw Endsman and began firing, hitting him in the neck. Endsman attempted to escape but sadly collapsed outside the nightclub and died. Despite several people witnessing this, no one said a word due to fear and both murders are unsolved to this date. Now forward to 2007, a pivotal moment in a northwest London gang culture. The introduction of the bandana movement. Stonebridge linked up with several sets such as South Kilburn, Chalk Hill and Monks Park. They all flagged blue. Their rivals flagged red. I go into more detail about this in my other video that's on my channel that you should check out. However, Church Road, they stuck with a black flag to distinguish themselves from their rivals. They weren't a part of the link-up despite sharing the same rivals and kept to themselves. April 2008, Zeno, aka Wayne Freckleton, was sitting in a barber shop. Zeno, aka Wayne Freckleton, was sitting in a barber shop when he was brutally shot and killed by masked gunmen. The gunmen were Ford and Osborne, two Stonebridge members who were later sentenced to life. In prison, this vicious attack was a revenge for the double murder Zeno was a part of in 2002. Although it happened a good six years ago, it's a testament to the statement that revenge has no expiry date. 2009, Church Road affiliate Pinky had been attending a party inside the local primary school in the Stonebridge Park estate. Hours later, whilst leaving the premises, he was confronted by Stonebridge members which led to a gunshot being fired. Pinky was hit and later died from his injuries. Stonebridge member Grandad and others were arrested, even going as far as to arrest the schoolboy in connection with the murder. But due to insufficient evidence and no witness coming forth, the case was later dropped and the murder remains unsolved. An individual from the Church Road area that goes by a dipset was once spotted by Stonebridge members.  Now this stripping business is something I've seen gangs all over the world do and I generally think it's one way closeted, down low homosexual gang members can express their desires whilst disguising it as humiliating and not because there's nothing gangster about it. The video was uploaded to YouTube, but for some reason you can only hear the audio. Now onto the 2010s, Stonebridge member K Coke was making a name for himself in a rap scene, consistently producing bangers, notably his hit A You Alone Fam which was dedicated to disinformer Stonebridge member Spider who snitched and relocated outside of London. K Coke also did a fire in the booth and was one of the first artists I've seen hitting million views back then. This was a monumental feat as London didn't have much of a rap scene, like this song sits at a pretty 22 million views today. 22 million is impressive for anybody. Now onto the late 2010, K Coke and fellow member Squingy was spotted in a barber shop by church road members. K Coke was sitting waiting for his haircut when they ran up on him recording, verbally abusing him, throwing bricks and leaving with his jacket. K Coke stood his ground and jokingly replied, What you saying? So credit to him for that, can't buy a heart. What? What? Now throughout the next few years, operation Shouldn't even have posted that. Trident, which is a police service unit, originally set up in 1998 for the black community as the community-led initiative with the police to tackle gun crime and homicides disproportionately affecting African Caribbean communities. Trident successfully arrested many gang members for firearms and ammunition possession. This helped lower the crime within the borough of Brent, especially within the housing area. Gentrification also played a part and had taken an influx as it staged with demolition. Many residents, including gang members, were forced to move out of the area due to high rent and some for criminal convictions. song with Rita Ora, where the hook says, lay down your weapons. Kate Coke's response was said, lay down your weapons to the kiddies and that I never laid down mine. I got a Fiziana Mac. In other words, I was telling the kids to lay down their weapons. Asked the old Godmind, Kate Coke didn't stop there. He crossed the line and talked about Zeno's death. The older brother of 9s who got gunned down in a barber shop.  Your brother died in 06. Now come 2018, the rise of the new generation. Many fucks of Stonebridge members got locked up in drug offenses and firearm charges. This led to the extinction of SGP and made way for the new upcoming generation from the SOS, aka shoot on sight. Prominent members included Crush Corn, Little Shanks, Little J. The Alliance were newer generation of the South Cuban and Chulkyl Estates, now known as A9 and SSK. Over the years, more alliances have emerged with other gangs such as CGM and LGA. Just like their rivals Church Road would also usher a new generation of CSP members, which consisted of prominent members such as Chapo, South Q2T, Screamer and many more. Unlike Stonebridge though, the younger generation would keep the name CSP going. They were going to make music and adopt a popular UK drill song. Now remember Big Keys I talked about earlier? Well, his nephew, Rico Finlayson was stabbed 10 times in the Church Road area.  Meanwhile, his father, Justin, has just secured funding to expand a charity that tackles knife crime. In August 2017, the father launched a music outreach project which was a double decker bus converted into a music studio which picked up gang members from Church Road in the Hardland area in the morning and Stonebridge gang members in the afternoon. He wanted to inspire the youth within the community instead of being on the road committing crimes to channeling. Emotions into art On the 31st of May 2018, a 24-year-old man, known locally as Jay, was found with gunshot wounds on Lawrence Avenue at about 8.30pm. He had been shot 11 times with a machine gun. Luckily, he survived the attack. It was reported that he had been at the wrong place at the wrong time and they intended to talk to his friend, a Fox of Stonebridge member. In 2019, an event took place that added oil to an already raging fire. This would lead to a severe upscale in future violence. One day, Nines was driving around in his Porsche and had been spotted by Mad Big and AR. After they locked eyes, Nines was chased. This is what led to Nines crashing his car.  AR even recorded him chasing Nines.  They used the footage as evidence in the courtroom and it was later sentenced for the stabbing. Nines left with a nasty scar that you can see today on his face. On the 5th of July on Harrow Road, Monk's Park, at around 8.20pm on Friday, Craig Small, aka Small's, a Stonebridge member and friend of K-Cog, was gunned down. This was a retaliation for what happened to Nines. On such a named brand and important member such as Nines's attack, the retaliation always has to be murder. The shooting was caught on CCTV. The shooter creeped up close and unaware Small standing outside the chicken shop was shot at point blank range. And when it looked like the shooter was fleeing, he came back to shoot again while Small's was lying on the floor. Two things we do not do, I would consider lacking. Standing outside of the food shop, you don't stand outside. We place the order, we go pick up the order, we get back in the car, we go. We don't go to the place, order the food, wait, no, no, no, no. We even pay for it on the phone, just give me it. And I don't send myself in, send somebody else in. We don't do that. Second thing is wait outside the night close, don't do that either. Once it's done, go to the car, leave. Simple. Summer rest was made, including fellow CSP rapper and right-hand man of Nines, Scraps. He was charged on September 12th with perverting the Court of Justice. The death of Small's hit Stonebridge heavy. Emotions were high and retaliation was a must. Without any proof, they thought St. Raphael's had involvement in his murder. This led to tips for tax with them. They resorted to taking their anger and frustrations out on any St. Raphael's member they could find. The next day St. Raphael's GK was shot numerous times while sitting in his car. That's another thing we don't do, sit in the car. It's for work. Then trio, now going into her. It's going to be in constant motion. Fortunately he only got shot in his arm, was rushed to hospital and discharged. Both Skeng and M1 would be arrested for their participation in their attempted murder. Young Sam was charged with the murder of Small's. The next day beefy rounded up Fox's Stonebridge members to go off to St. Raphael's leader Bucky. I'm assuming this all is public knowledge on the internet. Can all be found? To make an example. Go off to St. Raphael's leader Bucky. This is because they wanted to make an example by going off to the main figurehead at the time. The Fox's Stonebridge member saw an innocent man named Kowasi Mensa walking out of a shop. They followed him and shot him in the head at point blank range. Another case of mistaken identity. A trend we are sadly so accustomed to. Come 2020, many CSB members were released from prison and held a block party to celebrate. A SOS member got word that the party had slid. The gunman spotted a CSB member along with his family and started shooting. A CSB member was shot in his arm. His wife was shot five times in the chest and the most heinous crime of them all. Their two-year-old was shot in the head. Thankfully all survived but had life-changing injuries. The shooter was Crashcon. He was charged with triple attempted murder. However, he beat the case due to insufficient evidence and I'll talk about luck. Ain't no luck. He had a mask on. It can't be luck. But yeah, nah, that's crazy. That's an unfortunate event, man. That's why you gotta stay away from this lifestyle, man. Kids in the head, innocent wives. Look who you put in danger. You got hit in your arm. Look what your kid got. Look what your wife got. That's crazy. I'm sure you can imagine the sheer anger the CSB member was going through. It's one thing being shot but to have your family, your wife and your young child inflicted with life-changing pain, trauma and injuries, I couldn't comprehend the level of revenge that he was contemplating. Now remember how this video started in Jamaica? Well, let's take it back there. As revenge for what Crashcon did, his father was assassinating Jamaica as revenge. An innocent baby and wife shot and now an innocent father was taken all because of what his son had did. This vicious cycle looks like it may never end. It just- Nah, not with them kind of stats, okay? Unfortunately. And you know, all you can do is change your life for the better and try to move away from it, but that's- Eyes down for a bit until another event re-triggers it. How many lives taken spanning through three different generations in three different countries? How many civilians were taken that had nothing to do with it?  And if you're lucky enough to make it out, you certainly don't without trauma and misery. What's the point of being the one who made it if you can't enjoy it with your friends because- That's the survival remorse. A lot of people go and do that man. I made it out of the head and all your friends is either gone or- They were mad. That survivor's guilt. If you like what I do, make sure you give this a like and subscribe. Plenty more to come in a few- Be decent. Do you know, leave a like, comment, subscribe, turn on your post, man. I think this is the only video, man, because I'm sick. It honestly hurts to sit here more than 10 minutes. You're like a whole body and whatnot. Okay.


So, welcome to today's PostgreSQL conference webinar, building a PostgreSQL backed website quickly. We're joined by John Ashmeade, database developer and DBA at Nistica, who will discuss using Ruby on Rails to build a PostgreSQL backed website, what to watch out for, which tasks to leave to the framework, what to do on the database side, and the various stages of development. My name is Lindsay Hoover, I'm one of the PostgreSQL conference organizers, and I'll be your moderator for this webinar, a little bit about your speaker. So John's been working with relational databases since the 80s, building and enhancing databases in SQL Server, Oracle, InformX, Ingress, and PostgreSQL. For the last five years, he's been a DBA and database developer at a leading manufacturer of optical switches, and John is in charge of the care and feeding of the manufacturing database. For the last year, he's been maintaining a manufacturing database to a factory in Zuhai, China. Welcome, John. So with that, I'm going to hand it off. Take it away, John. Okay. Hi, guys. I'm looking forward to doing this talk. I learned a lot putting it together, and I hope you'll have some useful takeaways from the talk as we go through it. Our objective is to learn how to build a PostgreSQL-backed website quickly. You might be wanting to get a trial balloon up just to see what happens. You might be at the beginning of some venture and want to get started with your website without doing too much work on that, or you simply might want to know how a client server works soup to nuts, and we should be able to take you off to a good start on all three of these goals. The approach I'm going to use here is to focus on doing this with Ruby on Rails, which I'm expert on and which is an extremely good tool for building a website quickly. It's so helpful. In fact, it's sometimes even too helpful, and we'll discuss when you have to watch that. If you can see the URL on the screen, you can go there, but if you look for getting started with Rails, you'll get to the site as the third item on your first search page. I looked around for good introductions to how to do this, and I found that the best one for our purposes is the tutorial on the website itself. It's simple, it's very well organized, it gets you off to a quick start. But before we look at the tutorial itself, we need to look at what's actually going on here. This is an overview of the talk. We've got five sections to this talk. First, we're going to look at what is model view controller. I'm sure most of you have already at least heard the term, but we're going to explain what this is and why this is critical to building websites quickly. Then we're going to look at a typical workflow, starting with the users and the use cases you might deal with and going through what you do on the database side and on the views and so forth. Then we'll take a quick look at the tutorial. We don't have enough time to do the tutorial. In any case, the tutorial does a great job of doing itself, but what I want to do is show you how to get started with it, how to do your necessary setup, what kind of things to watch out for, and what questions to address as we're working through the tutorial. After we've given you a good foundation for that, I want to pull back and look at the relationship between Ruby on Rails and Postgres SQL. Most of the material on building a website focuses on the framework, which is Ruby on Rails in our case, and they don't necessarily spend a lot of time on the relationship and how to manage the transactions between the framework and the database. We're going to look at that, and then we'll look at best practices and how to get your pyramid up smoothly and correctly. So okay, an overview of model, view, and controller. There are a fair number of pieces here. We have the client side, which is usually just a browser, and we have the server side, which is where the router, controller, model, database live, and where the views are built. We're going to go through each part of this system in enough detail to get you started. But as an overview, you're sitting on a browser, you've been given a URL, like, say, getting started with Rails, and you put the URL on the browser, and it navigates through the internet, and if it hits a Ruby site, it gets handed to a router. The router checks the URL to make sure it understands this. It will send you an error if it doesn't. And then does Ruby calls, Ruby is a scripting language, to something called the controller, which is the main piece of code on the Ruby on Rails framework. The controller uses something called Active Record to talk to models, which are front ends to the database, and the models use SQL to talk to the database itself. The controller is also able to use SQL to talk directly to the database for more complicated tasks and for exceptions. Once the controller has got its data put together and all lined up, it uses a language called embedded Ruby, ERB, to build a view and passes the view, which is a clump of HTML cascading style sheets and JavaScript back to the browser, which then renders it. And that's the basic picture. And this is an extremely typical way to do stuff. We're doing Ruby on Rails here, but a lot of the Python frameworks do something quite similar, and I think Java does that as well. It's a very common way to do it, and there's an excellent reason why this approach is preferred. And that's something called the restful architecture. It's hard to believe that this was invented by one guy, Ray Fielding, I think it was, in the year 2000. And he said, look, most of what we need to do on the web, or certainly a lot of it, has to do with somebody on a client side wanting to get a hold of a resource and somebody on the server side serving it up, serving the resource up to them. So the client might want to get a resource or might want to change the resource with a post or to replace that resource with something else or to update the resource, that's a patch, or to just get rid of the resource. And resource could be anything you like. It's usually, it's often some kind of a web page. It could be a pile of PDFs. It could be on GitHub, a program code. It doesn't really matter that much what the resource is for this model. And the great advantage of a restful architecture is that it creates a clear division of responsibilities between the client, the browser, and the server. So the server can just worry about satisfying all these calls and not have to worry whether the browser is Firefox or Safari or Chrome or what have you, not have to worry even if the client is actually a terminal or another piece of software. It just has to attend to its business and get on with it. That's a major win from a development point of view and why this model has taken over the Internet. Now, when I'm getting started building a website or adding a new feature to our website or whatever, I usually like to start with the use cases. Who's going to be using this thing? What are they going to be doing with it? And usually one of the first things that you think about is just what is my resource, which could be in my case, would be manufacturing specs or a page on how to assemble a optical fiber card or what have you. So the first task, the users will want us to locate the resource and there might be a search page or just an index or whatever. Then they need to do maybe a little bit of adding and editing. They'll have to log in for security reasons. Usually there might be a manager, there might be a programmer, there might be a data scientist, but it'll start off with a bundle of use cases like three or 10 or whatever, not too many or too few. And these serve as the basic checklist at every point. If I have done the right thing for every one of my use cases, then I have a working system if the use cases are complete. Otherwise, some more work still to be done. Often when we're building the website, we focus on the first three, just the regular user, and we forget that we have to manage the interactions. We have to hunt down bugs, which are unavailable, and we may want to use the data for other purposes. So we want to think about at least a little the basic use cases. Now, use cases map very quickly into the development model with Ruby on Rails because for each use case, you imagine you're going to type in an associated URL like an index or whatever, and then the router is going to figure out what to do with this. This is a sample from the tutorial of the four line router for the first set of pages about articles. There are sample databases of articles and comments, and they say that your starting point is index of articles, that's logical, and we want to access articles in a restful way. Basically, the router is using what's called a DSL, a domain specific language. That's a special language built for this one problem. Actually, DSLs are an extraordinarily powerful tool for building software. Instead of writing code to solve the problem, write a language to solve the problem in which the solution of the problem is easy to do. After all, that's what HTML is, DSL, what CSS, what JavaScript, and so forth all are. In the Ruby on Rails router, this is what you get by default on the bottom left, that simple word resources for articles gave you URLs that will find an article, create a new article, edit, that's the post thing, post and get, update an article and delete an article. So you got a ratio of about eight or 10 to one on your code. That's one of the things that frameworks are really good for. You're writing 10 lines of code for one line of your code, which means you're 10 times as fast or whatever. In the router, you can include double checks to make sure that if your articles are identified by ID number, somebody can't put in an article with the name potato, which is not an ID, and fix other things like that. And in my routers, I like to have a cleanup route at the very bottom, which is for exception trapping. And if we don't mention anything else, we'll send them to our home page. The next thing I like to look at when I'm building a site or fixing one are the models. Models are the front end to tables in the database. They are wrappers for tables. So usually the rails will talk to the table, not directly, but via the models. And this way, again, you get this one line of programmer code into about 10 lines of SQL ratio Ruby, Ruby on Rails models, really part of their active record subsystem are pretty easy to put together. This top line in green is the command used to build the comments table in the tutorial. Rails is the starting point. You're going to generate a model called comment. It will have the field commenter, the field body, and it references the article. Comments are child of the article table. The comment.rb model in Ruby on Rails is really short. You've got the class comment, it inherits from application record. Ruby is an object-oriented language, so it does everything by inheritance, same general pattern as, say, Java or Python. Notice how short this file is. You're looking on the Ruby side, you say, how can three lines of code give me a whole table? Well, this is where the cleverness comes in. The first time you try to use the comment model in Ruby on Rails session, active record, ar, goes to PG catalog, which it knows about, and looks up all the characteristics of the comment table. And so it's during that lookup phase that it learns what the fields are in the comment, and that's why it doesn't need them here. And I recommend to you, as you go through the tutorial, keep open a terminal, set your Postgres server to log every SQL and watch the SQL as your various commands are run. And you'll see a lot of really interesting stuff going on. There's an enormous amount of stuff going on under the hood. And when you're getting started, it's useful to learn about this. By the way, active record doesn't do this every time you open up a comment record. It only does it the first time and then it caches it. Once you've built, set up your comment table, you have to run a DB migrate command, which is actually do it. And in the tutorial, you can look at the commands that actually build the table. And when Rails builds the table, it's going to do a lot of extra stuff for you. First off, it gives every table an ID, which will be your primary key. Then you see the two fields that were mentioned. Then you see article ID, which references the article table. And then you see two timestamps, one for when the record is created, another for when it's updated. And Ruby takes care of the ID, created at and updated for you. It adds the primary key here and it adds the foreign key looking into the articles. When I first started out with Ruby on Rails, a much earlier version, it didn't necessarily build all of the structure it needed. It wouldn't build the index that goes along. There should always be an index on the article ID. And that version of Rails didn't do that. And I was pleased to see that the latest Rails does take care of this and a bit more besides. So that's the underlying structure. And I usually like to build my database first and then build stuff on top of it. Now the heart of a Ruby on Rails application is the controller, which you can kind of guess from the name. This is a little bit of controller from the tutorial, just a sample. First off, it's part of the class hierarchy. It starts with application controller and then does stuff specialized for articles. We want to look here at the starting point for a new article. There's a function called new and a function called create. And you think you might need only one function. In fact, the new function sets you up. It doesn't actually talk to the database, which is interesting. If you say I want a new article in this framework, you'll get the view, the stuff you need to set that up, but the database won't hear about this until you hit submit. When you hit submit, the method create will be called. The database will check that the parameters you sent back, this is some useful screening code that makes sure you only set back things that you were allowed to send back. And if it likes everything, it will save the article and then send you to the article's own page, to an edit page for the article. If the save fails, well, what the save does is it does an SQL call into the database with all this extra screening here that will probably work. But if it doesn't, it will just go back to the new page with a few error messages showing up on it. So that's the basic riddle. You get a setup method and an update method. You get a bunch of utility methods to screen it or to help do things. You have mechanisms in Ruby on Rails that let two controllers share methods with each other. You have to plan that out a bit, but it's very powerful and you get helper tools that let the controller share information with the view. OK, so the next big chunk is the view. This is again a whole pile of domain specific languages, including primarily embedded Ruby. If you've worked on PHP, you're familiar with the rhythm of a page like this. This is HTML. You can see that we've got a new article here. Then we have this percent equals. This means that Ruby is being told from the percent equals to the end of the percent equals you do work. And Ruby will call up its form with model using the article model. And this at article is the data structure that was set up in the controller. At is a keyword meaning attribute. So this is all the records on that article, but for a new guy, they won't have anything in them. This is another bit of Ruby. You see the embedded stuff on the left and right. It's going to put the title in here. Just the word title break. Then it's going to put in a text field, which goes to the field title. And then it's got some air handling here. And this is really kind of interesting because you're getting an enormous amount of HTML code being generated for you. This is the second field on the article table, which is called body and any errors about the body are going to show up here. So the errors are right next to the problem that created it, and this will generate a submit call when you hit submit. I'm not going to show you this here, but when you work through the tutorial, be very careful to take a look at the HTML, which is being generated, your browser, no matter what it is, is going to have a developer tools menu on it. Bring up developer tools, look at your real page on the left, and at the developer tools, which will let you look at the HTML, the JavaScript and so forth. And don't just breathe through the tutorial, but like savor it, see what it's doing for you and whether you like what it's doing and whether you understand it. And this will give you a firm foundation for when you have problems or need to add stuff and so forth. So there's like a rhythm to working with a tutorial. You do what it says, and it's very helpful, but you take a look under the hood at every statement. Now, Ruby or Ruby has the Ruby community has a couple of key philosophies which are which show up in views and everywhere. One is convention over configuration. Instead of telling Ruby and Rails how to do stuff, you do it their way and then it knows how to figure things out. Like this article is in the singular because it refers to a single article. If you did a set, you'd see something like articles, and that's really cute. And eventually you get used to that. Furthermore, at every point in Ruby on Rails, you can share code. So controllers have concerns or mix-ins to share with other controllers and views have something called partials, which are like little bits of views. They're like a little square area on the form where two views will share common code and only make daily use of partials. Ruby will also integrate unobtrusive JavaScript. For instance, we've all written code that says you really want to delete that confirm and you'll bring up some JavaScript to do that. Ruby has syntax that lets you put a confirmed question on the page without you doing actual work. It will compile cascading style sheets so you can have a master style sheet for your site and then sub style sheets for each part of it. So you want to internalize that. Don't repeat yourself. DRY, which is a Ruby mantra. OK, so now we've completed a quick review, very quick review of the essential parts of model view controller architecture. Those are the main parts of that original diagram. Now we're going to the center of this talk, getting started with the tutorial. I'm not going to do the tutorial. I looked at it, you know, over the last few weeks, and it's really good. It does things step by step, but it's a little over focused on getting the page up and doesn't give you enough information about the background. And we're going to look at how you set up Ruby, supporting tools, the classic Hello Rails and a bit about workflow and what you do after you've done the tutorial. So you can think of this talk as a kind of client server with respect to the tutorial. This talk is the client. The tutorial is the server. Now, before we can turn on Ruby on Rails, we have to turn on Ruby. I found a very helpful site. I'll see if I can pronounce this correctly. Havier Julio.com R-B-E-N-V. And I suggest going to this and just having a look at it. He gives very good instructions about how to get a tool called Ruby environment or R-B-E-N-V up. There are two major tools for setting up Ruby and Ruby on Rails, R-B-E-N-V or R-V-M. I use R-V-M at work all the time and time and it's you're perfectly good, but I chose R-B-E-N-V and the tutorial chose R-B-E-N-V because it just has a cleaner interface and it's a little easier to deal with. But you can pick either. Julio explains how to clone R-B-E-N-V from GitHub and then to install it, you type in R-B-E-N-V install and I'm recommending Ruby version 274. I'm being quite specific about it because it's the latest really solid Ruby version in the two series. There's a Ruby 3.0 which is out now and I don't know if you've heard the proverb don't use .o of anything. Ruby 3.0 will probably work most of the time, but unless you're an enthusiast, you might want to wait for Mr. 3.1. So 274 is a very specific recommendation here and it will help you have a better time doing this. When R-B-E-N-V installed Ruby, and it doesn't say install Ruby because that's what R-B-E-N-V does unless you say something else, it installed also a program called gem. Gem is a Ruby gem. That's what they call their libraries and it's a gem for installing gem. So it's kind of a meta gem. So you go gem install Rails and that will install Rails 6.1. It will always install the latest solid version unless you say otherwise. Notice that this is Rails 6.1, not 6.0. If you're still on 6.0, I'd be recommending a five something. At this point, we actually have a working set up sitting on your server, whether it's Windows, Linux or Macintosh. So I think this is pretty brilliant. Now you're going to need a few more tools before you get into this. You don't absolutely have to have a software configuration manager here, but you really want to do this. It's a service to yourself. And I've used Git and Subversion. I use Subversion at work and Git for my own project, both our first rate tools. If you're undecided between the two, I'd go with Git because I don't make it easier to push your stuff up to the internet. You need a bunch of internal tools. The instructions for getting them are in the tutorial. Yarn is to work out dependencies. It's like a Ruby centric version of Mac, which figures out what the dependencies are. Node is a JavaScript support tool which is needed for a lot of the JavaScript support tools in Rails. Rails is actually almost a hybrid of Ruby and JavaScript at this point. SQLite is a little baby database, just one table at a time, which is used a lot in cell phones. It's very lightweight, so all sorts of code will use a small SQLite database inside itself. We're doing Postgres here, but you need to be aware that these things are floating around that are often useful. In fact, your own client browser, your Firefox or whatever, is maybe using SQLite to manage internal data stores on your machine. And then you need to talk to Postgres. You can use PgAdmin, which is highly focused on Postgres completely and very powerful to do all kinds of wonderful statistics and monitoring stuff, or Dbeaver, which can talk to Postgres perfectly well, and talk to a SQL server and MySQL and so forth, if you're in a multi-database setup. So now we've done our prep and we are now already at the middle of this talk for the core of this talk. Hello, Rails. You knew this was coming. And we can get to a server running on your server in four lines, which is awesome. First, you do Rails new blog. They use blog for the name of your site. It would be whatever your site's name is. Notice in red, the minus D, Postgres SQL. Do that. You don't want to go, the default is SQLite. Don't do that. Just minus D, Postgres SQL. Then you CD to the blog directory, which is created for you. That directory is full of files and subdirectories. Take a look around. If you become a Rails developer, you'll be spending a lot of time navigating that tree. But in fact, I usually keep a couple of terminal windows open at the same time to parts of that tree. Then you type in bin Rails server. The bin Rails is a little tricky. One of the subdirectories in blog is bin. That has a front end of Rails, which is modified for your particular website. You type in Rails server, and now you're running a web server, believe it or not. That's great. Then you take your browser and you navigate to this location, slash <IP_ADDRESS> is also called local host and port 3000 is the Rails port by convention. You just did four things. Let's see what happens. You get this wonderful welcoming page. Isn't that cute? We haven't actually done anything specific. You can see at the bottom that I'm running this thing on the Mac from the Darwin and I'm running Rails 614 and so forth. That's very good to show that your web server is up. Now we want to actually get out the traditional Hello Rails. We can do this with a little bit of work. It's detailed in the tutorial. As you might expect, first we have to fix up the router a little bit. I'm not putting the instructions here, but you'll need to set up a route for this. So you can route to your Hello page. Then you have to fix the database configuration. I usually do, I change the username and the database. I'm thinking of building a Postgres links website. So I've created an identity on my Mac PG links. And that's nice because I'm using .pgpass, that's .pgpass, which is a wonderful tool. I don't need to put the password in here. So I avoid that security violation of putting a password in a generally readable file. Now I had a little bit of trouble when I was setting this up because I was on a Mac running Postgres 13. I got a whole spew of error messages when I put my first article in, about 4,000 in a row, which is a lot. And with a little bit of work with a search engine, I used ..go, I found that the problem was that something called GSS, which is a security system, doesn't work well on a Mac between Rails and PG12 and higher. Since I don't need it on my own server, I just disable that. I would say that as you walk through the tutorial, you have a good chance of finding one or more spots where it simply won't work the way you expected. If you have a good understanding of what's going on and just look at the error messages with a search engine and because Rails is a solid product and Postgres is and presumably your platform is as well, it shouldn't take too long to see that error message and then to find out what to do about it. This is pretty much guaranteed to work for the general case. Then after you've done that, you have to generate an articles model. I showed you the generate command earlier for the comments. It's the same thing.  And then the fun bit, you go to a page called app views articles index.html.erb. App is a sub folder of that blog directory where everything lives. That's the application. Views are the views. We're doing model view controller. What else is new? The articles are the articles and index is the index page. Erb means that this is an embedded Ruby file and Rails will take care of stripping off the dot erb and expanding to create the index.html which the client is going to see. That means that to the browser, it doesn't know about erb. It just knows index.html. You're going to create, sorry, one line in that HTML which just says hello Rails and we jumped ahead a little bit and that's what you get back. So that's your basic setup. Hello, type in the hello Rails, get back hello Rails. If you've left that web server running, you just refresh the page and you see this. If not restart the web server, Rails server and then reload the page and you'll see this. The first guy who came up with hello Rails, hello world, a Kernigan and Richie and their wonderful book on C programming said that getting to the hello world stage means that all of your framework is working and you've accomplished a great deal of setup. That means you can now start without going back and forth between is my compiler okay or my assembler or my pass set up.  This is a pretty Spartan page. It needs a wrapper, some CSS, all sorts of real stuff, but it means you basically have stuff working. And that's fantastic. And I love the fact that the control of the tutorial only takes about five edits to get you to this point. On for C code, you have one or two, but for MVC and for a website five is pretty fast. Okay, so I'm not going to carry you through the tutorial. That's the tutorials job, but I'm going to show you what to watch for as you go through the tutorial. First off, you take the sample code. In fact, they make it really easy to cut and paste the stuff. There's something to be said by the way for hand typing the code to make sure you really understand it, but you can use cut and paste. And then if you remember Ronald Reagan's own motto, motto, trust but verify, it works the way the tutorial said, but look under the hood, run PG dump to see what the table actually looks like. Look at the PG log to see what SQL was generated. Look at the HTML and your browser's development tools to see what that's going. And PG admin, you can watch the whole Megulol at once. Rails has its own log, which will show you the SQL. It will show you every view being loaded, all the parameters and give you the times. It's brilliant. And stare at this thing. I often leave a terminal session open doing in Linux terms, a tail minus half to see each new line as it comes in. You can also intersperse debugging messages using the logger object and the info method. Remember object oriented. So this is the object. That's the method. Hey, then the browser development tools. And I'm going to look at these things and they are astonishing that the browser will let you look at the complete structure of the HTML at the JavaScript, the CSS in your JavaScript, you'll probably put in console dot log and console dot air to tell you about key events. Generally, I like the beginning and end of a JavaScript function for targeted error messages. The browser tools will also let you watch the network, watch files being pulled in. And then if you are really hardcore, you can look at every packet. You can actually bring up wire shark on your server and stare at all postgres packets. That's a recognized convention on this. And I mentioned this partly because I spent the last two weeks staring at packets on our work network to deal with some latency problems. That's not fun, but necessary. So you have a lot of extraordinarily powerful tools, and I encourage you to take a relaxed view of the tutorial. Don't rush to the end, but savor it. If you can savor a tutorial, when you get to the end of it, we'll have a perfectly working website with articles and comments on it, but it won't really meet modern standards for a website. What we do nowadays is called single page architecture.  You stay on that page. And secretly Ajax calls go out to the server, you know, over to the server, over to the controller. And then the controller will send you a quick message back with Jason. Jason is like frozen JavaScript. It's a hierarchical another DSL, which can convey a lot of information in an easy to read and compact format. Your web page gets the Jason decodes it and does stuff based on that like do checks, report error messages and additional information. You can frame the page and layout so you can have a common layout for your site. You can build lots of JavaScript, which does useful stuff. By the way, JavaScript is a tricky language to write correct code in. And that would be a whole talk of itself again, simply to get started. There are wonderful libraries like jQuery for moving stuff around and bootstrap for running a database on your client. And there's a tool called JS hint, which will look at your JavaScript and say nasty things to you like you didn't define that variable before you used it. That was sloppy. You can use compiled CSS rails as nuts for automated tests. I use a few of them at work, not as many as I should, quite frankly. And if you want to have actual users, if you're not on an intranet where you control things through a firewall, do not try to write your own user and password modules. The black hats do this stuff full time and will cut right through whatever new be mistakes you make on it. Pull down one of the numerous rails modules on how to handle users and passwords and just install that and obey the orders. Yes, sir. Yes, sir. Don't build password code yourself. It's way harder than you might think versus one of the things that goes wrong is that because rails is doing a lot of logging, it will actually log the user passwords into the rail log. You didn't want that to happen. The ways to avoid that, but you have to know. Furthermore, you need to upload all this to the web, but we haven't covered that again, a whole talk in itself, but you can use either Amazon Cloud Nine or any of the other cloud providers. You can go to a local ISP if you're within an intranet as I am during the workday. And then you probably have some simple procedure. Ruby on rails lets you have development mode and production mode. And I keep one server in development mode. Then when I'm done with the code, I save it into an SVN database and in production mode, I check it out from the SVN database. And then I do a restart. In development mode, rails is nice enough to load every payload, reload every page when you change it. In production mode, it doesn't do that, which is expensive. It does the reload when you tell it to. And that's a major win. So that way you can change five or 10 modules at once and reload them in a single instant rather than giving your unfortunate users a fragmentary view.  Okay, that concludes the tutorial section of this talk. Now we're on to a comparison of active record and postgres. What part should be, what things should be handled by the database and what things should be handled by active record? I apologize for the screenshot, but this is from one of my favorite movies, The Golden Voyage of Sinbad. If you notice the statue on the right, this was just lying sitting in an alcove binding its own business into a bunch of application developers showing up on the left here came in to see what was what. Then when they turned rails on, it suddenly came to light. And I think of the models as a table come to light. That when the table when the record is sitting in the database, it's just there quiet, biting its own business, being backed up, being watched over and cared for, but not doing stuff. And then when the call comes in from active record, the data, the database record is pulled into the controller into the view and comes to light. And this the swords could be the methods of your rest for architecture like select, insert, update, delete, and some fifth method, which is useful here. And you have the application programmer against the record come to life. Eventually, you deal with it and put it back to sleep. The dark figure in the back is of course the DBA or the database developer. Anyway, I really enjoyed the movie and you might enjoy it too. So the first thing about the advantage, we want to look at the advantages of using rails with Postgres, the advantages in particular of active record. When I started out seven or eight years ago with rails and Postgres, there wasn't that much support from Rails for Postgres. And the situation has gotten way better since then. And in fact, there's a whole page that you can look up and we'll tell you just how to deal between active record and Postgres. Active record is really good for rapid views. One of the most fun bits about active record is something called method missing. Let's say you have a field commenter and you want to search by the commenter in the comments table. And normally, if you're writing a website from scratch, you have to write the select star from comments where commenter equal or matches the parameter. But you don't have to do that on rails. What you do is write a method called find underscore by underscore commenter and call it. And you didn't write that method. You just wrote it down in accordance with the rules. And when Ruby hits that method or the method hits Ruby, it goes all the way up the object chain to the very object, the initial object at the top of the entire object chain, the egg from which all of all Ruby objects come up. It's called object. And it has a method called method missing. And if it doesn't know how to handle fine by commenter, it will go to active record and say, what do I do with this? An active record will say, aha, I know you're working on the comments table. I know the comments table has a field called commenter. I will create a search method on the commenter field right on the fly. And the next time somebody does this, I'll have that method ready, and you won't go all the way up to method missing. So this means that you can have hundreds and thousands of fields in your database, and you don't have to write search scripts for all of them. If you need more complicated searches, two fields at once and so forth, there's syntax to let you put them together with a little more trouble, but not much more. Furthermore, if you want to know what are my fields or what methods are currently available, Ruby is nuts for introspection, and there are functions that let you say what are all the functions, all the methods that I can use at this instant. Now active record now provides reasonable support for postgres. As I say, not always true. On the left, you'll see a list of all the data types supported as of the instant for postgres. And you see all the traditional types like this is your binary thing, arrays and so forth. You get strings and text, of course, without even worrying about it. Jason and Jason B are great, even composite types and network addresses. I don't see geo spatial here. And I don't see, of course, user constructed types. But you aren't likely in ordinary practice to need much more than this. And you can do things to cope with new types as well. So you've got your field types known to active records, you can specify them when you first create that table using the Rails generate model command. And that's great. Sometimes there are surprises. Because as I mentioned, Ruby works by convention. And by convention, it does things like let's say you want to count of all the articles, there'll be a pseudo field called articles underscore count, which is that count. If you'd like to call one of your fields underscore count, you could be in for a surprise. Active record is extremely helpful. Sometimes it's too helpful. I remember one favorite problem favorite and only in retrospect where there was an active record command that said I'm going to start here with the parent. And then I'm going to call up its children and its grandchildren and its great grandchildren. And actually, it's great, great grandchildren went four levels down. And for a single active record call, it generated 100,000 SQL calls I counted them. The result was that something should have been instant took 10 minutes. And that was active record being very helpful about fetching the children and the grandchildren. And that was a case where you want to write your own SQL and have one statement, which is infinitely faster. There are all sorts of statements, which features which really require direct SQL support. And you have to know when to cut over to that. Another example of this are time stamp columns. Rails will try fix up the timestamps for you, you do an update through rails, and it will fix the timestamp. But if you have other code also editing the records, you might be better off turning off that Rails feature and fixing the timestamps with a trigger. Okay. So potential problems. As I mentioned, the SQL can be suboptimal. Another problem I've seen a few times is that active record is, of course, talking to the database through some connections, by default, it sets up five connections and just keeps them open. That saves you having to open and drop a connection. It does a little bit of PT bouncer style pool management. But sometimes you run out of connections. You have to be aware of this is happening and be prepared to work around it up the number of connections, spread your code out, or you'll get a bottleneck at the connection pool. Okay. Active record does caching. If you edit a record on the inside, you have to tell active record to reload that record. If it's currently being looked at by a user. And of course, you have the users hammering the database as they always will. Active record, the cascade of Ruby on Rails, active record Ruby and Postgres can't deal with every new piece of ingenuity your users come up with. Well, that's a regular development programmers problem. And the great thing about these frameworks is that they do the routine work that's in common across websites, the stuff specific to your project you're responsible for. It has to be that way. So we are at the pen ultimate page. And we'll look quickly at some best practices for active record and Postgres. They give you a default exception page here. Okay, it's an exception page. And it tells you that something went wrong. I have a checklist for exception pages. Number one, reassure the user it's not his or her fault. Any exception is always the programmers fall. Tell the user what to do next like go to the homepage report to it. For that matter, just tell it send an email back to the developer with a stack trace that also and I think this is important, log the air to a table of error. So you can do analysis. Am I seeing a lot of a particular kind of error? And this is a very valuable technique. Usually, if you see like I have 10 errors at the same line, you can pretty much go to that line and say I know what the problem is. You want when using active record of the rails interface to databases to put an active record what is a good fit for active record stuff that's dynamic that live statute. You don't need to be shy about doing things like relational integrity in active record and in Postgres both. You can go to active record and say these fields have got something in them and go to Postgres and say it's not not. And this way, if some problem gets through one, it will be caught by the other. No harm. There's a lot of automated code checking for Ruby and for JavaScript and so forth, versus Ruby has the minus CW option. Check and warn. And I have this option set. So when I deploy something to production, it runs this check on every module and if a module fails this, which it shouldn't, but it can happen, it stops the replacement. And I have to fix it. You want to write any code that faces the database and begin rescue and which is Ruby for trap the exceptions. And all exceptions should send an email even if they don't create an exception page. I usually like to write the air handling first and then write the code. And this is a variation on test driven development TDD, where you first write the tests, and then you write the code, so that your tests will first go red because there's no code, and then hopefully they'll go green when you write the appropriate code. And you can keep the tests around as a regression suite. Okay. So we are now on the final page of this talk, best practices for site building in general. This is perhaps the most famous site building failure of all time, or at least the biggest. This is the bent pyramid. It's the second pyramid that was ever built four and a half thousand years ago. They decided to save money by not digging the sand out all the way to the basal underneath, because it was a lot of money to dig out the sand. As a result, when they tried to put stone on top of the sand, it turns out when you put enough weight on sand, sand turns into a liquid, and they began to see their little pyramid drift, or actually bigger pyramid.  And they had to scale back the plans and put the rest of the pyramid in at a reduced angle to have less weight on the sand. So you want to have a clear overall objective, have dug the sand out of the way. And I hope this talk will have helped you with that. Use each tool for what it is good for. Don't try to write data analysis tools in Postgres. Postgres is not Excel, but don't use a word as a database. Word is not Postgres. One of my big rules is throw the first one away. In fact, I followed that rule for this talk. The first version of this talk was way long and complicated. And I said, you know, I can get a much better talk by letting the tutorial do the step by step stuff and giving you the overview in the talk. So I'm following my own advice. When you put together a site, don't just think about your target architecture, but figure out what order you're going to build the stuff at. Build articles and comments first, some other stuff or do a different build order, but pick an order that lets you test and validate as you go up. Don't do everything. Don't build 10 tables at once and then hope the whole thing's going to work. It's not. Once it's up, make sure you plan to make it easy to fix up. You have lots of error messages and testing and so forth. And that should give you a nice, solid piece of work so you can be proud of that will provide real value to your users. And I hope this talk has provided some value to you guys. Okay, I'm going to take a look at questions now. But thanks for your attention. What have we got here, Lindsay? That was great. Now, we haven't gotten, I think we've only gotten one question. So now is the time to get them in if you have any. And the one question is, will the presentation be available in order to take the URLs? It will actually be up on my website. Probably by the end of today, that will only be the slides, not the actual recording. So that's our only question. And I figure with that. Thank you, John. So much for taking the time. This was really, this was really, really great and really great perspective. So I really do appreciate it. And to all of our attendees who spent a little bit of your day with us. Thank you so much. I hope to see you at future Postgres conference webinars. Cheers. Okay, thanks, Lindsay, for setting this up. Okay.


This is a terrible ult chat, if you guys don't say not as I do, there's 2 hooka, 2 hooka, 2 hooka, 2 hooka, 2 hooka. Before the video continues, I wanted to talk about today's video's sponsor, Valorant Tracker. Valorant Tracker is an app that assists with everything you need Valorant related. One of the best features in my opinion is their live match infill tool that gives you a full breakdown of all of your teammates and opponents for the current match that you're playing. And you can also look at your stats even beyond the current match that you're playing such as your weapon accuracy, your win rates, your best maps, your best agents, and more. What I use a lot is their match history tab. It gives you a full breakdown of your most recent matches with detailed reports on every player in the match and I can also see if I play against any familiar faces for streamer reactions in my YouTube videos. Valorant Tracker is completely free and you can download it by using my link in the description or the pinned comment below. Enjoy the video. I'm really low. Cypher's here. I'm sure he'll get to the trip. There's one close here. Back triple, back triple. I think. I once watched Valorant. There's no going back after it. Kidding. Please don't like it. One's up top here. My ping, my ping, my ping. And one's up a wrap too. Why is my short skin so beautiful? It's the fade one I think. Yeah, two mid again. Two mid again. The same two people. They're on top of the wall. Can you help me? There's one elbow. My bad, my bad. One AK? One, I don't know. That guy was AK. He shot me last second. One tree. Three tree. Last player standing. Fight down A. Over here. One enemy remaining. Oh, I thought he was a cat. Where? Two more. And they got the spike. Plus, two more hookah. One is inside. One is inside. Two, two, two, two. They got the spike. They're both hookah, right? I don't know. He went there. I'm going to take TP one sec. They're going to TP. They walled themselves off. Back right. I'm kidding about the sniping. Does one be mid side? I'm going to flash tower. One's to be mid. I don't think one was close though. Yeah, they're nervous. Oh. That's close, man.


Hello everyone, today in the previous session we have discussed different components of time series analysis that means what are the components exist in a time series data and how can we analyze them and how can you make a prediction by understanding that behavior of the data that part we have discussed through different components of time series data. Now we are going to discuss the measures of forecast accuracy that means once you make a forecast with the data after understanding the different components and the pattern of the data and bringing a accurate model or appropriate model time series models, suppose you have made the forecast right and that forecast is not sufficient. So you have to calculate the measures, the accuracy level of your forecast right. So that we are going to study now, what is measure of accuracy? Suppose if you calculate mean of a data, suppose you have a past data or any data and you want to calculate the mean of the data, in that case you know only mean is not sufficient, you need to calculate the standard deviation right like variation of the data measure of this person you have to calculate. So this way you can calculate mean variance and standard deviation and that standard deviation or you know diversion from your mean data is also important and you can understand what is the confidence of the data or confidence interval of the data and accordingly mean and standard deviation people calculate right. Similarly in time series data, when you have past data and you understand the pattern of the data and you have already selected, suppose you studied all the models of time series and you have already selected a model and you have made a forecast, but this only forecast or expected prediction is not sufficient. At the same time like mean and standard deviation, at the same time you need to predict, you need to calculate the measure of accuracy, the error part how much deviation are being there with your data from your mean predictions. So that is called measure of forecast accuracy. For example, if you go to the time regression analysis or causal models which we will discuss later, if you calculate the regression or the relationship between dependent variable and independent variable, so we calculate how strong the relationship between dependent variable and independent variable right and that calculation are been called as a measure of determination or you can say r square. So r square which is nothing but square of correlation coefficient, so this r square actually measures the confidence or how much it is explaining, the independent variable is explaining the dependent variable, so that is been calculated through r square, so that define the relationship between dependent variable and independent variable. So where the r square means the better the regression analysis or the relationship you have built between independent variable and dependent variable, same logic need to be implemented into time series data also. That means if you have a past data and you want to make a forecast for future, you have to calculate the measure of accuracy, how the measure of accuracy can be calculated we are going to study now. So generally there are 4 methods, 3 methods, there are many more methods available in the literature, but today we will discuss only 3 plus 1 total 4 methods, 1 is the mean absolute deviation of the data and mean absolute percentage error, then mean square error and then square root of mean square error, we call it as root mean square error RMSC which is very popular in financial domain. So let us understand one by one the measure of accuracy of the data and how that is been calculated and let us bring a numerical example, through that we will understand how this measure of accuracy of a time series data can be calculated. So first one, the mean absolute deviation, look at the calculation here, it is nothing but the data, the actual data, the difference between actual data and the forecast data and take the average of all the error, the residual part and that average if you take that is called the mean absolute deviation. I will give you example in the next slide you will get to know, suppose you have a time series data, let me put a sample data and suppose this is your forecast, this is actual data and this is your forecast data. Suppose actual data are here, suppose y1, y2, y3, y4, y5, y6, dot, dot, dot, dot yn. So you have the actual data and suppose you have made a forecast, y1 forecast, y2 forecast, y3 forecast, y4 forecast, y5 forecast, so this way suppose you have made the forecast, right. So now if you calculate the error term here, in the right hand side column, I show you in the next slide or in the excel, so you calculated the error, right, error, what is that? What y minus y hat, so this is what your you know formula. So if you calculate the error term, this error term if you consider suppose error, this error term if you consider and if you calculate the MAD mean absolute deviation, mean absolute percentage error, this will give you the accuracy level of the model. If the total error, if you take you know some of them we call it a total error or the average of the error, but that may not be good to make a prediction if you take the average of the error, because what happens you know there may be you know this in this case suppose you have a plus 8 error, but suppose here suppose e10 suppose you have a say minus 8, so effectively what happens if you add them you will you will say it is cancelling out. So it is coming to be 0, so error is not 0, but actually too much of deviation from your actual data, right. Suppose you have a data like this and your forecast are like this, so look at the deviation, this deviation if you add your total error might be if you take only average it might be you know 0, so it is not good, but your prediction should be closer to the line. So therefore, we take the absolute value of the error and then we take the average we call it as a mean absolute deviation. Then come to the mean absolute percentage error, it is nothing but the absolute deviation part, but what we consider we take the absolute value of the error the residual part and then we divide it by the actual data that means relative value how much error is there in terms of percentage and then we multiply with the 100. Suppose I will show you in the next slide suppose here you have calculate the error error on. So error 1 by y1 into 100, so this is nothing but your percentage error of actual data. So error is the first period error say and this is your actual data, out of actual how much is the error is occurring the deviation has been there, so that you multiply with 100 you will get the mean absolute percentage error. So absolute percentage error you will get and after that if you take the average of the data you will get mean absolute percentage error. Then next is the very popular and throughout the forthcoming sessions I will focus mean square error or RMSE, but it does not mean that RMSE or mean square error is you have to follow you can follow any one of them because in industry people talk about how much is the error percentage error. So they call it is a 10 percent error 20 percent better, so this way mean absolute percentage error has also merit we can follow that also, but I will be focusing majorly on mean square error because in the calculations of excel I have preferred the calculation through mean square error or RMSE or minimizing maximizing etc. through optimization software. So think about mean square error, so it is also same like you know like the waste standard deviation in calculation you take the error take a square and sum them and divide by n you will get the mean square error square of the error. So if the projective negative part I mean remove now you have taken the square and then you are taking you know average of them sum of them and then you do the average you will get the mean square error. RMSE is more interesting because you take you know square root of MSE so that is called the RMSE both are not linear, but very popular in optimization process or you know in time series data analysis for making a forecast with supporting document that is called mean square error or RMSE as a measure of accuracy which provides the strength of the reliability of a forecasting models. Let us understand these three or four you know concepts of mean absolute deviation, mean absolute percentage error, MAPE and then mean square error MSE and the RMSE root of mean square error through a numerical examples. Here let us consider the basic model or name model because we have not started the you know different models of time series in the next session onwards we will focus on that, but let us understand the basic name model which does not require any calculation only. Name method says that whatever the past data you have past period just immediate past period that is your forecast look at here whatever has happened of say TCA stock price in the last day that will be the forecast for the next day. So that means today closing price of say gold or say you know crude oil price or say stock price so if that is the today's stock price closing price tomorrow will be the considered that price will be considered as a forecast for tomorrow no calculation no average no you know seasonality nothing you are considering just you are considering the past data as your forecast then the difference of them with the actual and the forecast will be your error. So these errors will be considering through name models and we will understand the four method of measure of accuracy. Let us go here you know even this name method is also very popular you might say it is very easy you know let us go to the next slides we will get to know you might say it is very easy say look at here so you have a say first period of first week say is 23 the next period forecast this is actual actual next period forecast is say 23 so this has come now. So error you can write down error so error would be say 24 minus 23 equals to 1 so next period you can see for the third period the forecast is second period actual data is your forecast. So your error will be 32 minus 24 so it will be say 8. So this error you are writing in the right hand side and you will calculate the average or mean absolute division etc. etc. RMSC etc. we will calculate through Excel. So this is what called name method for basic understanding of the models I have bought name model but it has a good merit also I will discuss in some other session the advantage of name model. Actually you know in industry the benchmark has been done through name model though it is says that you know whatever has happened in the previous period you consider that as a forecast no calculation are required. But if you go to the industry say quarter to quarter which is forecast or the sales as well as the earning or say you know EBITDA and the PAT profit after tax so all these things are being predicted or been measured through a name model actually. So that means what happened in the previous year corresponding quarter. So that data are being considered as a benchmark for you know improving the you know EPS or the PAT of a company. For example say suppose you think about Hindustan Unilever HUL. So suppose HUL forecast for say third quarter you want to make prediction right. So what whether it is good or bad how will do the prediction can be done some other way but benchmark analysis can be done or the comparative analysis can be done through name model. For example what happened in the previous years corresponding third quarter sales of HUL or say PAT of HUL. So that is your benchmark and that you are making a comparison with the current period of third quarter of this year 2023 say and you are making a comparison.  So this down or up that analysis can also be followed under name method. So previous quarter also you know for margin analysis you can do what happened in the second quarter of HUL and that data you can bring like just immediate data immediate period data and you can see what happened in this current quarter and you can see the difference also. So for margin purpose this is good but for you know profitability and growth purpose of a company people use name model people bring name model because there is no calculation only what happened in the past that you take and you make a forecast for the future. So these are you can make a comparative analysis with the past sales of a company. So this is called name model. We are not focusing on the name model we will bring this name model as a past whatever has happened in the past that concepts only and we will make a calculation of four method. Look at the data here. So we have the data time series data so sample data I have prepared. With this data we have used the name forecast only. So suppose whatever has happened in the past that we have taken as a forecast for the next period and we have calculate the error in this column. So you can take the average of the data. So that we will not consider I told you we will take the absolute value of the data. We will take the absolute value of the data. Absolute value of the data and then we will make the forecast for the we will calculate the MAD for that data that error data. So here is the absolute error and if you take the average of them you will get the MAD. Suppose 2.5 for this data and the next period forecast is the immediate past. That is not important for us to understand because this is just a forecast. So for any data we will be studying several dozens of say time series models or forecasting models. So everywhere we are not bothered about what is the forecast value. Our main concern will be what is the error part mean square error or RMSE or the percentage error because lower the error that is the better forecast because forecast is prediction future prediction. Even in the Masenland it takes all about the predictions. It might not happen in future. If some computer closes store enters demand might shift to you so your sales might go up. So therefore you cannot make anything everything accurate. So you just a forecast by understanding the study of past data or behavior of the past data through different understanding of components of the data and you make forecast. That's the forecast only. So to make a business plan for the forthcoming periods or quarters but effectively you need to focus about absolute error calculation. Suppose here MAD you have calculated. So note that point actually. Now if you take the percentage of error so you know percentage you have taken and divide by absolute error by actual and then you multiply with the percentage error. So you will get the absolute percentage error and then if you take the average of that you will get the mean absolute percentage error. And the square error you can take also square of the data or absolute data, absolute error square and then if you take the average you are getting RMSE, MSC. And the square root which MSC is RMSE 3.22. Suppose this four you have calculated. Now you might say, sir okay we calculated the MAD of the data with actual data and forecast data by calculating the error. We have calculated the mean absolute deviation. We have calculated the mean absolute percentage error. We have calculated the MSC and we have calculated the RMSE. But the point here is that which formula we should calculate we should consider for our forecast with our data, with industrial data or practical data or say for our project. You can select only one of them. You don't record all four. MAD is also has a merit percentage error. MSC also has a merit. MSC or RMSE also has a merit. Any one of them you can select. You don't record all three to calculate for a particular data. Because these are the different model because here is a percentage. It's a 9% say. And here is a 10 point something some different calculation. So you cannot compare them. If you what you can do is that you can select different model. Suppose name model for that data I have used and have calculated the error. Suppose if you calculate the say moving average model suppose if you bring a moving average model and you calculate this particular data forecast through moving average you will get a different percentage error or say MSC or RMSE. That RMSE of moving average model and name model you can compare. And then you can see for this particular data whether moving average model is better or name model is better. That is that comparison you can do. But among the measure of accuracy formulas you don't need to make any comparison because they have a different merits. So you select any one of them and you make different and use different models and make a comparison and see whoever is providing lower RMSE or the lower error percentage error you select that model okay. So select only one formula among the three or four that I have discussed today. So let's see suppose for this particular data we got name forecast with percentage error of 9.34 or say mean square error say 10.37. Note down it. Here you can see the name model also. For your understanding you can see whatever has happened in the past that is the forecast for the next period. Look at here whatever has happened in the past that is the forecast for next period. Whatever has happened in the past that is the forecast for next period. So this way you can culture and the actual is coming like this. So error you can write down which I have shown you in the slides. Error you can write down in the right hand side and you can calculate the name forecast. The forecast is not also bad. But it does not take the trend of the data whatever has happened in the past that you are taking. So seasonally trend cannot be captured through that effectively. It is just a basic model to make a comparative analysis of the data. So I thought of bringing that to focus on measure of accuracy calculations. Now for same data suppose you know if you use with moving average model suppose if you calculate the simple moving average model for the same data if you implement the simple moving average and if you calculate the error I will discuss detail of moving average models simple moving average and the say you know weighted moving average or you know exponential moving average in a separate session. But here you see suppose you have select the moving average model and suppose you have considered four period moving average. So, you take the four period average and make that as a forecast for the next period. Then in the next period what you do? You drop the older period and select the this four period average you keep the range you keep and then as it is then you can freeze it and then you consider the next period into your data. So, your next combination will be like this to make a forecast for the sixth period. So, this way suppose for example, for 14th period your forecast will be combination on the past four period because four period combination you have taken. So, you can make a forecast for that and if you drag that you will get the forecast the moving average once you select the cluster or the range of the data say four period and if you drag it every time one older period you will drop and new period you will be considering you will be adding to your average. So, this way if you consider and if you make a forecast that forecast is called the moving average forecast. We will discuss that detail in the next session. Now, using that model for the same data if you calculate the absolute error error and the corresponding absolute error you are getting MAD is 1.71 and percentage error is you know 6.61 and RMSE, MSE is a say 4 and RMSE 2. So, what is the comparison now? Now you can compare think about you know say MAP percentage error think about this how much is the percentage error for moving average data for moving average model of the same data 6 percent 6.6 percent if you select the percentage error as a comparison. Now if you come back to the name model what was the forecast through percentage error? The percentage error was 9.34 and if you see name model sorry moving average model here 6.61. So, which model is better for that moving average model is better because it is giving the less percentage error 6.66 percent 6.6 percent and that was 9 percent 9.5 percent say. So, the name model is providing higher error. So, therefore, do not select name model for this data you select moving average model for this data. This is what the comparison you can do for that particular you know for a particular data and by selecting different models, but you cannot compare MAP and MSE. For example, here you can see the MSE is 4 here for this moving average model of this data 4 note down it, but if you go back to name model here you see for name model it is 10 here it is 10 and there it is 4 only. So, which model to select the error is where you are getting less error on an average you are getting the less error through moving average model for that data. So, do not select name model for this particular data you select moving average model. So, this way you can use the measure of accuracy for different model. So, today what we have discussed actually. So, here you can see the graph of moving average model and you can see it is taking the average. So, 4 pure average it is taking and it is forecast the forecast started from that point and then you drag the forecast the moving average you get the forecast. So, this question looks better actually as compared to name model and this is the forecast which I have shown you through competitive analysis here. So, this is called the different aspects of measure of accuracy whether it is a mean absolute deviation, whether it is a mean absolute percentage error, whether it is a mean square error or RMSE. I have not talked much about RMSE today, but next class onwards you will see everywhere I will be using RMSE only for my excel calculations. And then you can see the competitive analysis between different models through percentage, so through error of absolute error or percentage error or say mean square error and that will be your benchmark calculation for a model which model is most suitable for this particular data. I will show you now some excel calculation for that error calculation here you can see. So, here I have calculated the name model enter same data what I have shown you in the PPT I have kept in the excel now this is the data you can see and this is the forecast for the next period just I have copied this 23 here and then 24 here this way I have copied here you can write like this also like this cell is your forecast and you can drag it right you can drag it. So, this is your forecast right, but look at the error. So, error I have calculated here and I have taken the absolute error here absolute error here right absolute data of that this absolute value you can keep here and then percentage error I have also calculated here MAD mean absolute deviation of the average of the error and here I have calculated MAP in terms of percentage and the average of them and here I have calculated the MAC what is that just you take the square of them square of the absolute data or error or actual error because you are taking the square and then you take the average of them total 16 error I guess total 16 error we have a 16 error. So, this error is the main document of your residuals of the data and using them you can calculate the MAD MAP and MAC and the corresponding you know RMS also you can calculate square root of it. So, all four are been calculated here this way you can calculate the error for any data with corresponding forecast. So, what is the summary this is the forecast 25 for the pre-auditing and this is the MAC 10 or say MAP 9.34 percent. Now, for the same data I have used the moving average and you can see the forecast is 26.5, but in main method here it is 25. So, moving average model I have used so 4 pre-auditing average I have taken 4 pre-auditing average I have taken and I have dragged it right dragged the moving average. So, I got the forecast for the pre-auditing. So, here you can see 26.5 is not the main part it is just a forecast for throw moving average model and in name model what is the forecast in name model the forecast is say you know the forecast for name model for pre-auditing are just you know 25 that is it. So, you might say here it is 25 there is 26.5 which one is better both are better both are good that is not the objective, objective is the calculate the error. So, here you can see for moving average the error is 6 like here you can see it is about 6 percent only right almost 6.6 percent here and here if you see the name model what I talked about it is a 9 percent. So, moving average is better similarly if you think about name model MAC it is 10.37 or RMS is 3.2, but if you go to moving average you are calculating the MAC or you are getting the MAC how much 4. So, 10 and 4 it is a much difference right. So, it is a much more this model is much more reliable or with better prediction you are coming up with moving average model for this particular data. So, you can recommend that for this data select the moving average model because it is giving lower error or better accuracy. So, this way you can actually you know calculate the or use the measure of accuracy for different model and this is a mandatory for any time series data without that you cannot make prediction only the outcome of the data for the future. That means 26.5 is the forecast for the pre-audiative that is not the sufficient at the same time you have to calculate the measure of accuracy whichever the model will give you the lower a measure of accuracy that model you have to select. Suppose for this particular data we have is name model and we have is moving average model and we found moving average model to be the unique winner. So, you select that, but if you select any other model which can give a better forecast than moving average model you have to go to that model rather than moving simple moving average model. So, in the next class we will discuss different type of moving average model and with the same data we can bring and we can see among the moving average which models which model is more suitable for this particular data. We will understand more detail about that in the next session, but today let us conclude the session about understanding of different type of components of time series data which we have discussed in the part 1. And now in part 2 we are completing the you know the different type of measure of accuracy and we understood how that this measure of accuracy are being calculated and what is the need for their use in time series data. So, with that let us conclude today's session.


Hello and welcome to the session. I am Asha and I am going to help you solve the following question which says show that diagonals of a square are equal and bisect each other at right angles. Let us now begin with the solution and here we are given a square A, B, C, D and we have to show that the diagonals are equal that is A, C is equal to B, D and they bisect at right angles that is A, O is equal to O, C and D, O is equal to O, B and all these four angles are right angles that is A, C and B, D intersect at right angles. Now consider a triangle A, D, C and triangle B, C, D here side D, C is common to C, D, angle A, D, C is equal to angle B, C, D is equal to 90 degree since angles of a square 90 degree each also A, D is equal to B, C since opposite sides of a square are equal. Now from these three conditions by right-hand side rule it follows that triangle A, D, C is concurrent to triangle B, C, D and this implies that A, C is equal to B, D since by C, P, C, D that is if two triangles are congruent then their corresponding sides are equal. So this implies that diagonals of square A, B, C, D are equal. Now we have to show that D, O is equal to O, B and A, O is equal to O, C and they intersect at right angles. Now in triangle A, O, B and triangle D, O, C, AB is equal to DC since sides of a square are equal and also since AB is parallel to DC and BD is any transversal so angle A, B, D is equal to angle B, DC that is we can say angle AB, O is equal to angle O, D, C since AB is parallel to DC and DB is the transversal this implies angle ABD is equal to angle B, DC since alternate interior angles are equal. Similarly we can say that angle BAO is equal to angle TO since again these two lines are parallel and now AC is the transversal this implies angle ABD is equal to angle CDB. Now from these three conditions by ASA exam we can say that triangle ABO is congruent to triangle DOC which further implies that AO is equal to OC and DO is equal to OB so this is by CPCT according to which if two triangles are congruent then their corresponding parts are also equal. So with the help of ASA exam we have shown that the two diagonals bisect each other and now it is considered triangles AO, D and triangle AO, B. Now in these two triangles AO is equal to OA this is common sight DO is equal to OB just now we have proved AD is equal to AB since sites of a square are equal. So by ASA exam triangle AOD is congruent to triangle AOB so this implies angle AOD is equal to angle AOB since again by CPCT. Now angle AOD plus angle AOB is equal to 180 degree and since these two angles are equal it follows that two times angle AOD is equal to 180 degree which further implies angle AOD is equal to 90 degree. Similarly we can show that angle AOB is equal to angle BOC is equal to angle DOC is equal to 90 degree this implies that diagonals of a square are equal bisect at right angles. So this completes the session take care and bye for now.