Adding points check and fixing some minor other issues

This commit is contained in:
LaDfBC
2020-12-20 10:11:09 -06:00
parent caa0819d91
commit f592bb8234
8 changed files with 203 additions and 69 deletions

View File

@@ -3,6 +3,7 @@ from copy import deepcopy
from src.main.database_module.database_classes.db_classes import Guess
from src.main.db_session import DatabaseSession
MEMBER_ID = 'member_id'
PLAY_ID = 'play_id'
GUESSED_NUMBER = 'guessed_number'
@@ -15,11 +16,13 @@ class GuessDAO():
Session = None
engine = None
_database_session = None
def __init__(self):
pass
self._database_session = DatabaseSession()
def insert(self, guess_info):
session = DatabaseSession.session
session = self._database_session.get_or_create_session()
guess = Guess(
member_id=guess_info[MEMBER_ID],
@@ -55,7 +58,7 @@ class GuessDAO():
return converted_games
def set_differences(self, pitch_value, play_id):
session = DatabaseSession.session
session = self._database_session.get_or_create_session()
games_to_update = self.__convert_all__(session.query(Guess).filter(Guess.play_id == play_id))
for game in games_to_update:
@@ -74,7 +77,7 @@ class GuessDAO():
return possible_value
def fetch_closest(self, num_to_fetch):
session = DatabaseSession.session
session = self._database_session.get_or_create_session()
return self.__convert_all__(
session\
@@ -83,8 +86,19 @@ class GuessDAO():
.limit(num_to_fetch)
)
def refresh(self):
self._database_session.__create_new_session__() # I know, I know. It's fine.
def get_all_guesses_for_plays(self, play_ids):
session = self._database_session.get_or_create_session()
return self.__convert_all__(
session
.query(Guess)
.filter(Guess.play_id.in_(play_ids))
)
def get_closest_on_play(self, play):
session = DatabaseSession.session
session = self._database_session.get_or_create_session()
# TODO: Make this a MAX query for ties
converted_guesses = self.__convert_all__(