From 98e375682a50f3cdeddc8e6af022d1e8d12f608d Mon Sep 17 00:00:00 2001 From: Rasmus Luha Date: Thu, 17 Mar 2022 13:48:15 +0200 Subject: file name fixes --- API/main.py | 13 ------------- API/routers/get.py | 52 ------------------------------------------------- API/utils.py | 18 ----------------- api/__init__.py | 0 api/main.py | 13 +++++++++++++ api/routers/__init__.py | 0 api/routers/get.py | 52 +++++++++++++++++++++++++++++++++++++++++++++++++ api/utils.py | 18 +++++++++++++++++ 8 files changed, 83 insertions(+), 83 deletions(-) delete mode 100644 API/main.py delete mode 100644 API/routers/get.py delete mode 100644 API/utils.py create mode 100644 api/__init__.py create mode 100644 api/main.py create mode 100644 api/routers/__init__.py create mode 100644 api/routers/get.py create mode 100644 api/utils.py diff --git a/API/main.py b/API/main.py deleted file mode 100644 index 8068243..0000000 --- a/API/main.py +++ /dev/null @@ -1,13 +0,0 @@ -from fastapi import FastAPI -from routers import get -import pandas as pd - -app = FastAPI() - -#CORS STUFF HERE - -app.include_router(get.router) - -@app.get("/", tags=["Index"]) -def getIndex(): - return {"Message": "Hello! add /docs for documentation"} diff --git a/API/routers/get.py b/API/routers/get.py deleted file mode 100644 index 031b469..0000000 --- a/API/routers/get.py +++ /dev/null @@ -1,52 +0,0 @@ -from fastapi import FastAPI, APIRouter -import numpy as np -import pandas as pd -import sys - -sys.path.append("..") -import utils - -router = APIRouter(tags=["Get requests"]) - -@router.get("/teams") -def getTeams(): - - # Getting the data from csv files and then converting into dict to be send out on get request - teamsDf = pd.read_csv(utils.relPathTeams).to_dict() - - teams_dict = {} - for el in range(len(teamsDf["name"])): - teams_dict.update({el+1 : - {"Abbreviation" : teamsDf["abbreviation"][el], - "Name" : teamsDf["name"][el], - "FullName" : teamsDf["full_name"][el], - "City" : teamsDf["city"][el], - "Conference" : teamsDf["conference"][el], - "Division" : teamsDf["division"][el]} }) - return teams_dict - - -@router.get("/players/{team_name}") -def getPlayers(team_name: str): - - teamNames = utils.getTeamNames() - team_name = team_name.capitalize() # Capitalizing in case url is given as lowercase - if team_name in teamNames.keys(): - - playersDf = pd.read_csv(utils.relPathPlayers+teamNames[team_name]+".csv") - playersDf = playersDf.replace({np.nan:None}) # For Json Nan must be replaced - - players_dict = {} - for el in range(len(playersDf["first_name"])): - players_dict.update({el+1 : - {"first_name" : playersDf["first_name"][el], - "last_name" : playersDf["last_name"][el], - "position" : playersDf["position"][el], - "height_feet" : playersDf["height_feet"][el], - "height_inches" : playersDf["height_inches"][el]} }) - - - return players_dict - else: - return {"Error 404" : "Team name Not Found"} - diff --git a/API/utils.py b/API/utils.py deleted file mode 100644 index c04bdf1..0000000 --- a/API/utils.py +++ /dev/null @@ -1,18 +0,0 @@ -import pandas as pd - -# Making relative paths. On windows slashes would be backwards -# It is probably not the best way. -relPathTeams = "../AllAboutData/Data/NBAteams.csv" -relPathPlayers = "../AllAboutData/Data/Players/" - -def getTeamNames(): - ''' - Returns dictionary with fetched teams' names as keys - and full_names as values. - ''' - - teamsDf = pd.read_csv(relPathTeams).to_dict() - team_names = {} - for el in range(len(teamsDf["name"])): - team_names.update({teamsDf["name"][el] : teamsDf["full_name"][el]}) - return team_names diff --git a/api/__init__.py b/api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/api/main.py b/api/main.py new file mode 100644 index 0000000..8068243 --- /dev/null +++ b/api/main.py @@ -0,0 +1,13 @@ +from fastapi import FastAPI +from routers import get +import pandas as pd + +app = FastAPI() + +#CORS STUFF HERE + +app.include_router(get.router) + +@app.get("/", tags=["Index"]) +def getIndex(): + return {"Message": "Hello! add /docs for documentation"} diff --git a/api/routers/__init__.py b/api/routers/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/api/routers/get.py b/api/routers/get.py new file mode 100644 index 0000000..bbbd26d --- /dev/null +++ b/api/routers/get.py @@ -0,0 +1,52 @@ +from fastapi import FastAPI, APIRouter +import numpy as np +import pandas as pd +import sys + +#sys.path.append("/home/rasmus/Proge/STACC/api") +from .. import utils + +router = APIRouter(tags=["Get requests"]) + +@router.get("/teams") +def getTeams(): + + # Getting the data from csv files and then converting into dict to be send out on get request + teamsDf = pd.read_csv(utils.relPathTeams).to_dict() + + teams_dict = {} + for el in range(len(teamsDf["name"])): + teams_dict.update({el+1 : + {"Abbreviation" : teamsDf["abbreviation"][el], + "Name" : teamsDf["name"][el], + "FullName" : teamsDf["full_name"][el], + "City" : teamsDf["city"][el], + "Conference" : teamsDf["conference"][el], + "Division" : teamsDf["division"][el]} }) + return teams_dict + + +@router.get("/players/{team_name}") +def getPlayers(team_name: str): + + teamNames = utils.getTeamNames() + team_name = team_name.capitalize() # Capitalizing in case url is given as lowercase + if team_name in teamNames.keys(): + + playersDf = pd.read_csv(utils.relPathPlayers+teamNames[team_name]+".csv") + playersDf = playersDf.replace({np.nan:None}) # For Json Nan must be replaced + + players_dict = {} + for el in range(len(playersDf["first_name"])): + players_dict.update({el+1 : + {"first_name" : playersDf["first_name"][el], + "last_name" : playersDf["last_name"][el], + "position" : playersDf["position"][el], + "height_feet" : playersDf["height_feet"][el], + "height_inches" : playersDf["height_inches"][el]} }) + + + return players_dict + else: + return {"Error 404" : "Team name Not Found"} + diff --git a/api/utils.py b/api/utils.py new file mode 100644 index 0000000..c04bdf1 --- /dev/null +++ b/api/utils.py @@ -0,0 +1,18 @@ +import pandas as pd + +# Making relative paths. On windows slashes would be backwards +# It is probably not the best way. +relPathTeams = "../AllAboutData/Data/NBAteams.csv" +relPathPlayers = "../AllAboutData/Data/Players/" + +def getTeamNames(): + ''' + Returns dictionary with fetched teams' names as keys + and full_names as values. + ''' + + teamsDf = pd.read_csv(relPathTeams).to_dict() + team_names = {} + for el in range(len(teamsDf["name"])): + team_names.update({teamsDf["name"][el] : teamsDf["full_name"][el]}) + return team_names -- cgit v1.2.3