Pringleman83 / SportsBook

A sports data scraping and analysis tool
GNU General Public License v3.0
82 stars 38 forks source link

Making the project more object oriented? #14

Open surister opened 6 years ago

surister commented 6 years ago

The project is looking good bit it's getting a bit big, maybe instead of wrapping everything in functions we can start playing with some classes, that'd make the code insanely more tidy

Pringleman83 commented 6 years ago

This is something I'm only just learning about so I don't think I could contribute much yet. If you want to try some things out though I'll create a branch for it and learn from what you do.

I was considering having a league class where each selected league would be an instance of it. The class could have special functions then to compare teams, return top scoring teams, lowest scoring teams etc.

I'd be interested to know how you'd plan to approach this and what your ideas are.

Pringleman83 commented 6 years ago

I'm continuing my learning of object orientated code today and I'm beginning to understand how it will really help to keep all relevant code together. This is definitely something that needs to be implemented.

While I'm learning, I've started writing a class for a set of predictions. The idea I have is that each prediction that is generated will be added to the prediction set. The class will have all the methods necessary to process the information. I've written some basic code to visually display all relevant information (including stats), an alternative display method that just produces the predictions, and methods for adding and removing predictions. I would also write methods for exporting the list to excel, html, json and text.

It's gonna be a task to introduce this approach to the whole project, but it's definitely better to do it sooner rather than later.

I still think I'm going to do the fixture scraper first, but after that, I'll see how much I can work towards this issue.

surister commented 6 years ago

That sounds sweet, I'll help you as much as possible.

surister commented 6 years ago

This is something I'm only just learning about so I don't think I could contribute much yet. If you want to try some things out though I'll create a branch for it and learn from what you do.

I was considering having a league class where each selected league would be an instance of it. The class could have special functions then to compare teams, return top scoring teams, lowest scoring teams etc.

I'd be interested to know how you'd plan to approach this and what your ideas are.

Yeah create a branch called _experiment or something like that and we can settle some foundations

surister commented 6 years ago

I think it'd be better if the experiment branch was empty, making the project more object oriented is basically rewriting the codebase in a different fashion (we'll copy paste a lot) but I find it easier having a blank canvas

Pringleman83 commented 6 years ago

Fully agree. I've deleted most of the files. I've started an 'idea' of how it could work (class_sample.py), but I'm only just learning OOC, so it might not be the best approach. Feel free to add to it or write up some alternative ideas.

Pringleman83 commented 5 years ago

I've written a couple of classes. One for Leagues and one for Teams. I've complicated things slightly by linking the classes. When a new Team object is instantiated, if necessary a new League object is instantiated too. Checks are performed to see if a League object already exists.

Both classes have class dictionaries keeping links to all League and Team objects. This means all objects are iterable, can be linked to other objects (like a one League to many Teams relationship) and checked for existence.

It's a little complicated (for me at least), but it should help to simplify related code.