Rock Music Recommendation Software
Tags: python, algorithms, computerscience, database
Published: 2023-09-30 08:34:38

(before anything, I really just want to sat that I am not a professional, or even have many years of experience in the area, so be concerned that there may be some mistakes in my explanation. I am posting this blog as a kind of *exercise*: explaining what I've built and how I built it, while using simple terms. In a way that anyone can understand! So feel free to make corrections and send me a feedback in the comments :)

## A Brief Introduction...

Hello! I started this project with the simple idea of making an **easy** Python software that was capable of creating a **good interface** for users to **find what they are looking for** in a **spreadsheet**. This could be any kind of spreadsheet, but I decided to make it 💫Rock 'n Roll💫 themed!🤘🏻🧑🏻‍🎤




![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9wk5v47hu352ge6832qw.png)




And if matching the user input to the closest value in the spreadsheet wasn't enough, I have also included a sort of "autocomplete" search algorithm:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mm7flexsilzfdbpn1hhz.gif)


Now you may be wondering: why a spreadsheet? Well, from all the possibilities, it seemed to me that spreadsheets would be both: a good file type to practice (working with .CSV), and the simplest way for anyone to try this software on their own (as basically anyone knows how to use Excel or Google Sheets). 🧠




## Gathering Data
To able to achieve this software I firstly needed to convert my spreadsheet into a more *programmable* kind of data. So I decided to set up a function to collect all the data stored in my .CSV file and organize it in a **Tree Node** structure. This made things much easier to manage since I was already thinking of something like:

- **Genres** are composed of **Artists**. 👯
- **Artists** (usually) produce **Albums**. 💿
- And **Albums** are a collection of **Songs**. 🎶

Which, in a Tree, is basically:

![Tree Structure example](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4cpmuv8xwego51hozipy.jpg)

My `generate_tree()` function is the one responsible for setting each value in its specific position in the Tree. 🌳

You can see the whole Tree generated by typing 'Library':


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nj2vv8cmidamrlrfnkhd.gif)


Once we have our Tree, all we need to do is search in it for the value asked by the user. Which takes us to...

## Tree Search
For this project I decided to implement a **Breadth-First** Search algorithm. This works basically by following a **FIFO** (First In First Out) order to compare each **Node** in our **Tree** with the goal value (the value asked by the user). By using this FIFO ordering, we end up looking at each layer of the Tree before moving to the layer below:


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3s12krl0dtwsad826y94.jpg)


 If the **current Node** is equal to the goal Node — 💥 BOOM!💥 — we got it! All we need to do is **return** the path to this Node (which we save at each step, using some loops). Otherwise, if we get to the end of the Tree without a match 💔 we return an empty path.

## Interface
And, with all the values returned by these functions, the only thing left to do is present them to the user. 👀

Just mix some conditions and String concatenation with all these and *tah-dah*: 🪄

https://github.com/vifatala/Rock-Music-Recommendation-Software/blob/main/tree_search.py