-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sourcery refactored main branch #1
base: main
Are you sure you want to change the base?
Conversation
2352dea
to
447c88f
Compare
…ting different neural networks
447c88f
to
2adeac5
Compare
app/source/bets_handler.py
Outdated
else: | ||
if not bets_session.query(Bet).filter(and_(Bet.gamePk == game_pk, | ||
elif not bets_session.query(Bet).filter(and_(Bet.gamePk == game_pk, | ||
Bet.playerId == player_id, \ | ||
func.lower(Bet.site) == func.lower(bet[4]), \ | ||
func.lower(Bet.overUnder) == func.lower(str(bet[7]).replace(",", ".")) \ | ||
)).all(): | ||
try: | ||
new_bet = Bet() | ||
new_bet.playerId = player_id | ||
new_bet.homeTeamId = home_team | ||
new_bet.awayTeamId = away_team | ||
new_bet.dateTime = time | ||
new_bet.site = bet[4] | ||
new_bet.gamePk = game_pk | ||
new_bet.overUnder = str(bet[7]).replace(",", ".") | ||
new_bet.oddsOver = str(bet[5]).replace(",", ".") | ||
new_bet.oddsUnder = str(bet[6]).replace(",", ".") | ||
|
||
bets_session.add(new_bet) | ||
except: | ||
print("Something went wrong, did not add {}".format(bet)) | ||
else: | ||
print("Bet already exists") | ||
return | ||
try: | ||
new_bet = Bet() | ||
new_bet.playerId = player_id | ||
new_bet.homeTeamId = home_team | ||
new_bet.awayTeamId = away_team | ||
new_bet.dateTime = time | ||
new_bet.site = bet[4] | ||
new_bet.gamePk = game_pk | ||
new_bet.overUnder = str(bet[7]).replace(",", ".") | ||
new_bet.oddsOver = str(bet[5]).replace(",", ".") | ||
new_bet.oddsUnder = str(bet[6]).replace(",", ".") | ||
|
||
bets_session.add(new_bet) | ||
except: | ||
print("Something went wrong, did not add {}".format(bet)) | ||
else: | ||
print("Bet already exists") | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function add_bet_to_db
refactored with the following changes:
- Merge else clause's nested if statement into elif (
merge-else-if-into-elif
)
app/source/nhl_handler.py
Outdated
else: | ||
if "skaterStats" in player_info["stats"]: | ||
res_skater_stats = player_info["stats"]["skaterStats"] | ||
|
||
new_skater_stats = SkaterStats() | ||
|
||
new_skater_stats.playerId = player_info["person"]["id"] | ||
new_skater_stats.gamePk = info["gamePk"] | ||
new_skater_stats.position = player_info["position"]["code"] | ||
new_skater_stats.team = team_info["team"]["id"] | ||
|
||
new_skater_stats.timeOnIce = convert_string_to_time(res_skater_stats["timeOnIce"]) | ||
new_skater_stats.assists = res_skater_stats["assists"] | ||
new_skater_stats.goals = res_skater_stats["goals"] | ||
new_skater_stats.shots = res_skater_stats["shots"] | ||
new_skater_stats.hits = res_skater_stats["hits"] | ||
new_skater_stats.powerPlayGoals = res_skater_stats["powerPlayGoals"] | ||
new_skater_stats.powerPlayAssists = res_skater_stats["powerPlayAssists"] | ||
new_skater_stats.penaltyMinutes = res_skater_stats["penaltyMinutes"] | ||
new_skater_stats.faceOffWins = res_skater_stats["faceOffWins"] | ||
new_skater_stats.faceoffTaken = res_skater_stats["faceoffTaken"] | ||
new_skater_stats.takeaways = res_skater_stats["takeaways"] | ||
new_skater_stats.giveaways = res_skater_stats["giveaways"] | ||
new_skater_stats.shortHandedGoals = res_skater_stats["shortHandedGoals"] | ||
new_skater_stats.shortHandedAssists = res_skater_stats["shortHandedAssists"] | ||
new_skater_stats.blocked = res_skater_stats["blocked"] | ||
new_skater_stats.plusMinus = res_skater_stats["plusMinus"] | ||
new_skater_stats.evenTimeOnIce = convert_string_to_time(res_skater_stats["evenTimeOnIce"]) | ||
new_skater_stats.powerPlayTimeOnIce = convert_string_to_time(res_skater_stats["powerPlayTimeOnIce"]) | ||
new_skater_stats.shortHandedTimeOnIce = convert_string_to_time(res_skater_stats["shortHandedTimeOnIce"]) | ||
|
||
session.add(new_skater_stats) | ||
elif "skaterStats" in player_info["stats"]: | ||
res_skater_stats = player_info["stats"]["skaterStats"] | ||
|
||
new_skater_stats = SkaterStats() | ||
|
||
new_skater_stats.playerId = player_info["person"]["id"] | ||
new_skater_stats.gamePk = info["gamePk"] | ||
new_skater_stats.position = player_info["position"]["code"] | ||
new_skater_stats.team = team_info["team"]["id"] | ||
|
||
new_skater_stats.timeOnIce = convert_string_to_time(res_skater_stats["timeOnIce"]) | ||
new_skater_stats.assists = res_skater_stats["assists"] | ||
new_skater_stats.goals = res_skater_stats["goals"] | ||
new_skater_stats.shots = res_skater_stats["shots"] | ||
new_skater_stats.hits = res_skater_stats["hits"] | ||
new_skater_stats.powerPlayGoals = res_skater_stats["powerPlayGoals"] | ||
new_skater_stats.powerPlayAssists = res_skater_stats["powerPlayAssists"] | ||
new_skater_stats.penaltyMinutes = res_skater_stats["penaltyMinutes"] | ||
new_skater_stats.faceOffWins = res_skater_stats["faceOffWins"] | ||
new_skater_stats.faceoffTaken = res_skater_stats["faceoffTaken"] | ||
new_skater_stats.takeaways = res_skater_stats["takeaways"] | ||
new_skater_stats.giveaways = res_skater_stats["giveaways"] | ||
new_skater_stats.shortHandedGoals = res_skater_stats["shortHandedGoals"] | ||
new_skater_stats.shortHandedAssists = res_skater_stats["shortHandedAssists"] | ||
new_skater_stats.blocked = res_skater_stats["blocked"] | ||
new_skater_stats.plusMinus = res_skater_stats["plusMinus"] | ||
new_skater_stats.evenTimeOnIce = convert_string_to_time(res_skater_stats["evenTimeOnIce"]) | ||
new_skater_stats.powerPlayTimeOnIce = convert_string_to_time(res_skater_stats["powerPlayTimeOnIce"]) | ||
new_skater_stats.shortHandedTimeOnIce = convert_string_to_time(res_skater_stats["shortHandedTimeOnIce"]) | ||
|
||
session.add(new_skater_stats) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function hook_factory.add_game_stats_to_db
refactored with the following changes:
- Merge else clause's nested if statement into elif (
merge-else-if-into-elif
)
app/source/nhl_handler.py
Outdated
base = "https://statsapi.web.nhl.com/api/v1/game/" | ||
urls = [] | ||
|
||
games_that_dont_have_to_be_updated = {} | ||
games = session.query(Game).filter(Game.statusCode == 7) | ||
for game in games: | ||
games_that_dont_have_to_be_updated[game.gamePk] = game | ||
|
||
games_that_dont_have_to_be_updated = {game.gamePk: game for game in games} | ||
if "dates" in res: | ||
base = "https://statsapi.web.nhl.com/api/v1/game/" | ||
for date in res["dates"]: | ||
for game in date["games"]: | ||
if game["gameType"] == "R" or game["gameType"] == "P": | ||
if game["gamePk"] not in games_that_dont_have_to_be_updated.keys(): | ||
if session.query(Game).filter(Game.gamePk == game["gamePk"]).first(): | ||
remove_gamePk(session, game["gamePk"]) | ||
|
||
add_game_to_db(session, game) | ||
game_pk = game["gamePk"] | ||
urls.append((base + str(game_pk) + "/boxscore", { "session": session, "gamePk": str(game_pk), "stats" : {game["teams"]["home"]["team"]["id"]: {"wins": game["teams"]["home"]["leagueRecord"]["wins"], | ||
"losses": game["teams"]["home"]["leagueRecord"]["losses"], | ||
"ot": game["teams"]["home"]["leagueRecord"]["ot"] if "ot" in game["teams"]["home"]["leagueRecord"] else "", | ||
"type": game["teams"]["home"]["leagueRecord"]["type"], | ||
"score": game["teams"]["home"]["score"]}, | ||
game["teams"]["away"]["team"]["id"]: {"wins": game["teams"]["away"]["leagueRecord"]["wins"], | ||
"losses": game["teams"]["away"]["leagueRecord"]["losses"], | ||
"ot": game["teams"]["away"]["leagueRecord"]["ot"] if "ot" in game["teams"]["away"]["leagueRecord"] else "", | ||
"type": game["teams"]["away"]["leagueRecord"]["type"], | ||
"score": game["teams"]["away"]["score"]}}})) | ||
if ( | ||
game["gameType"] in ["R", "P"] | ||
and game["gamePk"] | ||
not in games_that_dont_have_to_be_updated.keys() | ||
): | ||
if session.query(Game).filter(Game.gamePk == game["gamePk"]).first(): | ||
remove_gamePk(session, game["gamePk"]) | ||
|
||
add_game_to_db(session, game) | ||
game_pk = game["gamePk"] | ||
urls.append((base + str(game_pk) + "/boxscore", { "session": session, "gamePk": str(game_pk), "stats" : {game["teams"]["home"]["team"]["id"]: {"wins": game["teams"]["home"]["leagueRecord"]["wins"], | ||
"losses": game["teams"]["home"]["leagueRecord"]["losses"], | ||
"ot": game["teams"]["home"]["leagueRecord"]["ot"] if "ot" in game["teams"]["home"]["leagueRecord"] else "", | ||
"type": game["teams"]["home"]["leagueRecord"]["type"], | ||
"score": game["teams"]["home"]["score"]}, | ||
game["teams"]["away"]["team"]["id"]: {"wins": game["teams"]["away"]["leagueRecord"]["wins"], | ||
"losses": game["teams"]["away"]["leagueRecord"]["losses"], | ||
"ot": game["teams"]["away"]["leagueRecord"]["ot"] if "ot" in game["teams"]["away"]["leagueRecord"] else "", | ||
"type": game["teams"]["away"]["leagueRecord"]["type"], | ||
"score": game["teams"]["away"]["score"]}}})) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function fill_all_games_from_season
refactored with the following changes:
- Merge nested if conditions (
merge-nested-ifs
) - Replace multiple comparisons of same variable with
in
operator (merge-comparisons
) - Convert for loop into dictionary comprehension (
dict-comprehension
) - Move assignments closer to their usage (
move-assign
)
app/source/nhl_handler.py
Outdated
print(nhl_session.query(Person).filter( | ||
func.lower(Person.fullName).contains(func.lower(name)))) | ||
raise "More than one id..." | ||
|
||
if len(ids) == 0: | ||
print("Cant find a player with that name for:") | ||
print(name) | ||
return | ||
print(nhl_session.query(Person).filter( | ||
func.lower(Person.fullName).contains(func.lower(name)))) | ||
raise "Cant find a player with that name..." | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function add_person_nickname
refactored with the following changes:
- Remove unreachable code (
remove-unreachable-code
)
app/source/nhl_handler.py
Outdated
raise "More than one id..." | ||
|
||
if len(ids) == 0: | ||
print("Cant find a team with that name for:") | ||
print(name) | ||
print(nhl_session.query(Team).filter(func.lower(Team.name).contains(func.lower(name)))) | ||
return | ||
raise "Cant find a team with that name..." | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function add_team_nickname
refactored with the following changes:
- Remove unreachable code (
remove-unreachable-code
)
res = [] | ||
for i in range(len(tmp)): | ||
if tmp[i] == find: | ||
res.append(i) | ||
|
||
res = [i for i in range(len(tmp)) if tmp[i] == find] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function read_file
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
) - Use items() to directly unpack dictionary values (
use-dict-items
) - Convert for loop into list comprehension (
list-comprehension
) - Use str.join() instead of for loop (
use-join
)
for match in matches: | ||
for match, value in matches.items(): | ||
home_team = unidecode(match.split(" @ ")[1]) | ||
away_team = unidecode(match.split(" @ ")[0]) | ||
for i in range(0, len(matches[match]), 4): | ||
for i in range(0, len(value), 4): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function read_file
refactored with the following changes:
- Use items() to directly unpack dictionary values (
use-dict-items
)
app/source/bet_parsers/parse_ss.py
Outdated
for match in matches: | ||
for match, value in matches.items(): | ||
home_team = unidecode(match.split(" - ")[0]) | ||
away_team = unidecode(match.split(" - ")[1]) | ||
for i in range(0, len(matches[match]), 3): | ||
for i in range(0, len(value), 3): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function read_file
refactored with the following changes:
- Use items() to directly unpack dictionary values (
use-dict-items
)
for match in matches: | ||
for match, value in matches.items(): | ||
home_team = unidecode(match.split(" - ")[0]) | ||
away_team = unidecode(match.split(" - ")[1]) | ||
for i in range(0, len(matches[match]), 5): | ||
for i in range(0, len(value), 5): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function read_file
refactored with the following changes:
- Use items() to directly unpack dictionary values (
use-dict-items
)
app/source/bet_parsers/parse_wh.py
Outdated
for match in matches: | ||
for match, value in matches.items(): | ||
home_team = unidecode(match.split(" - ")[0]) | ||
away_team = unidecode(match.split(" - ")[1]) | ||
for i in range(0, len(matches[match]), 5): | ||
for i in range(0, len(value), 5): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function read_file
refactored with the following changes:
- Use items() to directly unpack dictionary values (
use-dict-items
)
Sourcery Code Quality Report✅ Merging this PR will increase code quality in the affected files by 0.95%.
Here are some functions in these files that still need a tune-up:
Legend and ExplanationThe emojis denote the absolute quality of the code:
The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request. Please see our documentation here for details on how these metrics are calculated. We are actively working on this report - lots more documentation and extra metrics to come! Help us improve this quality report! |
Branch
main
refactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
main
branch, then run:Help us improve this pull request!