Skip to content

Instantly share code, notes, and snippets.

@johnathaningle
Created June 10, 2021 20:44
Show Gist options
  • Save johnathaningle/6c88507f8d801ecfc0168318bb530e99 to your computer and use it in GitHub Desktop.
Save johnathaningle/6c88507f8d801ecfc0168318bb530e99 to your computer and use it in GitHub Desktop.
SDEV 400 Week 6 Project Code
import json
#sources:
#https://www.fiaformulae.com/en/results/race-results/?championship=2022019&race=20190208
#https://www.motogp.com/en/Results+Statistics
#https://www.formula1.com/en/results.html/2020/races.html
motorsport_data = {
"f1": {
"mercedes": {
"valtteri bottas": [
"P1: ROLEX GROSSER PREIS VON ÖSTERREICH - 2020",
"P2: PIRELLI GROSSER PREIS DER STEIERMARK - 2020",
"P3: ARAMCO MAGYAR NAGYDÍJ - 2020",
"P11: PIRELLI BRITISH GRAND PRIX - 2020"
]
},
"redbull": {
"max verstappen": [
"NC: ROLEX GROSSER PREIS VON ÖSTERREICH 2020 - 2020",
"P3: PIRELLI GROSSER PREIS DER STEIERMARK - 2020",
"P2: ARAMCO MAGYAR NAGYDÍJ - 2020",
"P2: PIRELLI BRITISH GRAND PRIX - 2020",
]
},
"ferrari": {
"charles leclerc": [
"P2: ROLEX GROSSER PREIS VON ÖSTERREICH 2020 - 2020",
"NC: PIRELLI GROSSER PREIS DER STEIERMARK - 2020",
"P11: ARAMCO MAGYAR NAGYDÍJ - 2020",
"P3: PIRELLI BRITISH GRAND PRIX - 2020",
]
},
},
"motogp": {
"suzuki": {
"joan mir": [
"P4: BARWA GRAND PRIX OF QATAR - 2021",
"P7: TISSOT GRAND PRIX OF DOHA - 2021",
"P3: GRANDE PRÉMIO 888 DE PORTUGAL - 2021",
"P5: GRAN PREMIO RED BULL DE ESPAÑA - 2021",
]
},
"yamaha": {
"fabio quartararo": [
"P1: BARWA GRAND PRIX OF QATAR - 2021",
"P1: TISSOT GRAND PRIX OF DOHA - 2021",
"P1: GRANDE PRÉMIO 888 DE PORTUGAL - 2021",
"P13: GRAN PREMIO RED BULL DE ESPAÑA - 2021",
]
},
"ducati": {
"francesco bagnaia": [
"P3: BARWA GRAND PRIX OF QATAR - 2021",
"P6: TISSOT GRAND PRIX OF DOHA - 2021",
"P1: GRANDE PRÉMIO 888 DE PORTUGAL - 2021",
"P2: GRAN PREMIO RED BULL DE ESPAÑA - 2021",
]
}
},
"formulae": {
"nissan": {
"sébastien buemi": [
"P3: Mexico City - 2020",
"P7: Berlin R6 - 2020",
"P2: Berlin R7 - 2020",
"P11: Berlin R8 - 2020",
]
},
"jaguar": {
"mitch evans": [
"P1: Mexico City - 2020",
"P13: Berlin R6 - 2020",
"P12: Berlin R7 - 2020",
"P9: Berlin R8 - 2020",
]
},
"bmw": {
"alexander: sims": [
"P5: Mexico City - 2020",
"P9: Berlin R6 - 2020",
"P19: Berlin R7 - 2020",
"P10: Berlin R8 - 2020",
]
},
}
}
def lambda_handler(event, context):
sport: str = event.get("sport")
if sport is None:
return get_invalid_sport_response()
team: str = event.get("team")
if team is None:
return get_invalid_team_response(sport)
return get_motorsports_data(sport, team)
def get_invalid_team_response(sport: str):
message = "The team was not found. "
if sport is not None:
team_data = motorsport_data[sport]
teams = list(team_data.keys())
message += "Valid teams: "
message += ", ".join(teams)
return {
"message": message
}
def get_invalid_sport_response():
sports = list(motorsport_data.keys())
return {
"message": "The sport was not found. Valid sports: " + ", ".join(sports)
}
def get_motorsports_data(sport: str, team: str):
message = f"For the sport {sport}, the {team} team had the following scores"
sport = sport.lower()
team = team.lower()
sports_data = motorsport_data.get(sport)
if sports_data is None:
return get_invalid_sport_response()
team_data = sports_data.get(team)
if team_data is None:
return get_invalid_team_response(sport)
return {
message: team_data
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment