diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..5a0b32c Binary files /dev/null and b/.DS_Store differ diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..038c67b --- /dev/null +++ b/.gitignore @@ -0,0 +1,227 @@ +BrowserLock/ + .CFUserTextEncoding + .DS_Store + .anaconda/ + .anyconnect + .bash_history + .bash_profile + .bash_sessions/ + .cisco/ + .conda/ + .condarc + .config/ + .continuum/ + .cups/ + .fontconfig/ + .gitconfig + .ipynb_checkpoints/ + .ipython/ + .jupyter/ + .python_history + .spss/ + .tcshrc + .xonshrc + .zshrc + Applications/ + Creative Cloud Files/ + Desktop/.DS_Store + Desktop/.ipynb_checkpoints/ + Desktop/.localized + Desktop/3. Semester/ + Desktop/4. Semester/ + Desktop/5. Semester/ + Desktop/6. Semester/ + Desktop/Alisa Bewerbung/ + Desktop/Auslandsemester Sydney/ + Desktop/Bachelorarbeit/ + Desktop/Bewerbung Alles/ + Desktop/Bewerbung Personal Fit/ + Desktop/Bewerbung workshops/ + Desktop/Bildschirmfoto 2021-06-03 um 10.01.09 (2).png + Desktop/Bildschirmfoto 2021-06-03 um 10.01.09.png + Desktop/Bildschirmfoto 2021-06-03 um 11.12.30 (2).png + Desktop/Bildschirmfoto 2021-06-03 um 11.12.30.png + Desktop/Bildschirmfoto 2021-06-03 um 11.12.36 (2).png + Desktop/Bildschirmfoto 2021-06-03 um 11.12.36.png + Desktop/Consulting Club/ + Desktop/ESCP/ + Desktop/Error_handling/ + Desktop/GMAT/ + Desktop/IE/ + Desktop/Imperial/ + Desktop/Ironhack All/ + Desktop/LAB_dicts/ + Desktop/LSE/ + Desktop/MySQLWorkbench.app/ + Desktop/Power Point Templates/ + Desktop/Presentation_game.pptx + Desktop/Private/ + Desktop/RealityConverter.pkg + Desktop/Strategy&/ + Desktop/Versicherung/ + Desktop/ironhack/.DS_Store + Desktop/ironhack/EN_Project1/Project-Week-1-Build-Your-Own-Game-1/.gitignore + Desktop/ironhack/EN_Project1/Project-Week-1-Build-Your-Own-Game-1/.ipynb_checkpoints/ + Desktop/ironhack/EN_Project1/Project-Week-1-Build-Your-Own-Game-1/Project1_Game.ipynb + Desktop/ironhack/EN_Project1/Project-Week-1-Build-Your-Own-Game-1/README.ipynb + Desktop/lab-jupyter-notebook/ + Desktop/lab-tuple-set-dict Kopie/ + Desktop/mysql-8.0.25-macos11-x86_64.pkg + Desktop/reduce_filter/ + Desktop/string_operations/ + "Desktop/~$ Lorenz open f\303\274r neue korrekturen.docx" + Desktop/~$- Arbeit.docx + Desktop/~$2019_Bootstrapping_Exercise_02 NEU.xlsx + Desktop/~$2019_Postponement_Exercise neu.xlsx + Desktop/~$ABC XYZ Inhalt.xlsx + Desktop/~$ALibaba.pptx + Desktop/~$Bain.docx + Desktop/~$C anschreiben neu_comments.docx + Desktop/~$E application.docx + Desktop/~$ESTEL1.docx + Desktop/~$GMAT-Prep-Now-Improvement-Chart-for-OG2021_0(Automatisch wiederhergestellt).xlsx + Desktop/~$Geschlecht- Attribute.xlsx + Desktop/~$IMT One pager.pptx + "Desktop/~$Instagram Influencer pr\303\244sentation.pptx" + Desktop/~$JA NEIN Vorteile.xlsx + Desktop/~$Kommunikations- und Medienmanagement-2.pptx + Desktop/~$LSE.docx + Desktop/~$Lernplan.pptx + Desktop/~$Lernplan.xlsx + Desktop/~$Mappe3.xlsx + Desktop/~$Mappe4.xlsx + "Desktop/~$M\303\244nnlichweiblich.xlsx" + Desktop/~$PPP Influencer fast fertig 3.pptx + Desktop/~$PPP Influencer.pptx + Desktop/~$Pra%CC%88sentation1 [Automatisch gespeichert].pptx + Desktop/~$Reko 4.docx + Desktop/~$Reko 6.docx + Desktop/~$SE neu.docx + Desktop/~$STEL Analysis.docx + Desktop/~$T Text.docx + Desktop/~$TA prsentation..docx + Desktop/~$Tata.pptx + Desktop/~$Tech.xlsx + Desktop/~$Test 1.xlsx + Desktop/~$Unterlagen.xlsx + "Desktop/~$Ver\303\244ndert.xlsx" + Desktop/~$Zusammenfassung.xlsx + Desktop/~$agebogen.docx + Desktop/~$agemn Bachelorarbeiten:Masterarbeiten.docx + Desktop/~$alibaba tabellen.pptx + Desktop/~$anchenanalyse Theorie und Praxis.docx + Desktop/~$ausur hm.docx + Desktop/~$ausur, hm.docx + Desktop/~$axisbezug Peter Ulrich.docx + Desktop/~$beitshypothesen.docx + Desktop/~$benslauf new version.docx + Desktop/~$bject Outline Finance.docx + Desktop/~$c Social Innovation and Entrepreneurship.docx + Desktop/~$chelor Arbeit.docx + Desktop/~$chelorarbeit Finish.docx + Desktop/~$chelorarbeit Fragen.docx + Desktop/~$chelorarbeit Hauptteil neudocx.docx + Desktop/~$chelorarbeit Hauptteil.docx + Desktop/~$chelorarbeit hauptteil neu.docx + Desktop/~$chelorarbeit.docx + Desktop/~$chelorarbeit_EN3.docx + Desktop/~$chelorarbeit_EN_Archiv 2.docx + Desktop/~$cht Zusammenfassung.docx + Desktop/~$cio Political Text 1.docx + Desktop/~$cio political management privatization of war.docx + Desktop/~$cket list neu.docx + Desktop/~$cket list.docx + Desktop/~$commendation Alibaba.docx + Desktop/~$derationsphasen.docx + Desktop/~$dwig Bewerbung_Word EN.docx + "Desktop/~$ellen \303\234bersicht.docx" + Desktop/~$ellenzusammenfassung Alibaba+.docx + Desktop/~$emens Fallstudie.docx + Desktop/~$euern Fragezettel.docx + Desktop/~$ference Letter 2.docx + Desktop/~$ference Letter Prof.Dr.Booms.docx + Desktop/~$ference Letter Prof.Dr.Fleisch.docx + Desktop/~$ference letter 1.docx + Desktop/~$fluencer Drucken.docx + Desktop/~$fteilung IMT.docx + Desktop/~$ibaba 1.docx + Desktop/~$ibaba2.docx + Desktop/~$ichard.docx + Desktop/~$in tools.docx + Desktop/~$isa Praktikum Elina.docx + Desktop/~$isa_Neu_Praktikum .docx + Desktop/~$iting Toeffl.docx + Desktop/~$ko Arbeit Gliederung (Automatisch gespeichert).docx + Desktop/~$ko Arbeit Gliederung.docx + Desktop/~$kro Class Outline.docx + "Desktop/~$l L\303\266schen.docx" + "Desktop/~$l L\303\266schen1.docx" + Desktop/~$l Texts.docx + Desktop/~$lernplan x.pptx + Desktop/~$libaba.docx + "Desktop/~$l\303\266scht ba.docx" + Desktop/~$minararbeit Medien & Kommunikationsmanagement (Final).docx + Desktop/~$ndelsmanagement 6, Beschaffungskompetenz.docx + Desktop/~$ndover Weekend.docx + Desktop/~$neu.xlsx + Desktop/~$nossenschaft.docx + Desktop/~$oduktsicherheitsgesetz neu.docx + Desktop/~$per Medien und Kommunikationsmanagement.docx + Desktop/~$perial Application neu1.docx + Desktop/~$perial Application.docx + Desktop/~$plication Digital Innovation Helena.docx + Desktop/~$plication Social Innovation.docx + Desktop/~$pothesen.docx + Desktop/~$pply Chain simulation.docx + Desktop/~$r Mensch als Marke1.docx + Desktop/~$r Mensch als Marke1a.docx + Desktop/~$rategisches first draft.docx + Desktop/~$rategy Statement.docx + Desktop/~$rategy TATA Motors.docx + Desktop/~$rategy.docx + "Desktop/~$rketing \303\234bung 1 Fallstudie MINI.docx" + Desktop/~$rnplan.docx + Desktop/~$rsonal FIT Questions.docx + Desktop/~$rsonengesellschaften vs Kapitalgesellschaften gewinnbesteuerung.docx + Desktop/~$rtschaftsrecht ZSF. Elinadocx.docx + Desktop/~$rucken.docx + "Desktop/~$sammenfassung Fif\303\274.docx" + Desktop/~$schreiben BCG.docx + Desktop/~$schreiben BCG_Elina_Neu.docx + Desktop/~$schreiben Mc Kinsey_Elina.docx + Desktop/~$se new.docx + Desktop/~$sonders wichtige Fragen Bain.docx + Desktop/~$tegrationsseminar Drucken.docx + Desktop/~$teratur (1) (Luisas MacBook Pros in Konflikt stehende Kopie 2018-11-22).docx + Desktop/~$test.xlsx + Desktop/~$test2.xlsx + Desktop/~$tivationsschreiben Flick Gocke Schaumburg korrigiert.docx + Desktop/~$tivationsschreiben.docx + Desktop/~$u citation.docx + Desktop/~$ucken 2.docx + Desktop/~$ues anschreiben.docx + Desktop/~$uppenarbeit 3.docx + Desktop/~$w lebenslauf.docx + Desktop/~$xusbranche Alisa.docx + Documents/ + Downloads/ + IBM/ + Library/ + Movies/ + Music/ + PWC anschreiben neu_comments.docx + Pictures/ + Public/ + Syntax1.sps + TEST/ + Untitled.ipynb + Untitled1.ipynb + Untitled2.ipynb + Untitled3.ipynb + Untitled4.ipynb + Zotero/ + alles.spv + copied.txt + hello.txt + new-file.txt + opt/ \ No newline at end of file diff --git a/Kick-Off.md b/Kick-Off.md deleted file mode 100644 index f784834..0000000 --- a/Kick-Off.md +++ /dev/null @@ -1,94 +0,0 @@ -Ironhack Logo - -# Build your own game! - -## Content -- [Project Description](#project-description) -- [Games](#games) -- [Project Goals](#project-goals) -- [Requirements & Deliverables](#requirements-&-deliverables) -- [Mentoring](#mentoring) -- [Schedule](#schedule) -- [Presentation](#presentation) - -## Project Description -In this project, you will create your first software! -You are tasked with creating a **game** that interacts with the user, using functions and other basic python resources you have learned during the week. Your game will be able to take an input from the user and provide an output. - -You will also present your game to the class. - -## Games -You will be assigned one of the following games: - -* [Strong Random Password Generator](https://strongpasswordgenerator.com/) -* [Guess The Number](https://www.funbrain.com/games/guess-the-number) -* [Hangman](https://www.coolmathgames.com/0-hangman) -* [Message Encryption & Decryption](https://www.base64decode.org/) -* [Mastermind](https://www.webgamesonline.com/mastermind/) -* [Tic Tac Toe](https://www.google.com/search?q=tic+tac+toe&oq=tic+tac+toe&aqs=chrome..69i57j0l5.1876j0j4&sourceid=chrome&ie=UTF-8) -* [Blackjack](https://bicyclecards.com/how-to-play/blackjack/) -* [Soldier & Dice (Risk)](https://en.wikipedia.org/wiki/Risk_(game)#Attack_and_defense) - -## Project Goals -During this project you will: -* Fork and manage your own git repository. -* Build your own code from scratch. -* Put into practice the basic python concepts learned during the week. -* Get used to public presentations. - -## Requirements & Deliverables -The **mandatory** requirements that this project needs to satisfy are: -* The project must be planned. That is why creating a Kanban board is important. You can either do it manually (e.g. with post-its) or use an online tool like Trello. You can find a template for Trello [here](https://trello.com/b/pc2CNZTo/project-1-build-your-own-game). Remember that you **CAN'T CODE** until your project is planned. -* Your repository must be clean and organized; this means that it must include a *.gitignore* file and a README file and also have a functional file structure. You can easily create a *.gitignore* template [here](https://www.toptal.com/developers/gitignore). -* Your code must include at least one function. -* The project needs to be presented to your colleagues on the day of the presentation. - -The **mandatory** deliverables that you must turn in are: -* Link to the repository you used while working on your project. The repository must include all the files you used to build your game. Remember to commit often to avoid trouble in case you mess up: this means more than 1 commit! -* Link to Trello or picture of your Kanban Board. Include the link or the picture in the README file. - -The **deadline** to turn in the deliverables is right before the project presentations. - -## Mentoring -One of the TAs will be your mentor! - -Your mentor will: -* Keep track of your project in general terms. Your mentor will be the second person that knows more about the project, after you. -* Check if you are following your plan: are you keeping up with your tasks and deadlines? Do you have any obstacles blocking you? -* Help/support you with specific questions. - -Your mentor is **not** meant to: -* Know everything. -* Be your manager. You have to be responsible of your own tasks! - -## Schedule - -**Please note** that the following schedule is simply a guideline. Feel free to organize your work as you see fit. - -**Wednesday** -* Choose the game that you are going to code. -* Plan your project. Remember that we are providing you with a Trello [template](https://trello.com/b/pc2CNZTo/project-1-build-your-own-game). Remember that you **CAN'T CODE** until your project is planned. -* Fork the repository and edit the README overview. You can find a [template](https://github.com/ta-data-bcn/Project-Week-1-Build-Your-Own-Game/blob/master/your-project/README.md) for your README file in this repository. Remember to keep the README up-to-date. -* Once you finish, start coding! Remember to use functions. - -**Thursday** -* Finish the coding and possibly check for bugs in the program (e.g. check what happens if the player gives unexpected inputs to the program). -* In the evening, start preparing the slides for Friday's presentation. - -**Friday** -* Presentation time at **3PM**! There will be a 15-minute break during the presentations. - -## Presentation -You will have **3 minutes** to present your project to the class and then **2 minutes** for Q&A. - -The slides of your presentation must include the content listed below and a demo of your game: - -* Title of the project + Student name -* Description and rules of your game -* Workflow -* Challenges you encountered during the process -* Learnings -* Possible future improvements -* Demo of the game (remember to save time for it) - -Tip: you have only 3 minutes for this presentation so keep it simple! diff --git a/Project1_Game.ipynb b/Project1_Game.ipynb new file mode 100644 index 0000000..fe8877a --- /dev/null +++ b/Project1_Game.ipynb @@ -0,0 +1,85 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "6fe73f8b", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Guess a number between 1 and 100: 50\n", + "Let´s go\n", + "Too bad, this number is too low \n" + ] + } + ], + "source": [ + "import random\n", + "def my_game(game_range = 100, num_guesses = 7):\n", + " \n", + " number = random.randrange(1, game_range)\n", + "\n", + " count = 0\n", + " guess = input(f\"Guess a number between 1 and {game_range}: \")\n", + " result = \"You lost!\"\n", + "\n", + " while count < num_guesses:\n", + " if guess.isdigit():\n", + " count +=1\n", + " print (\"Let´s go\")\n", + " guess = int(guess)\n", + "\n", + " if guess > number:\n", + " print(\"Too bad, this number is too high \")\n", + " elif guess < number:\n", + " print (\"Too bad, this number is too low \")\n", + " else:\n", + " result = \"Good job! You won the game!\"\n", + " break \n", + "\n", + " if count == num_guesses:\n", + " break\n", + " else:\n", + " guess = input(f\"Guess a number between 1 and {game_range}: \")\n", + "\n", + " else:\n", + " print(\"Please enter a valid input and go again!\")\n", + " guess = input(f\"Guess a number between 1 and {game_range}: \")\n", + " return result \n", + "my_game()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "56690403", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.8" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/Project_EN.ipynb b/Project_EN.ipynb new file mode 100644 index 0000000..388f78f --- /dev/null +++ b/Project_EN.ipynb @@ -0,0 +1,481 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "name": "Project_EN.ipynb", + "provenance": [], + "collapsed_sections": [], + "authorship_tag": "ABX9TyOq86Cs7Qv2/S1/qhrA0gar", + "include_colab_link": true + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + }, + "language_info": { + "name": "python" + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "view-in-github", + "colab_type": "text" + }, + "source": [ + "\"Open" + ] + }, + { + "cell_type": "code", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "GJ6WnNYmMmYa", + "outputId": "efdb3d4b-b012-4f40-8fe6-6f8804b55bd3" + }, + "source": [ + "#spotipy installen\n", + "!pip install spotipy" + ], + "execution_count": 14, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Requirement already satisfied: spotipy in /usr/local/lib/python3.7/dist-packages (2.18.0)\n", + "Requirement already satisfied: six>=1.15.0 in /usr/local/lib/python3.7/dist-packages (from spotipy) (1.15.0)\n", + "Requirement already satisfied: urllib3>=1.26.0 in /usr/local/lib/python3.7/dist-packages (from spotipy) (1.26.5)\n", + "Requirement already satisfied: requests>=2.25.0 in /usr/local/lib/python3.7/dist-packages (from spotipy) (2.25.1)\n", + "Requirement already satisfied: idna<3,>=2.5 in /usr/local/lib/python3.7/dist-packages (from requests>=2.25.0->spotipy) (2.10)\n", + "Requirement already satisfied: chardet<5,>=3.0.2 in /usr/local/lib/python3.7/dist-packages (from requests>=2.25.0->spotipy) (3.0.4)\n", + "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.7/dist-packages (from requests>=2.25.0->spotipy) (2021.5.30)\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "RcSbSRbGMuwd", + "outputId": "8dbfea1e-e86b-4cba-f8a6-d9422cbcb8a0" + }, + "source": [ + "#General installed\n", + "import re \n", + "from sklearn import datasets \n", + "from sklearn.preprocessing import StandardScaler\n", + "from sklearn.cluster import KMeans\n", + "from sklearn.metrics import silhouette_score\n", + "import random\n", + "from google.colab import drive\n", + "import pandas as pd\n", + "import numpy as np\n", + "drive.mount('/content/drive')\n", + "import sys\n", + "sys.path.insert(1, '/content/drive/MyDrive/credentials/')\n", + "from config import *\n", + "import spotipy\n", + "import json\n", + "from spotipy.oauth2 import SpotifyClientCredentials\n", + "from bs4 import BeautifulSoup\n", + "import requests\n", + "sp = spotipy.Spotify(auth_manager=SpotifyClientCredentials(client_id= client_id,\n", + " client_secret= client_secret))" + ], + "execution_count": 15, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount(\"/content/drive\", force_remount=True).\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "8e4B-bf2NtZQ" + }, + "source": [ + "#import top 100 from website\n", + "url = \"https://www.billboard.com/charts/hot-100\"\n", + "response = requests.get(url)\n", + "soup = BeautifulSoup(response.text, 'html.parser')" + ], + "execution_count": 16, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "5-MkaThqc6Vd" + }, + "source": [ + "#Billboard Hot 100, songlist and songtitles\n", + "#song titles of billboard HOT 100, via url\n", + "song_titles = []\n", + "for tag in soup.select(\"button > span.chart-element__information > span.chart-element__information__song.text--truncate.color--primary\"):\n", + " song_titles.append(tag.get_text())\n", + "#song artists of Billboard Hot 100, via url\n", + "song_artists = []\n", + "for i in soup.select(\"button > span.chart-element__information > span.chart-element__information__artist.text--truncate.color--secondary\"):\n", + " song_artists.append(i.get_text())\n", + "# Dataphrame of artists and Titles Hot 100\n", + "songlist = pd.DataFrame({'song_titles': song_titles, 'song_artists': song_artists})" + ], + "execution_count": 17, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "b9pT-D-DdRcE" + }, + "source": [ + "#Function Billboard100 \n", + "def get_playlist_tracks(username, playlist_id):\n", + " results = sp.user_playlist_tracks(username,playlist_id)\n", + " tracks = results['items']\n", + " return tracks\n", + "\n", + "top_100 = get_playlist_tracks(\"spotify\", \"6UeSakyzhiEt4NB3UAd6NQ\")\n", + "all_dicts = []\n", + "\n", + "#Funktion Billboard100 audiofeautures\n", + "for i in range(len(top_100)):\n", + " uri = top_100[i][\"track\"][\"uri\"] \n", + " all_dicts.append(list(sp.audio_features(uri)[0].values()))\n", + "len(all_dicts)\n", + "\n", + "#PUT AUDIO FEATURES INTO A PANDAS DATAFRAME\n", + "df = pd.DataFrame(all_dicts, columns=['danceability', 'energy', 'key', 'loudness', 'mode', \n", + " 'speechiness','acousticness','instrumentalness','liveness','valence',\n", + " 'tempo','type','id','uri','track_href',\n", + " 'analysis_url','duration_ms','time_signature'])" + ], + "execution_count": 18, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "gNgeSARtidFE" + }, + "source": [ + "#Final Dataphrame Top100\n", + "final100 = pd.concat([songlist, df], axis = 1)" + ], + "execution_count": 34, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "DTKrEtvNbgN3" + }, + "source": [ + "#Playlist Spotify\n", + "def get_playlist_tracks(username, playlist_id):\n", + " results = sp.user_playlist_tracks(username,playlist_id)\n", + " tracks = results['items']\n", + " while results['next']:\n", + " results = sp.next(results)\n", + " tracks.extend(results['items'])\n", + " return tracks\n", + "\n", + "#Playlist Spotify Songtitles & artists\n", + "all_tracks = get_playlist_tracks(\"spotify\", \"6yPiKpy7evrwvZodByKvM9\")\n", + "song_titles = [all_tracks[i][\"track\"][\"name\"] for i in range(len(all_tracks))]\n", + "song_artists = [all_tracks[i][\"track\"][\"artists\"][0][\"name\"] for i in range(len(all_tracks))]\n", + "spotify_data = pd.DataFrame(list(zip(song_titles, song_artists)),\n", + " columns=['song_titles','song_artists'])\n" + ], + "execution_count": 20, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "8Re27E5MKVFT" + }, + "source": [ + "# PULL ALL AUDIO FEATURES FOR THE SONGS FROM MY PLAYLIST\n", + "#errors = []\n", + "#all_dicts = []\n", + "\n", + "#for i in range(len(all_tracks)):\n", + "# uri = all_tracks[i][\"track\"][\"uri\"]\n", + "# try: \n", + "# all_dicts.append(list(sp.audio_features(uri)[0].values()))\n", + "# except:\n", + "# errors.append(i)\n", + "# continue\n", + "\n", + "\n", + "# PUT AUDIO FEATURES INTO A PANDAS DATAFRAME\n", + "#df1 = pd.DataFrame(all_dicts, columns=['danceability', 'energy', 'key', 'loudness', 'mode', \n", + "# 'speechiness','acousticness','instrumentalness','liveness','valence',\n", + "# 'tempo','type','id','uri','track_href',\n", + "# 'analysis_url','duration_ms','time_signature'])\n", + "# DROP THE SONGS FOR WHICH NO AUDIO FEATURES WERE FOUND \n", + "# FROM THE DATA SET \n", + "# new_artlist = spotify_data.drop(spotify_data.index[errors])\n", + "# new_artlist.reset_index(inplace=True)\n", + "\n", + "# MERGE SONG TITLES WITH AUDIO FEATURES\n", + "# final_fuck = pd.concat([new_artlist, df1], axis = 1)\n", + "\n", + "# STORE DATA INTO CSV TO SAVE LOADING TIME\n", + "# final_fuck.to_csv(r\"/content/drive/MyDrive/playlist_final.csv\")\n", + "\n", + "# LOAD SONGS (INCL. AUDIO FEATURES) FROM CSV FILE\n", + "#longlist spotify\n", + "long_list = pd.read_csv(\"/content/drive/MyDrive/playlist_final.csv\")" + ], + "execution_count": 22, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "TaSyqwk-ixEm" + }, + "source": [ + "#List of all billboard and spotify together\n", + "spotify_billboard = pd.concat([final100, long_list], axis = 0)\n", + "spotify_billboard.reset_index(inplace=True)" + ], + "execution_count": 23, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "1PQugXifjYrl" + }, + "source": [ + "#list with only numerical values\n", + "spotify_billboard_short = spotify_billboard.drop(['level_0','song_titles','song_artists', 'type','id','uri','track_href','analysis_url'], axis=1)\n", + "#spotify_billboard_short.reset_index(inplace= True)\n", + "spotify_billboard_short.drop([\"index\",\"Unnamed: 0\"], axis=1, inplace=True)" + ], + "execution_count": 24, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 110 + }, + "id": "HI-e8Sxn3vFV", + "outputId": "d7625a70-75a4-4859-9609-5038d124fce2" + }, + "source": [ + "\n", + "def spotify_en(dfshort, dflong):\n", + " #User Input clustering\n", + " userinput = re.sub(\"^\\s+|\\s+$\", \"\", input(str('Write down you favorite song: ')))\n", + " #y= re.sub(\"\\s+\", \" \", x)\n", + " #z = y.lower()\n", + " song = sp.search(q=userinput, limit=1) \n", + " print(song)\n", + " song[\"tracks\"][\"items\"][0][\"uri\"]\n", + " sp.audio_features(song[\"tracks\"][\"items\"][0][\"uri\"])[0]\n", + " input_id = sp.audio_features(song[\"tracks\"][\"items\"][0][\"uri\"])[0]['id']\n", + "\n", + " my_dict = sp.audio_features(song[\"tracks\"][\"items\"][0][\"uri\"])[0]\n", + " my_dict_new = { key: [my_dict[key]] for key in list(my_dict.keys()) }\n", + " my_dict_new['name'] = [song[\"tracks\"][\"items\"][0]['name']]\n", + " #print(my_dict_new)\n", + "\n", + " example = pd.DataFrame(my_dict_new)\n", + " #schritt 1\n", + " example_1 = example.drop(['type','id','uri','track_href','analysis_url', 'name'], axis=1)\n", + "\n", + " new = pd.concat([dfshort, example_1], axis = 0, sort = False) #putting the new song below the original list\n", + "\n", + " #scaling the whole list\n", + " scaler = StandardScaler()\n", + " scaler.fit(new)\n", + " new_scaled = scaler.transform(new)\n", + " new_df = pd.DataFrame(new_scaled, columns = dfshort.columns)\n", + " # scaler.transform(user_song)\n", + " #display(new_df)\n", + " #print()\n", + "\n", + " #clustering everything\n", + " kmeans = KMeans(n_clusters=33, random_state=1234)\n", + " kmeans.fit(new_df.iloc[:,:-1])\n", + " #Clusteraufteilung anschauen\n", + " clusters = kmeans.predict(new_df.iloc[:,:-1])\n", + " pd.Series(clusters).value_counts().sort_index()\n", + " #Final clustering\n", + " all_scaled_df = pd.DataFrame(new_df)\n", + " all_scaled_df[\"cluster\"] = clusters\n", + "\n", + " if input_id in list(dflong[:100]['id']): #checking if the new list is part of the hot 100\n", + " cluster_general = all_scaled_df[all_scaled_df['cluster'] == (list(all_scaled_df[\"cluster\"])[-1])] #all the songs of the list which have the same cluster\n", + " double_index = dflong[:100][\"id\"][dflong[\"id\"] == input_id].index[0] #index of the input id in the top100 list\n", + " sample_ids = list(cluster_general[cluster_general.index < 100].index)#list of all ids with the same cluster as the input id which are in top 100\n", + " sample_ids.remove(double_index)#removing the input id\n", + "\n", + " #print(sample_ids)\n", + " suggestion_idx = random.choice(sample_ids)#gives a random choice of the sample ids\n", + " #print(suggestion_idx)#print the index of the suggested id\n", + " #print(dflong.at[suggestion_idx, \"song_titles\"] + \", by: \" + dflong.at[suggestion_idx, \"song_artists\"])#print the song title and artist of the new suggested song\n", + "\n", + " else:\n", + " print(\"This song is not in the top 100 but I've got another one for you\")\n", + " cluster_general = all_scaled_df[all_scaled_df['cluster'] == (list(all_scaled_df[\"cluster\"])[-1])]\n", + " sample_ids = list(cluster_general[cluster_general.index >= 100].index)#all titles which are in the general playlist\n", + " #print(cluster_general)\n", + " try:\n", + " double_index = dflong[100:][\"id\"][dflong[\"id\"] == input_id].index[0]#check if the song is in the long playlist\n", + " sample_ids.remove(double_index)#remove the ones which are the same \n", + " except:\n", + " pass\n", + "\n", + " #print(sample_ids)\n", + " suggestion_idx = random.choice(sample_ids)\n", + " #print(suggestion_idx)\n", + " #print(dflong.at[suggestion_idx, \"song_titles\"] + \", by: \" + dflong.at[suggestion_idx, \"song_artists\"])\n", + "\n", + " return (dflong.at[suggestion_idx, \"song_titles\"] + \", by: \" + dflong.at[suggestion_idx, \"song_artists\"])\n", + "\n", + "spotify_en(spotify_billboard_short, spotify_billboard)\n", + " " + ], + "execution_count": 36, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Write down you favorite song: mamma mia\n", + "{'tracks': {'href': 'https://api.spotify.com/v1/search?query=mamma+mia&type=track&offset=0&limit=1', 'items': [{'album': {'album_type': 'album', 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/0LcJLqbBmaGUft1e9Mm8HV'}, 'href': 'https://api.spotify.com/v1/artists/0LcJLqbBmaGUft1e9Mm8HV', 'id': '0LcJLqbBmaGUft1e9Mm8HV', 'name': 'ABBA', 'type': 'artist', 'uri': 'spotify:artist:0LcJLqbBmaGUft1e9Mm8HV'}], 'available_markets': ['AD', 'AE', 'AG', 'AL', 'AM', 'AO', 'AR', 'AT', 'AU', 'AZ', 'BA', 'BB', 'BD', 'BE', 'BF', 'BG', 'BH', 'BI', 'BJ', 'BN', 'BO', 'BR', 'BS', 'BT', 'BW', 'BY', 'BZ', 'CA', 'CH', 'CI', 'CL', 'CM', 'CO', 'CR', 'CV', 'CW', 'CY', 'CZ', 'DE', 'DJ', 'DK', 'DM', 'DO', 'DZ', 'EC', 'EE', 'EG', 'ES', 'FI', 'FJ', 'FM', 'FR', 'GA', 'GB', 'GD', 'GE', 'GH', 'GM', 'GN', 'GQ', 'GR', 'GT', 'GW', 'GY', 'HK', 'HN', 'HR', 'HT', 'HU', 'ID', 'IE', 'IL', 'IN', 'IS', 'IT', 'JM', 'JO', 'JP', 'KE', 'KG', 'KH', 'KI', 'KM', 'KN', 'KR', 'KW', 'KZ', 'LA', 'LB', 'LC', 'LI', 'LK', 'LR', 'LS', 'LT', 'LU', 'LV', 'MA', 'MC', 'MD', 'ME', 'MG', 'MH', 'MK', 'ML', 'MN', 'MO', 'MR', 'MT', 'MU', 'MV', 'MW', 'MX', 'MY', 'MZ', 'NA', 'NE', 'NG', 'NI', 'NL', 'NO', 'NP', 'NR', 'NZ', 'OM', 'PA', 'PE', 'PG', 'PH', 'PK', 'PL', 'PS', 'PT', 'PW', 'PY', 'QA', 'RO', 'RS', 'RU', 'RW', 'SA', 'SB', 'SC', 'SE', 'SG', 'SI', 'SK', 'SL', 'SM', 'SN', 'SR', 'ST', 'SV', 'SZ', 'TD', 'TG', 'TH', 'TL', 'TN', 'TO', 'TR', 'TT', 'TV', 'TW', 'TZ', 'UA', 'UG', 'US', 'UY', 'UZ', 'VC', 'VN', 'VU', 'WS', 'XK', 'ZA', 'ZM', 'ZW'], 'external_urls': {'spotify': 'https://open.spotify.com/album/1kM6xcSYO5ASJaWgygznL7'}, 'href': 'https://api.spotify.com/v1/albums/1kM6xcSYO5ASJaWgygznL7', 'id': '1kM6xcSYO5ASJaWgygznL7', 'images': [{'height': 640, 'url': 'https://i.scdn.co/image/ab67616d0000b27392d0747a634fcc351c6ac3c2', 'width': 640}, {'height': 300, 'url': 'https://i.scdn.co/image/ab67616d00001e0292d0747a634fcc351c6ac3c2', 'width': 300}, {'height': 64, 'url': 'https://i.scdn.co/image/ab67616d0000485192d0747a634fcc351c6ac3c2', 'width': 64}], 'name': 'Abba', 'release_date': '1975', 'release_date_precision': 'year', 'total_tracks': 13, 'type': 'album', 'uri': 'spotify:album:1kM6xcSYO5ASJaWgygznL7'}, 'artists': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/0LcJLqbBmaGUft1e9Mm8HV'}, 'href': 'https://api.spotify.com/v1/artists/0LcJLqbBmaGUft1e9Mm8HV', 'id': '0LcJLqbBmaGUft1e9Mm8HV', 'name': 'ABBA', 'type': 'artist', 'uri': 'spotify:artist:0LcJLqbBmaGUft1e9Mm8HV'}], 'available_markets': ['AD', 'AE', 'AG', 'AL', 'AM', 'AO', 'AR', 'AT', 'AU', 'AZ', 'BA', 'BB', 'BD', 'BE', 'BF', 'BG', 'BH', 'BI', 'BJ', 'BN', 'BO', 'BR', 'BS', 'BT', 'BW', 'BY', 'BZ', 'CA', 'CH', 'CI', 'CL', 'CM', 'CO', 'CR', 'CV', 'CW', 'CY', 'CZ', 'DE', 'DJ', 'DK', 'DM', 'DO', 'DZ', 'EC', 'EE', 'EG', 'ES', 'FI', 'FJ', 'FM', 'FR', 'GA', 'GB', 'GD', 'GE', 'GH', 'GM', 'GN', 'GQ', 'GR', 'GT', 'GW', 'GY', 'HK', 'HN', 'HR', 'HT', 'HU', 'ID', 'IE', 'IL', 'IN', 'IS', 'IT', 'JM', 'JO', 'JP', 'KE', 'KG', 'KH', 'KI', 'KM', 'KN', 'KR', 'KW', 'KZ', 'LA', 'LB', 'LC', 'LI', 'LK', 'LR', 'LS', 'LT', 'LU', 'LV', 'MA', 'MC', 'MD', 'ME', 'MG', 'MH', 'MK', 'ML', 'MN', 'MO', 'MR', 'MT', 'MU', 'MV', 'MW', 'MX', 'MY', 'MZ', 'NA', 'NE', 'NG', 'NI', 'NL', 'NO', 'NP', 'NR', 'NZ', 'OM', 'PA', 'PE', 'PG', 'PH', 'PK', 'PL', 'PS', 'PT', 'PW', 'PY', 'QA', 'RO', 'RS', 'RU', 'RW', 'SA', 'SB', 'SC', 'SE', 'SG', 'SI', 'SK', 'SL', 'SM', 'SN', 'SR', 'ST', 'SV', 'SZ', 'TD', 'TG', 'TH', 'TL', 'TN', 'TO', 'TR', 'TT', 'TV', 'TW', 'TZ', 'UA', 'UG', 'US', 'UY', 'UZ', 'VC', 'VN', 'VU', 'WS', 'XK', 'ZA', 'ZM', 'ZW'], 'disc_number': 1, 'duration_ms': 213266, 'explicit': False, 'external_ids': {'isrc': 'SEAYD7501010'}, 'external_urls': {'spotify': 'https://open.spotify.com/track/2TxCwUlqaOH3TIyJqGgR91'}, 'href': 'https://api.spotify.com/v1/tracks/2TxCwUlqaOH3TIyJqGgR91', 'id': '2TxCwUlqaOH3TIyJqGgR91', 'is_local': False, 'name': 'Mamma Mia', 'popularity': 75, 'preview_url': None, 'track_number': 1, 'type': 'track', 'uri': 'spotify:track:2TxCwUlqaOH3TIyJqGgR91'}], 'limit': 1, 'next': 'https://api.spotify.com/v1/search?query=mamma+mia&type=track&offset=1&limit=1', 'offset': 0, 'previous': None, 'total': 4686}}\n", + "This song is not in the top 100 but I've got another one for you\n" + ], + "name": "stdout" + }, + { + "output_type": "execute_result", + "data": { + "application/vnd.google.colaboratory.intrinsic+json": { + "type": "string" + }, + "text/plain": [ + "'Closer, by: Tegan and Sara'" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 36 + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "9PdU1zDf-R7O" + }, + "source": [ + "#try if cluster works the same\n", + "#spotify_billboard_short\n", + "#scaler = StandardScaler()\n", + "#scaler.fit(new)\n", + "#spotify_billboard_short_scaled = scaler.transform(spotify_billboard_short)\n", + "#spotify_billboard_short_df = pd.DataFrame(spotify_billboard_short_scaled, columns = spotify_billboard_short.columns)\n", + "# scaler.transform(user_song)" + ], + "execution_count": null, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "hqnv_KKEQibH" + }, + "source": [ + "#filtering all the title with the same cluster as the cluster of the inserted song\n", + "#all_scaled_df[all_scaled_df['cluster'] == int(list(all_scaled_df[\"cluster\"])[-1])]" + ], + "execution_count": 40, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "8mo4IuukW7qw" + }, + "source": [ + "#filtering all the title with the same cluster as the cluster of the inserted song, as list\n", + "#inter_df = all_scaled_df[all_scaled_df['cluster'] == (list(all_scaled_df[\"cluster\"])[-1])]\n", + "#list(inter_df[inter_df.index < 100].index)" + ], + "execution_count": 41, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "k1_VbqWedAFT" + }, + "source": [ + "#getting the optimal k elbow method\n", + "K = range(2, 60)\n", + "inertia = []\n", + "for k in K:\n", + " #print(\"Training a K-Means model with {} neighbours! \".format(k))\n", + " #print()\n", + " kmeans = KMeans(n_clusters=k,\n", + " random_state=1234)\n", + " kmeans.fit(all_scaled_df)\n", + " inertia.append(kmeans.inertia_)\n", + "import numpy as np\n", + "import matplotlib.pyplot as plt\n", + "%matplotlib inline\n", + "\n", + "#plt.figure(figsize=(16,8))\n", + "#plt.plot(K, inertia, 'bx-')\n", + "#plt.xlabel('k')\n", + "#plt.ylabel('inertia')\n", + "#plt.xticks(np.arange(min(K), max(K)+1, 1.0))\n", + "#plt.title('Elbow Method showing the optimal k')\n", + "#Getting the optimal k , silhouette mthod\n", + "import pickle\n", + "K = range(2, 60)\n", + "silhouette = []\n", + "\n", + "for k in K:\n", + " kmeans = KMeans(n_clusters=k,\n", + " random_state=1234)\n", + " kmeans.fit(all_scaled_df)\n", + " filename = \"/content/drive/MyDrive/kmeans1_\" + str(k) + \".pickle\"\n", + " with open(filename, \"wb\") as f:\n", + " pickle.dump(kmeans,f)\n", + " silhouette.append(silhouette_score(all_scaled_df, kmeans.predict(Four_scaled_df)))\n", + "\n", + "#plt.figure(figsize=(16,8))\n", + "#plt.plot(K, silhouette, 'bx-')\n", + "#plt.xlabel('k')\n", + "#plt.ylabel('silhouette score')\n", + "#plt.xticks(np.arange(min(K), max(K)+1, 1.0))\n", + "#plt.title('Silhouette Method showing the optimal k')" + ], + "execution_count": null, + "outputs": [] + } + ] +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..f4f5ad7 --- /dev/null +++ b/README.md @@ -0,0 +1,38 @@ + +# Project 1: Guess a number +*[Elina Neu]* + +*[Data Analytics,remote, 04.06.2021]* + +## Content +- [Project Description](#project-description) +- [Rules](#rules) +- [Workflow](#workflow) +- [Organization](#organization) +- [Links](#links) + +## Project Description +This project is intended to simulate the game "guess a number", in which the player has to guess a number from 1 to 100 within a limited number of attempts. For using the project the package "random" has been downloaded. +## Rules +The rules of the game include the following requirements: +1. The number the player will guess is within the range of 1-100 +2. The player has max. 7 tries to guess the number +3. The player must choose a number(not word) +## Workflow +1. Select game and research +2. Select steps in the game and structure code +3. Test code +4. Correct errors and finalise code + +## Organization +To organise myself, I used a kanban board, which helped me to get an overview of the individual tasks. +My repository contains my Jupiter notebook file, a .gitignore file and the read me file. + +## Links + +[Repository](http://localhost:8888/notebooks/Project1_Game.ipynb) +[Slides](https://drive.google.com/file/d/1hNRSgNtHJg3G3ms-diKEU_d0PRaD5KIW/view?usp=sharing) +[Trello](https://trello.com/b/pc8tH6HR/kanban-template) + + + diff --git a/your-project/README.md b/your-project/README.md deleted file mode 100644 index 2a8493d..0000000 --- a/your-project/README.md +++ /dev/null @@ -1,34 +0,0 @@ -Ironhack Logo - -# Title of Your Project -*[Your Name]* - -*[Your Cohort, Campus & Date]* - -## Content -- [Project Description](#project-description) -- [Rules](#rules) -- [Workflow](#workflow) -- [Organization](#organization) -- [Links](#links) - -## Project Description -Write a short description of your project. Write 1-2 sentences about the game you chose to build and why. - -## Rules -Briefly describe the rules of the game. - -## Workflow -Outline the workflow you used in your project. What are the steps you went through? - -## Organization -How did you organize your work? Did you use any tools like a kanban board? - -What does your repository look like? Explain your folder and file structure. - -## Links -Include links to your repository, slides and kanban board. Feel free to include any other links associated with your project. - -[Repository](https://github.com/) -[Slides](https://slides.com/) -[Trello](https://trello.com/en)