Merge additional changes from laptop
This commit is contained in:
commit
6980f6d860
5 files changed
+64
-14
No files matched your search
@@ -6,15 +6,18 @@ from sqlalchemy import select
|
||||
|
||||
from data.database import Base, dal, project_variables
|
||||
import util.drawing as drawutil
|
||||
import util.environment as envutil
|
||||
|
||||
project_variables = envutil.load_environment_variables()
|
||||
|
||||
|
||||
def load_dataframe(
|
||||
table_name: str, start_date: datetime | None = None, end_date: datetime | None = None
|
||||
) -> pd.DataFrame:
|
||||
"""connect to the database and load game data into a pandas dataframe"""
|
||||
"""
|
||||
:param table_name: the name of the table to load data from
|
||||
:param start_date: the start date for the data
|
||||
:param end_date: the end date for the data
|
||||
|
||||
:returns: a pandas DataFrame containing the data
|
||||
"""
|
||||
|
||||
dal.connect()
|
||||
session = dal.Session()
|
||||
@@ -39,10 +42,15 @@ def load_dataframe(
|
||||
|
||||
|
||||
def get_most_common_number(
|
||||
data_frame: pd.DataFrame,
|
||||
columns: list | None = None,
|
||||
top: int = 1
|
||||
data_frame: pd.DataFrame, columns: list | None = None, top: int = 1
|
||||
) -> list[int]:
|
||||
"""
|
||||
:param data_frame: a pandas DataFrame containing the data
|
||||
:param columns: a list of column names to use
|
||||
:param top: the number of top (most seen) numbers to return
|
||||
|
||||
:returns: a list of the most common numbers
|
||||
"""
|
||||
if columns is None:
|
||||
columns = ['main_ball1', 'main_ball2', 'main_ball3', 'main_ball4', 'main_ball5']
|
||||
flat_numbers = data_frame[columns].values.flatten()
|
||||
@@ -51,10 +59,15 @@ def get_most_common_number(
|
||||
|
||||
|
||||
def get_least_common_number(
|
||||
data_frame: pd.DataFrame,
|
||||
columns: list | None = None,
|
||||
bottom: int = 1
|
||||
data_frame: pd.DataFrame, columns: list | None = None, bottom: int = 1
|
||||
) -> list[int]:
|
||||
"""
|
||||
:param data_frame: a pandas DataFrame containing the data
|
||||
:param columns: a list of column names to use
|
||||
:param bottom: the number of bottom (least seen) numbers to return
|
||||
|
||||
:returns: a list of the least common numbers
|
||||
"""
|
||||
if columns is None:
|
||||
columns = ['main_ball1', 'main_ball2', 'main_ball3', 'main_ball4', 'main_ball5']
|
||||
flat_numbers = data_frame[columns].values.flatten()
|
||||
|
||||
@@ -18,7 +18,11 @@ project_variables = envutil.load_environment_variables()
|
||||
|
||||
|
||||
def get_record_count(table_name: str) -> int | None:
|
||||
"""get the most recent draw record from the specified table"""
|
||||
"""
|
||||
:param table_name: the name of the table to get a count of records from
|
||||
|
||||
:returns: the count of records found in the specified table
|
||||
"""
|
||||
game_dict = drawutil.check_table_name(table_name=table_name)
|
||||
if game_dict:
|
||||
dal.connect()
|
||||
@@ -30,7 +34,11 @@ def get_record_count(table_name: str) -> int | None:
|
||||
|
||||
|
||||
def get_recent_draw_date(table_name: str) -> datetime | None:
|
||||
"""get the most recent draw date from the specified table"""
|
||||
"""
|
||||
:param table_name: the name of the table to get the most recent draw date from
|
||||
|
||||
:returns datetime: the most recent draw date, if there is one
|
||||
"""
|
||||
game_dict = drawutil.check_table_name(table_name=table_name)
|
||||
if game_dict:
|
||||
dal.connect()
|
||||
@@ -42,7 +50,11 @@ def get_recent_draw_date(table_name: str) -> datetime | None:
|
||||
|
||||
|
||||
def get_missing_records(table_name: str) -> int:
|
||||
"""collect and insert missing records, returning a count of insertions"""
|
||||
"""
|
||||
:param table_name: the name of the table to collect and insert missing records in
|
||||
|
||||
:returns: the number of records inserted into the target table
|
||||
"""
|
||||
# if the table_name is valid
|
||||
game_dict = drawutil.check_table_name(table_name=table_name)
|
||||
if game_dict:
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import random
|
||||
|
||||
|
||||
def generate_random_ticket(max_main: int, max_game: int, num_main: int = 5) -> tuple[list[int], int]:
|
||||
"""
|
||||
Generate a random lottery ticket.
|
||||
|
||||
:param max_main: The maximum number in the range to choose from for main game balls
|
||||
:param max_game: The maximum number in the range to choose from for the game ball
|
||||
:param num_main: The number of numbers that can be chosen in the main field
|
||||
|
||||
:returns: A tuple of (main_balls, game_ball)
|
||||
"""
|
||||
main_balls = random.sample(range(1, max_main), num_main)
|
||||
game_ball = random.randint(1, max_game)
|
||||
return sorted(main_balls), game_ball
|
||||
@@ -1,6 +1,5 @@
|
||||
from datetime import datetime
|
||||
import pytest
|
||||
import pandas as pd
|
||||
|
||||
import lottery_predictor.analyze as analyze
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import pytest
|
||||
|
||||
import lottery_predictor.draw as draw
|
||||
|
||||
|
||||
def test_generate_random_ticket() -> None:
|
||||
assert isinstance(draw.generate_random_ticket(max_main=69, max_game=26), tuple)
|
||||
assert isinstance(draw.generate_random_ticket(max_main=70, max_game=24), tuple)
|
||||
with pytest.raises(TypeError):
|
||||
draw.generate_random_ticket()
|
||||
Reference in new issue
Block a user