Skip to content

This program extracts data on several professional NBA players, and given a positive integer supplied by the user, the program is capable of creating pairs of players, in such a way that their heights in inches add up to the number supplied by the user. The code was written in Python.

Notifications You must be signed in to change notification settings

arnaldo10cisne/nba_app__python

Repository files navigation

NBA App main menu

NBA App - Python edition

Before continuing, don't forget to check the WEB EDITION of this project too!

This program was intended as the resolution of a technical test provided by Macheight. The program extracts general information about several NBA players from an URL and is capable of creating pairs of players whose heights add up to a number previously given by the user.

App capture 1 App capture 2 App capture 3

How to use:

This repository contains the following ".py" files. You'll need all three of them to run this program:

  • main: This is the file where you'll find the rendering of the main menu, and each of the options it contains. It will also do the calls to all the functions that will make this program work.
  • nba_module: Here, you’ll find the most important functions that will help sort the array of players and search for all the matches.
  • support_module: This module includes all the imports that the program needs to work, and some auxiliary functions to help with aesthetics.
  • unittest_module: This module contains some tests applied to the functions in "nba_module", to ensure that they work in multiple scenarios.

Running the code:

You can run this application following the next steps:

  1. First, you have to make sure that you have Python installed on your computer. If you are not quite sure if Python is installed on your computer, please go to the command line and type python3 --version if you are on Linux or Mac, or python --version if you are on Windows. You should be given the current version of Python installed on your computer. If an error message pops up saying that the command was not recognized, most likely you need to install Python. To do so, please follow this tutorial.
  2. After Python has been successfully installed, the next step is very simple. You need to download this repository in a ZIP file
    • Download link
  3. Once you have all files, locate them on a single directory, and make sure to run the file "main .py". If you have all files in the same directory, the app should run without any issues.
  4. If the program doesn't start, however, make sure you have the "request" module installed. This module is required for python to fetch the data from the URL. To install this module, inside the command line execute the following command: pip install requests
  5. There is also the "unittest_module" that contains some unit tests for the functions in "nba_module". To run these tests, you must enter the command python3 unittesting_module.py in the command line, making sure first that the working directory is the same as the one where the files are located.
    • unit tests

Inner workings:

The way this program works can be summarized in the following steps:

  1. After the user selects the option to Start this App in the main menu, the first thing this program is going to do is try to fetch the data from the given URL.
  2. After the information has been gathered by the program, a sorting algorithm is applied to said data. This is to facilitate the search later.
  3. Once the data has been collected and sorted, the user will be asked for a number. Before continuing, the program will carry out all the necessary validations to prevent any failure during the execution of the algorithm
  4. After doing all the necessary validations, the program will perform a binary search for each of the players in the array given.
  5. After finding one match, the program will validate all the other results that are next to it, to collect all possible solutions. I called this part the “spread” algorithm.
    • Spread algorithm
  6. After the "spread" algorithm has collected the indexes of all the players that match, the program evaluates the next player in the array and does the same process.
  7. To avoid repeated matches, the program has the condition that, in a pair, the first player has to have a lower or equal height to the second player.
    • Height validation
  8. Finally, when all the pairs have been saved in an array, the program uses that information to show all those pairs with the first name, last name, and height to the user.

Algorithmic complexity:

One of the requirements of this project was implementing algorithms that had better performance than O(N^2).

Algorithmic complexity

This program has two parts where the Algorithmic complexity is worth considering:

  • Sorting the array: The algorithm used to sort the array was The Merge sort. Created by John von Neumann in 1945, this is one of the most efficient sorting algorithms to date. Worst case scenario, this algorithm has a performance of O(N x log N). It works by dividing the array more and more until we have arrays of just one element. Then, through a series of comparisons, combine said unit arrays in such a way that they are in the desired order.
    • The Merge sort
  • Searching inside the array: The algorithm used to search for an element in the array was The Binary search. It takes the principle of “Divide and conquer”. Worst case scenario, this algorithm has a performance of O(log N), making it one of the most efficient algorithms to date. It works by dividing the array in half again and again until it finds the desired element. The only downside would be the fact that this algorithm requires the list to be ordered. Hence, it the importance of sorting the list before working on it.
    • The Binary search

The most complex algorithm used in this case was the mixing algorithm, used in the sorting section. Then, a function was used where binary searches were performed iteratively, causing an algorithmic complexity of O(N x log N). O(N x log N)

Finally

Any suggestion you have on how to improve this project can be submitted using the contact form in my personal website. Finally, to the developers at Macheight, I am very grateful for the opportunity you have given me to test my skills as a developer. I hope this resolution is to your liking. Please note that I have put a lot of heart into its realization. Have a wonderful day!

About

This program extracts data on several professional NBA players, and given a positive integer supplied by the user, the program is capable of creating pairs of players, in such a way that their heights in inches add up to the number supplied by the user. The code was written in Python.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages