Writing a simple Data Structure In Python3 for Fortnite Stats Tracking and Data Analytics | Mike Bell | Skillshare

Playback Speed

  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Writing a simple Data Structure In Python3 for Fortnite Stats Tracking and Data Analytics

teacher avatar Mike Bell, Hacker Teacher

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

9 Lessons (42m)
    • 1. Introduction

    • 2. Installing Python3

    • 3. Hello, World!

    • 4. Creating A New Class, Constructor, And Method

    • 5. Accepting Input From The User

    • 6. Implementing Input And Seeing The Output

    • 7. Writing Output To File And Verifying Results

    • 8. Viewing .csv Output In LibreOffice

    • 9. Outro

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.





About This Class

This is a simple how-to create a custom data structure used specifically to log games of Fortnite. We will be writing this structure in Python3, as well as a simple way to create and save log entries to a CSV file. This class is for beginning programmers, as well as anyone interested in seeing how to create your own custom objects from scratch. There is a lot that can be expanded upon here that will be covered in future classes.

Meet Your Teacher

Teacher Profile Image

Mike Bell

Hacker Teacher


Class Ratings

Expectations Met?
  • Exceeded!
  • Yes
  • Somewhat
  • Not really
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.


1. Introduction: Welcome to Computer Science with Mike Bell. This is my first time creating a lesson for skill share, and I'd like to start somewhere past the beginning, but not so far into computer science that it requires a whole lot of background knowledge. If you're a beginning student and you'd like to make quick strides, you've come to the right place. If you need a bit more intricate baby steps towards what will be building today, you'll might benefit from more beginner tutorials, which I plan on making at some point, but not today. Okay, so you all should be doing this in some sort of Lennox bash terminal. I will be doing this from my Mac OS Pash terminal. Your Windows user will be able to help you from here. I recommend that you download Virtual box or VM ware or some virtual ization solution and grab with Lennox distribution like a bun two or DB in and go through the installation process so that you can work in the Lenox environment 2. Installing Python3: you are going to need python three installed on your machine. If you are not using Lennox and you don't have it installed, you should navigate to the official python dot orc website. Navigate to downloads and click on your platform, which will be either Windows or Mac OS X. What say it's on Windows? It will then have a latest Python three release up at the top as well as a, uh, stable release. 373 is the current release. So click on that. And then if you scroll down, it tells you all about what's ah, good with it. And then you can scroll down to the, uh, execute herbal installers for X 86 64. If you click on this one, it will download an e x e file that you will then run, which will install Python onto your machine. Let's say you are running on Mac OS X. You will go to the Mac OS X page. You will click latest Python three release. You will scroll down in the same way, and there is a Mac OS 64 bit installer right here for OS X 10.9, and later there is also an installer for 10.6, and later, as I'm running 10 10 I believe I am running the most current version. 3. Hello, World!: Okay, So now you're ready to create our environment, go ahead and create a directory and name it my fortnight stats and changed into that directory you can use this are do this using M k D I R might fortnight stats and then CD my fortnight sets. This is not a lesson or tutorial on how to use bash commands or Lennox or anything like that. So I'm gonna assume, you know, at least this much to start working. We're gonna create a single file called main dot p y using your editor of choice. Create a new file in this directory and name it main dot p y I will be using v I or them the I am. It is very old Teoh, very old editor. This is not a tutorial on editors. So whether you like to use Nano or anything like that, eventually I'll get around Teoh doing tutorials on those. But for right now, this is just python and creating your own fortnight objects for your own steps, tracking for most new projects. No matter what language I'm working and I usually start with hello world. So we're gonna do that here as well for me. Hello World in Python is basically sculpting program like a bare minimum script, and it starts with death Mean open closed parentheses. Colon, which is our main function. Every program in general has a main function. Acts as an entry point to the program. It's also a starting point. Inside that mane, we're gonna simply print open front disease. Double quote. Hello, comma World double quote, close parentheses. Whole World is a string, which is passed to the print function as an argument. The result is that the string is written to standard output. Lastly, there's a special bit of code helps designate anything actually running the program. That is the real entry point that is indeed the main function. And it looks like this if underscore underscore. Actually, I'd like to start using a new way that I recently learned to refer to Double Underscore. It is called Dunder d u N D E r. Looks like this word Dunder, so it's double underscore If Dunder name Dunder exactly equal to quote Dunder Main Dunder quote. Cold main way this reads is if Dunder named under exactly equals Quote Dunder Main Dunder quote colon Execute the main function. So Dunder named under exactly equal to Dunder Main ways, actually reads and the meaning of it. It sells our program. Whatever program is running this script, whether it's Python three, Interpreter, High Charm or Jupiter or whatever visual studio Iron Python. You know, whatever you're running this script with that the actual main entry point is the main function. So start there. Your python program basically checks your whole file first or some line like this to see if it needs to start executing from the top of the file or from Maine. You can probably get pretty crazy here, but 4. Creating A New Class, Constructor, And Method: Okay, so we have a bare minimum python program. Our goal is to create a data structure that represents a game a fortnight. I greatly enjoy fortnight. So much that was to improve upon what I see as their limited stats tracking capability. This means that I created class of objects represent the state structure. So I'm gonna declaring class at the top of my father. I'm gonna name it Fortnight. All right. Any new class in any language was usually desirable to create an initialization method. Otherwise known as an in Stan Shih ation method or constructor method is a function that belongs to an object class. So let's create a constructor for our class. Tide yourself over so that you are one indented level into the class where my cursor is tab over one. It's right here. Um, this is four spaces for tapped. So you should set your editor upto work this way ahead of time. Begin by typing d e f space dunder i n i t. Or In it dunder parentheses itself. Close Prentice's going enter and have yourself over inside of death as well for classes, this is a bare minimum constructor with no arguments, I say no arguments. But the observant among you will see that the word self in between the parentheses there is a reason for that, and that is that self represents the instance of the object itself. Python is explicit about passing this reference and classmethod definitions. You can get into why that is on your own, as it is deeper topic about how the python language itself is implemented. So now we have some important decisions to make such a sin nature, nature of our fortnight entry data structure or how it looks. What it contains etcetera. And at the very least, our fortnight entry object has a time stamp of sorts. A month, a day, a year begin time and in in time. So let's extend our innit method to accept these as parameters. So right next to self, I want you to hit comma, and we're gonna add the word months Comma day. And actually, it's common space when I say you can put a comma day with no space if you want, but it's a little bit more readable if you put a space in between each parameter or each argument. So months, day, year begin time and I'm doing it. Begin underscore time because I'm conforming to a particular Python IQ style and end underscore time. In addition to those variables, we're also going to need a mode, a place in place as and, you know, like, What place did you get in this match? Kills as in how Maney eliminations did you get arena points, which is really only useful if you're logging an arena match accuracy is in What ratio of hits to total shots fired? Did you have hits? As in How many of the shots actually hit a target head shots, as in, How many of your hits were head shots and any notes of the match that you want to lock? So after in time, ready to comma mode, comma place comma kills comma arena underscore points. Comma accuracy, comma hits, comma head underscore shots, comma notes. What's tab over into the method so that we can perform assignments for each one of these variables that were passing it so self dot months, People's months. It's very obvious. One and all of these air very obvious to start with self that date Wednesday self here is here self dot begin. Time equals begin time. Self in time equals end time. Self dot mode equals mode Self dot place equals place. Self dot kills equals kills self dot arena points. People's every in a points self dot accuracy, vehicles, accuracy self dot hits. Those hits self dot head shots because head shots and self dot notes notes, It would be a good idea to have some pre defined values that air defaults for those variables and to allow our construct to be flexible enough to allow objects user or whomever is writing the code using our object to obstinately allow those values to be passed in that whole time. So let's add some default values to method argument with after each argument that you want to specify a default value for you would simply follow the pattern variable name equals, and then whatever value want So common separations. Still following the same rules, all you would have to do here is, for instance, if you want to specify months and actually, once you start, it's best my optional arguments. You have to like every argument after the 1st 1 that's optional or has a default value. You have to like make everyone after that. Also optional, like you can't like, mix and match it like that. So you can't, like, say, for instance, have, like, month equals zero and then day, year and all this stuff like this, every other thing after bond has also have an optional value. But thankfully, because we're trying to create a very configurable ah, customizable object here, this is exactly what we want to do. So we're gonna say equals zero. For most of these, there would be a few exceptions. Mode is not going to be a integer. It's going to be a string. And so we're gonna say equals double quote, double quote for empty string. Place equals zero kills equals zero Read appoints equals zero accuracy equals zero hits, zero head shots zero and notes is also going to be a string so empty at this point, we have a bare minimum data structure. It would be useful to be able to output this data structure in some way. So, like a lot of what I do is very frequently involving excel and spreadsheets. So we could output this object as a comma separated value, uh, that could be inserted, depended to a dot CS file. That would be nice and easy to do. So let's write a method called to see s Zero and that's going to start by looking like the to underscore s CSE. Actually tap that over because this is inside the class to underscore CSP underscore, Grow open, close parentheses. And don't forget the self. So we're going Teoh start by creating an empty string s and assigning it in district. We're going to then attend to that empty string string of variable self dot month. That's the first, uh, variable that we have. And then we're also going to add, plus a comma at the very end. So imagine that, you know, the month was one so it would look like one comma. You know, that's like, what s what looks like right here. Um, so then we're doing you as plus equals str again and renew self dot Day plus comma in double put. So imagine that day was one as well, so I'd be like one comma, one comma right now. Um and you're gonna follow a similar pattern for all the other. Very well. So as plus equals. Str self dot Year plus a comma as plus equals. Str self dot Begin time plus com assess Plus your the end time plus a comma Yes, plus people's All right Now this one What you gonna he was gonna do? You want to basically start by inserting a double quote? So in order to do that, you have to do double quote, back slash double quote, double boat and then you could do plus str self dot mode plus backslash double quote again plus a comma. And actually the comet can come immediately after so you can do it all this one string like that and he could do ask plus equals str self place plus mama s plus equals str self dot kills us call as plus equals str self dot arena for us comma as plus equals str self dot Accuracy plus a comma Pelosi was our So I thought it's plus plus equals r so dot head shots plus comma. So double coat backside Double quote double quote plus S T. R. Itself notes plus double backside, double double s plus equals double backslash in double. Quote this So we take every single parameter that is on our fortnight entry object and you're attending each item one item at a time to a string s that we return at the very end of the function that will basically convert our fortnight entry objects into a column are comma separated value row that we could just simply drop into a CS file and it'll instantaneously be added to it so you could create a running log of fortnight entry rose. That essentially would be like your historical match data. This is a very useful thing to be able to collect. You can have this set up so that, you know, with very minimal effort, you know, just a little bit of typing at the end of every match that you play. Enter this information and in time could even build up to a system where you import images from your thumb. Drive, uh, or your Facebook or wherever and automatically be able Teoh Recognize, based on the image data, the numbers that are inside of it and automatically create for entry objects off of images . That's something that we're able to do, but it's going to take a while for us to build up there, and we have to start somewhere For those of you who aren't familiar with how to write code and how to program, this is a great place. 5. Accepting Input From The User: Now that we have a basic object to play with, we need a simple way to create instances of the object. Something like a basic program that asked to use their tender each field of fortnight entry object like please enter month, please. Under day, please enter a place you got. Please enter. How many kills you got, etcetera. So, um, let's create a new class and call it for tonight and tree client. So just like, uh, before we're going to have a net method death under dull vendors Dunder Deaf Dunder, innit? Dunder itself. But this time there will be no arguments aside self that we need to pass it inside the body of the indictment that we're going to declare that self has an entry object on it by using self died entry. And, um, we're gonna sign any fortnight entry object instance when the fortnight entry client has created So we're gonna say equals and we're gonna say fortnight entry that would create a branding fortnight entry object on the local the fortnight into clients entry property. So now we need Teoh. Create a method called entered data death enter underscored data parentheses. So and, uh it's gonna be something that we're going to use to assign to each particular variable in our fortnight. Entry clients entry object a different value. So, for instance, let's take mode. So you say self dot entry dot mood equals input. Enter mode like that self dot entry dot month equals inputs. Enter self dot entry that day. Input entered day self dot entry dot here input. Enter a year, so entry begin time equals and put enter time itself dot in ST dot in time entered in time country that place people's input. Inter place Self entry kills people's input and turn kills self intrigue. Points I was in put Inter are Rina points, self dot intrigue, dots, accuracy and put inter accuracy. Self dot entry dot It's people's input. Enter hits. Self died entry dot had shots equals input into head shots. Self dot in tree dot notes equals and put inter notes. All right, finally done. So teach property variable of our entry objects. We asked the user to enter some value for it. We aren't doing any form of data protection right now. This is strictly brought and put out to do this. We're using the input function and the parentheses of each input function. We are passing a string that asks the user tender. Some value user will see this when the program is run later. For example, the total line for mode would be self dot entry dot mode equals input inter mode. We wrote those lines and we're good. 6. Implementing Input And Seeing The Output: All right, So now that we have a client class created, we can use a task the user to enter. Those values was going navigate down to our main here and, uh, common tout the print statement putting a hashtag or a pound symbol in front below that line, you know, right A equals fortnight and tree clients open close parentheses. If it's going to create a new instance of the object that we just defined. Fortnight entry client read a sign it to the variable. A. Realistically, we could name very whatever one you could name it Fortnight and Tree Client or some really long word like that. But I'm just gonna do a for right now and we'll get back around Teoh Proper variable naming and what I thought, you know, maybe in a future class. But this isn't about proper naming and what not. This is just about getting something working that is moderately interesting and useful. So now we have a fortnight entry plan. We can actually enter data by calling a dot enter data open close parentheses. The inter data method will follow each of the products that we just wrote the inputs and they will assign the result of what every type to each of those variables on the self doubt entry object in our fortnight entry client. And once we have completed that, then we should simply a dot entry dot to see SV row open, close parentheses and that will straight up print out the A fortnight entry client object in a CSP comma separated value manner, which is very useful for inserting at the end of a dot C S v file as I will demonstrate. So now that our program is written, let's go and save that which I did and we're going to run it. It's gonna be different for everyone. But if you are working similar to myself, all you'll need to do is type. Python remained up. You I So I thought three main dot It asks us to enter mode, so imagine that I'm playing solo, so we're gonna enter a month. Today is, uh, Monday May. So it's the fifth month. The day is 20 and the year is 2019. The begin time would be 2036. The end time would be well, you know, realistically if it starts now and you know we're creating future game here. So let's just say it ends, Uh, four minutes from now at 2040 and let's say I want that match. That would be great. Let's say I got five pills that even more amazing. And let's say, uh, I managed to climb my way out of the hole that I dug myself into and back at 300 million appoints. Let's say you had perfect accuracy. So we're gonna see one point out. And let's say the number of hits that I got was 100 hits and that 10 of them were head shots and that I got the baller. That's what it would print out. Is this line right here? It would comma separate each of those values, and it would be very useful to be able to right these values to file. So, for instance, if we wanted to create a C S V file first of all, doing this from the clinics command line, this is a little bit kind of on the fly, actually haven't scripted this, but I think this would be a great place to tidy up. This lesson is to show you how that we could create a dot CS file without having to do a whole lot else other than run this program and then append the output to the file itself. Let's say we want to create some headers. So even though the order that I ask the questions and is different as you notice, first thing we ask is for mode. Um and, uh, the actual mode appears later in the comma. Separated values is actually not the first value that I output. And I did that on purpose because originally when I was out putting or rather defining the object in the very beginning, I made the decision that I wanted to be able to enter the mode first. So it's not waste time later on because you only have a limited amount of time to actually see the output screen when you like, finish the match before it kicks you out of the arena. And I didn't wanna have to, like, save image files and constantly, like load them up and refer to them. I actually did that on purpose for a reason. So let's say we wanted Teoh create a brand new stats file, so we want to have some headers, right? Like, uh, what's a mode comma? Let's say, uh, months comma actually not mode for his Randy month Comma day comma here actually. Did that whole rat begin time Underscore time And this time mode place kills arena Underscore plates, accuracy. Hits had underscore shots and notes and we're going Teoh first output that by redirecting the results of the Echo Command in my bash Terminal two Stat Stott CSP. Now, if you take a look, we have a brand new stat side CSP file. Even cat STAD starts. Yes, we And there you are. Now, let's say that you wanted to upend the results of running our program to the end of this file so that the file effectively grows. What you would end up doing is 7. Writing Output To File And Verifying Results: back in your main. Unfortunately, it's not so easy to just simply append the output, using the input, function and bash, There's conflicts. So in order to do this, what we really want to do is get our road. And instead of printing out our right away, we're gonna do instead. Is was open. Stat starts. Yes, we A as f f dot right are now. When you go to run our program, let's come up with another fictitious game match. So may 20 years. 2019 2045 2015 1st 5 kills points, one point of accuracy, 100 hits, 10 head shots and all right, so now when you cat stats, you notice that the word inter mode that is getting attended, that's not good. Actually, that's from a previous run. So how embarrassing. I need to clean up that file. So, for instance, if we were to run the program again, uh, sorry. So 5 2020 19 24 7 2050 1st 5 kills 300 arena points. One point of accuracy, 100 shots. Now, if you were to cat stats now, it's a little bit down there, and we can actually clean that up by getting rid of the new line between there. But now, every time I'm gonna run the program, it's going to properly append the values to the next line down. If you were to run the program again, you would see this for sure. So we're gonna do the side duos. Where do? Five, 2020 19 24 7 2050 first place, 100 kills, which is a little bit unreasonable. But whatever one point of accuracy, no Mrs all its 100 shots, every it was. And now, if you were to cat stats could see that it is properly a pending to the end of the file. Now let's say that you wanted to manage several different stance files. That's reasonable. This would want to differentiate between different players unless you wanted to redefine the 49 entry object and come up with a completely new thing. But that little bit of reasonable. So let's say that we wanted to quickly extend this before the end of the session because I feel like this is a pretty good place to wrap up that we wanted to have the ability to specify, say, which arguments it is. So, for instance, we're gonna do this using, uh, from cysts. Imports are now Our TV is nice because, for instance, when you run it from the the terminal like like Siazon, there's no there's no initial argument that gets passed in. But, for instance, the first arguments usually script, name So at the very top of your main, not we're going to from Cysts Import R V. If you didn't do from Cysts, you'd have to say import cysts, and then you'd have to say so stop Arkady. But we're just going to say R. V here, make it a little bit easier on ourselves. We don't really need all assists in here. So, for instance, uh, if we wanted to print whatever the result of our objects and whatnot are are rather parameters when we pass them to the program when we go to run it. What we can do, for instance, is print um, length of R V to start with, just to verify that it's actually a valid thing. So, for instance, here it's one, because the first entry in R. V. RV of zero is going to be made, and you can verify this. So that means that the second value RGB of one is going to be whatever the first parameter is that you passed your program. So in order to do this, But I almost kind of did all of that for my own clarification because I wanted to make sure before I explained it to you. But I ended up doing it in real time. So whatever, uh, RV of one is going to be whatever you pass in. So our length of RV must be, too. If the length of RV is not equal to two, then we want to print. You said, uh, python three mein gott P y. And then, uh, stats file dot CS and then we also want to exit. So, uh, we want Teoh Import R V comma exit And then that way we can say exit negative one we could go and uncommon are other things. But before we do, we're going to say our stats file equals bar V bracket one. Then we're going to uncommon tar A are a doubt inter data are our road are with open and then we're gonna change our with open stats, etc. Etc. To be stats five and then we can say f dot right our row again. This is very clean and tidy, and I think this is a great place for us to test our program one more time before we call it a day. So we're gonna do python three main dot p y, and it immediately complains, which is great because that means that I have successfully implemented an error checking mechanism. It is very important that your code is error checked when you run it and that you write code that is safe. A lot of the code that we have written today is not safe and can be definitely mess with in weird ways. So later we're going to come back to this code and make it safer by implementing type checking as well as various different checks to make sure that the values entered our values that we would expect to be entered. In that way. No erroneous values can be input that might create some sort of impossible data structure like, say, a fortnight data structure that has negative one, as are placing or negative kills or something like that, or maybe something that's like greater than 1.0, accuracy, which is impossible. It's like 110% accuracy. How is that possible? So what we can do now is go python surgery. I mean that you Why stats that CSP? So it starts Arts I asking us and promote We're gonna be solo again. We're gonna say it's currently Monday, May 20 s 2019. Our begin time is going to be 2052. Our end time is going to be 2100. Our place is going to be first again. We got one kill. We are at 300 arena points. One point of accuracy. We got 50 hits, we got 10 head shots and no Vollard this time. Now, if you were to cat stats dot CSP You see that are most recent entry appears here on the bottom. This is effectively a bare minimum for night status tracking. So, like, I could open this up And, uh, how do you say open office or a similar program? And in fact, I think I should do that before we call 8. Viewing .csv Output In LibreOffice: as you can see here, I have loaded up the stats starts es three, file in tow. Liber office. This is allowing me to view it as a spreadsheet. This is essentially the end result that we're aiming for is the ability to very easily inter Rose where each row is representative of a different fortnight Stats entry. So this way you can actually collect your own data and perform your own data Analytics later on. One thing that I'm going to dig into and future videos is how to perform your own analytics using different python libraries. Python as a whole is a very powerful language. It's like any programming language but with the benefit of having a wide variety of easy to access libraries that are very quick to install and quick to implement into your own programs. 9. Outro: I hope you've enjoyed my tutorial on how to write a basic fortnight and three object and a way to enter data into a CS file from within a Python script. If you need any assistance writing code or need a pair programmer, please visit me at www dot code mentor dot io ford slash Mike Bell 66. And you can take a look at my credentials on this page. I started doing things on here in addition to accepting students from other websites, and I currently work in Python C Plus Plus Java script. Html Java Lennix Bash. I also offer code review. I also work in assembly language. I don't currently list that on my profile I am able to help most people in most things, even if it's something that I don't personally know 100% well, myself. I can't even say that I know Python 100% well, but I know it enough to basically write a lot of things from scratch. Apply basic computer science principles, two different problems I'm trying to solve and then get a working result and then later go back and actually clean things up and inefficiently. I hope that you like it again. I hope that you've enjoyed this and please reach out to me. I'll take it easy and have a great rest of you.