 Okay, so many of you probably know that I am a firefighter. Many of you may not know that. Well, I want to talk here real quick about a little script I wrote to solve a problem. And like many things in life, a lot of your problems can be fixed with a simple little shell script, or scripting in any language. So, the county I live in just went to a new dispatching system, which is a great system, definitely better than the old system we had before, where before each station had its zone, and usually the fire station was right as close as you can get to the middle of the zone, and you cover a certain area. The problem with that is if you're out and about, sometimes you might be closer to a call and you may not realize it. So the new system, each truck has its own GPS tracker on it, and when a call comes in it sends whichever unit is the closest, which is a great way to go. It's much more efficient. But there are occasional problems with some weird scenarios. And the weird scenario that I'm talking about here is actually how to do with the station I work at, where as I said, usually the station is, they try to put it in the middle of your zone. My station was built on the very edge of my zone, which is usually not what you want to do. But the reason it's there is because we share the station with a neighboring fire department, so we're all in the same building. And before it wasn't a problem because if we got dispatched, the computer had a database of addresses, and it sent who was supposed to go to which address based on that. But since we're both at the same location, the new system doesn't know who to send, and it seems to quite often pick the wrong truck to go to certain addresses because since we're at the same location, they should still be covering their zone and we should still be covering our zone. But those zones no longer really exist. So people debate on what we should do, if there's anything that can be done. So basically, as I said, the station is right on the border of the two districts. So although we don't have that database anymore, which seems a little silly to me that we had these features before, it's great to implement the new GPS, but the old stuff should still be available, but apparently it's not. The quickest solution I found to fix this problem is, very simply, get the latitude of the station. And if it's north, when you get an address, get the latitude of the address, north of the station, dispatch one unit. If it's south, dispatch the other. Now this isn't going to be 100%, but it's going to be like 99% accurate for the calls we get. And it's very simple to do. I wrote a script in probably about 10, maybe 15 minutes does this, and it's very, very simple. So I just want to show you that script right now. So again, this is a short little script I wrote in about 10, 15 minutes last night to solve that problem of which truck should be dispatched. So quickly I'll just show you how it works. So the program is called Dispatch, and then you give it an address. And again, these are addresses I just randomly grabbed off of Google Maps there, and no way associate to any calls I've run. So here's an address, and I'll tell you whether it's engine A or engine B. Let me do another one. So this address is engine A. And here's another address. Engine B. Another one here. And I am putting in the full address. As you can see, it has the, you know, the city, state, and zip. But in reality, since I'm in that state, I can actually just put the street, and I'm using Google to get the latitude of these addresses, and it knows where I am. So as long as the computer is in the area that you're searching, it knows where you're talking about. It's a good practice to put the full address in there. So let's go ahead and have a look at this code. So this first part here, you know, anything with the pound symbol is just a comment with the first line, it's a shebang line. But here, this part here isn't even really needed in the code. That's just to help the user along. So again, if I was to run the command without giving it an address, it would tell me how to use the program. That's all that first part of the program is. All this up here. So this isn't even necessary, these lines right here that I'm highlighting. So then here, I've got S. I'm setting the latitude of the station. So this is the latitude that never changes, and we're checking if something is above or below it, north or south of it. Then we're setting the, we're getting the address from what the user inputs and calling it address. And so we're going to get the latitude of the address to a variable called C for call. And here is, I am using Google to get the latitude of that address. Now again, the county already has all this in their mapping system, so they should already know the latitude and longitude of the coordinates of an address. But I don't have access to that. So I'm using what's available to me. And so just to show you that working alone. So here we go. So we've got a Google address here, URL, and then we're going to give it the address. So I'll just say 555, 101st Avenue North, and hit enter. It will actually, even though there's not a house at that location, it should return. Yes, it's going to return what the latitude and longitude would be if that address did exist. So here, right here, is the latitude and longitude. It actually gives you it a few times. These are the northeast and southwest corners of the lot, or at least approximately. So what we would do then is we would take that information and I'm going to say grep, which means look for lat. So it's going to find the lines with latitude. Then I'm going to say head dash and one. And that just means give me the first line it returns. And then we'll do some other, a few other commands just to remove everything before that and everything after that, leaving us with just the number. So let's go back into our script here. And you can see that we have that. We are getting all the information from Google. We're going to grep for latitude. We return just the first one. And then these last two commands here, the awk and the cut, are just to trim away all the excess information. So this is one line of code here. I broke it into two lines just for formatting. That's one line of code right there. Now, all we have to do, we have the latitude of the station and the latitude of the call. Next we're just going to say if. So it's checking if something is true. And we're going to say use BC, which is a calculator. And we're going to say, check is the latitude of the station less than the latitude of the call. If it is, then tell us that it's engine A. If it's not, if it's anything else, then tell us it's engine B. And that is it. This is basically right here, the meat and potatoes of the script. And really we've got one, two, three, four, five, six really lines of code. The rest is just broken up for formatting and informational stuff. So problem solved and about six lines of code. And again, let's go ahead, clear the screen and check a few addresses here. And again, these are just random addresses. There's a second or so delay just because we are retrieving information from Google where, you know, if it's to run actually on a county system, they should already have latitude and longitude for all the addresses and it should be a bit quicker, but it's not really that slow as is. And now, so how would you implement this? Obviously you could port this code into the actual program it's running, or you can have the code that's already running, the program you're running, ask this program when it gets an address. So basically it would be, it wouldn't be any address it would use this for. It would only use it if one of the two, engine A or engine B are dispatched. So they put it in the system, you know, whatever this address right here, and it says, oh, it's engine A or it's engine B. But anytime it says engine A or engine B, that program goes okay, if it's engine A, engine B, then ask which engine is supposed to be. So it's asking this program. And if it returns engine A or engine B, then use it. I hope that makes sense. So basically we get a call at this address and the computer, the dispatch system says, you know what, it's engine A or it's engine B. It doesn't really know. It picks one. It says if it's either of those engines, then ask this program which one it should be. And again, that's not 100% accurate, but it's gonna be 99% accurate and it's a quick fix until you have something better, which the only way to really get accurate would be to set up zones in the program again that it can check, which would be a database of addresses and correlating with what truck should be dispatched first. And that's it. So again, really simple, really quick fix. Not perfect, but better than just randomly picking a truck when an address comes in. And that's it. Well, thanks for watching. I hope you have a great day. Please visit filmsbychrist.com. That's Chris Decay. Again, have a great day.