comment cleanup, put the windows line endings back and added the 2021 draws that were missing from the excel

This commit is contained in:
admin committed 2026-10-22 21:03:15 -04:00
1 parent d634159947
commit f4c4ee616d
11 files changed
+451 -467

No files matched your search

+70 -73
View File
@@ -1,73 +1,70 @@
# WVLottopy: Matteo DiBiagio
from fractions import Fraction as frac
from math import comb
import pandas as pd
import records
import requests
from collections import Counter
def get_data():
# Old records from the excel sheets, wvlottery.com took these down but they go back to the early 90s on some games
df_old = pd.read_excel('./excel_lotto_records/lotto_america.xlsx')
salvaged = df_old[['Date', 'Numbers', 'SB']]
url = 'https://gateway.loyalty.wvlottery.com/services/jackpot/api/v1/jackpot-results?gameId=16&jackpotStatus=PAYABLE&size=500&sort=externalId,drawDate,desc&page='
header = {
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.75 Safari/537.36",
}
# Get web data, the new site pulls past draws from json 500 at a time
web = {'Date': [], 'Numbers': [], 'SB': []}
page = 0
while True:
r = requests.get(url + str(page), headers=header)
data = r.json()
for x in data['content']:
web['Date'].append(records.draw_day(x))
web['Numbers'].append('–'.join(str(n['data']) for n in x['resultData'] if n['type'] == 'REGULAR'))
web['SB'].append([n['data'] for n in x['resultData'] if n['type'] == 'SPECIAL'][0])
if data['last']:
break
page += 1
dfs = [pd.DataFrame(web)]
pd.set_option('display.max_rows', None)
# Specifies no max rows, otherwise only shows 10 records
# Adds any draw not in the sheet yet, so the excel record keeps growing
df = records.merge_save('./excel_lotto_records/lotto_america.xlsx', dfs[0], fallback=salvaged)
df2 = df[['Date', 'Numbers', 'SB']]
date = list(df2['Date'])
nums = list(df2['Numbers'].astype('str'))
SBs = list(df2['SB'].astype('int'))
return date, nums, SBs
date, nums, SBs = get_data()
# Formatting
# Site numbers come split by – and the excel records by - so it splits on both
hyphenfree = []
for x in nums:
hyphenfree.append(x.replace('–',', ').replace('-',', '))
splitlist = ", ".join(hyphenfree)
sep = splitlist.split(", ")
# Only count numbers that can still be called, the ball ranges have changed over the years
# so the old records have some numbers that dont exist in the game anymore
sep = [x for x in sep if x.isdigit() and 1 <= int(x) <= 52]
SBs = [x for x in SBs if 1 <= x <= 10]
for n in range(0, 52):
most_common= Counter(sep).most_common(5)
likely_nums = [v[0] for v in most_common]
frequency = [v[-1] for v in most_common]
for n in range(0, 10):
most_common_sb = Counter(SBs).most_common(1)
SB = [v[0] for v in most_common_sb]
frequency_sb = [v[-1] for v in most_common_sb]
sorted_nums = sorted(likely_nums, key=lambda x: (len(x), x))
# Chance = 1 / every possible ticket, 52 choose 5 white balls times 10 star balls = 25989600
# every ticket has the same odds, the forecast just goes with the numbers that get called the most
Chance = frac(1, comb(52, 5) * 10)
Forecast = str(" - ".join(sorted_nums))
print(f"Likely numbers are . . . {Forecast} SB: {SB}\n"
f"With percent chance of winning being {Chance}")
# WVLottopy: Matteo DiBiagio
from fractions import Fraction as frac
from math import comb
import pandas as pd
import records
import requests
from collections import Counter
def get_data():
# previous records which have since been removed from wvlottery.com's database
df_old = pd.read_excel('./excel_lotto_records/lotto_america.xlsx')
salvaged = df_old[['Date', 'Numbers', 'SB']]
url = 'https://gateway.loyalty.wvlottery.com/services/jackpot/api/v1/jackpot-results?gameId=16&jackpotStatus=PAYABLE&size=500&sort=externalId,drawDate,desc&page='
header = {
"User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.75 Safari/537.36",
}
# Get web data, 500 draws a page
web = {'Date': [], 'Numbers': [], 'SB': []}
page = 0
while True:
r = requests.get(url + str(page), headers=header)
data = r.json()
for x in data['content']:
web['Date'].append(records.draw_day(x))
web['Numbers'].append('–'.join(str(n['data']) for n in x['resultData'] if n['type'] == 'REGULAR'))
web['SB'].append([n['data'] for n in x['resultData'] if n['type'] == 'SPECIAL'][0])
if data['last']:
break
page += 1
dfs = [pd.DataFrame(web)]
pd.set_option('display.max_rows', None)
# Specifies no max rows, otherwise only shows 10 records
# adds new draws to the excel so the records keep growing
df = records.merge_save('./excel_lotto_records/lotto_america.xlsx', dfs[0], fallback=salvaged)
df2 = df[['Date', 'Numbers', 'SB']]
date = list(df2['Date'])
nums = list(df2['Numbers'].astype('str'))
SBs = list(df2['SB'].astype('int'))
return date, nums, SBs
date, nums, SBs = get_data()
# Formatting
# site uses – and the excel uses -
hyphenfree = []
for x in nums:
hyphenfree.append(x.replace('–',', ').replace('-',', '))
splitlist = ", ".join(hyphenfree)
sep = splitlist.split(", ")
# ball range changed over the years so drop numbers that arent in the game anymore
sep = [x for x in sep if x.isdigit() and 1 <= int(x) <= 52]
SBs = [x for x in SBs if 1 <= x <= 10]
for n in range(0, 52):
most_common= Counter(sep).most_common(5)
likely_nums = [v[0] for v in most_common]
frequency = [v[-1] for v in most_common]
for n in range(0, 10):
most_common_sb = Counter(SBs).most_common(1)
SB = [v[0] for v in most_common_sb]
frequency_sb = [v[-1] for v in most_common_sb]
sorted_nums = sorted(likely_nums, key=lambda x: (len(x), x))
Chance = frac(1, comb(52, 5) * 10) # Chance = 1 / all possible tickets i.e. 25989600
Forecast = str(" - ".join(sorted_nums))
print(f"Likely numbers are . . . {Forecast} SB: {SB}\n"
f"With percent chance of winning being {Chance}")