File size: 10,355 Bytes
b0be684
99b268c
 
 
 
2192e30
 
 
 
 
99b268c
 
 
2192e30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99b268c
 
 
 
2192e30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99b268c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cde26fc
2192e30
99b268c
2192e30
1e0905f
99b268c
 
 
2192e30
99b268c
 
 
 
 
 
2192e30
 
 
99b268c
 
 
 
 
 
2192e30
 
 
 
 
99b268c
 
 
 
 
2192e30
 
 
99b268c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2192e30
99b268c
 
 
 
 
2192e30
99b268c
 
 
 
 
 
2192e30
 
99b268c
 
2192e30
99b268c
 
 
 
 
 
 
 
 
 
 
 
 
2192e30
 
99b268c
2192e30
99b268c
 
 
 
 
 
 
 
 
 
 
 
 
2192e30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
99b268c
2192e30
 
 
 
 
 
 
 
 
 
 
 
 
99b268c
2192e30
 
99b268c
 
 
 
 
b0be684
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
import streamlit as st
import pandas as pd
from gimme5_predictor import generate_gimme5_prediction
from la_predictor import generate_la_prediction, la_predict_star_ball
from mb_predictor import generate_mb_prediction, mb_predict_star_ball
from mm_predictor import generate_mm_prediction, mm_predict_star_ball
from pb_predictor import generate_pb_prediction, pb_predict_star_ball

from pb_predictor import clean_powerball_df

from gimme5_predictor import get_hot_and_cold_numbers as g5_get_hot
from la_predictor import get_hot_and_cold_numbers as la_get_hot 
from mb_predictor import get_hot_and_cold_numbers as mb_get_hot
from mm_predictor import get_hot_and_cold_numbers as mm_get_hot
from pb_predictor import get_hot_and_cold_numbers as pb_get_hot

def display_wheel_table(hot_df, cold_df):
    """
    10 hot + 10 cold sayıdan oluşan wheel havuzunu tablo olarak gösterir.
    """
    hot_numbers  = [int(n) for n, _ in hot_df.values]
    cold_numbers = [int(n) for n, _ in cold_df.values]
    wheel_numbers = sorted(hot_numbers + cold_numbers)
    
    if len(wheel_numbers) == 20:
        wheel_labels = list("ABCDEFGHIJKLMNOPQRST")
        wheel_df = pd.DataFrame([wheel_numbers], columns=wheel_labels)
        # Comment out
        # with st.expander("🎡 Your 20 Numbers to Wheel"):
        #     st.table(wheel_df.style.hide(axis="index"))

def display_hot_cold_tables(hot_df, cold_df):
    """
    Var olan hot_df ve cold_df tablolarını düzgünce gösterir.
    """

    hot_df.index = range(1, len(hot_df)+1)
    hot_df.index.name = 'No'
    cold_df.index = range(1, len(cold_df)+1)
    cold_df.index.name = 'No'

    with st.expander("🔥 Hot Numbers (Top 10)"):
        st.table(hot_df)

    with st.expander("❄️ Cold Numbers (Bottom 10)"):
        st.table(cold_df)


st.set_page_config(page_title="Multi Lotto AI Engine", layout="centered")

st.title("🎯 Lotto AI Engine (V1.3)")

with st.expander("🛠️ Requirements (click to view)"):
    st.markdown("""
1- powerball (pb) and megamillions (mm) game will be added. they also 
    should have sum_range.   
    **pb = 65 - 265**  
    **mm = 75 - 280**
    
2- their regular numbers:  
                **pb = 1-69**  
                **mm = 1-70** 
                   
their powerball:   
                **pb = 1-26**  
                **mm = 1-24**

3- a wheel will be added. it will contain 10 hot and 10 cold numbers. 
so it will be 20 numbers. it will be sorted. and later by using txt
file which Randy provided to us, it will return 76 ticket combinations. 
                                 
                """)        

with st.expander("🛠️ App Features (click to view)"):
    st.markdown("""
This app generates predictions based on past drawing data and client-specified rules:

**1- Machine Learning Backbone:**
The prediction engine is powered by a lightweight Random Forest 
algorithm trained on historical draw results. The model takes into 
account not only number frequencies but also the day of the week on 
which each draw occurred — recognizing patterns tied to specific 
weekdays. To maintain prediction accuracy, it is important to keep the 
CSV data files updated with the latest draw results, as the model adapts 
to evolving trends over time.   
                        
**2- Recent Draw Awareness:** Includes 1 number from the most recent draw 
    — selected based on its historical recurrence. (Occasionally 
    replaced to maintain parity balance.) 
                     
**3- Parity Balance Enforcement:** Every combination ensures either 
    2 even + 3 odd or 3 even + 2 odd numbers — avoiding rare, 
    statistically weak patterns.  
                
**4- Sequential Pair Logic:** If enabled, the model guarantees at least 
    one pair of consecutive numbers in the prediction. However, even 
    when this option is disabled, such sequences may still appear by 
    chance — as they are statistically common in lottery draws. 
                 
**5- Weighted Frequency System:** Numbers are chosen based on long-term 
    frequency, with extra emphasis on trends from the last 30 days.           

**6- Total Sum Range Enforcement:**
Each predicted combination must fall within a predefined total 
sum range — based on statistical analysis of past results.

Gimme5: total must be between 40–160  
LA (Lotto America): total must be between 70–210  
MB (Megabucks): total must be between 45–165  

This rule helps eliminate outlier combinations with abnormally low or 
high totals, which historically have a lower likelihood of being drawn. 
If a generated set falls outside the allowed range, the system 
regenerates a new one until the condition is satisfied.                

**7- Fortuna favet ludens, qui non ludit, non vincit, In ludo est spes**               

""")


lotto_type = st.selectbox(
    "Select Lotto Type:",
    options=["LA (Lotto America)", "MB (Megabucks)", "G5 (Gimme 5)", "MM (Mega Millions)", "PB (Powerball)"],
    index=0
)

DATA_PATHS = {
    "G5 (Gimme 5)": "data/gimme5_results.csv",
    "LA (Lotto America)": "data/la_results.csv",
    "MB (Megabucks)": "data/mb_results.csv",
    "MM (Mega Millions)": "data/mm_results.csv",
    "PB (Powerball)": "data/pb_results.csv"
}


g5_df = pd.read_csv(DATA_PATHS["G5 (Gimme 5)"])
la_df = pd.read_csv(DATA_PATHS["LA (Lotto America)"])
mb_df = pd.read_csv(DATA_PATHS["MB (Megabucks)"])
mm_df = pd.read_csv(DATA_PATHS["MM (Mega Millions)"])

#POWERBALL SPECIAL CLEANING
raw = pd.read_csv(DATA_PATHS["PB (Powerball)"])
pb_df = clean_powerball_df(raw) #DELETE ROWS WHICH CONTAINS "DOUBLE PLAY"

#WE CALCULATE HOT-COLD NUMBERS HERE
hot_g5, cold_g5 = g5_get_hot(g5_df)
hot_la, cold_la = la_get_hot(la_df)
hot_mb, cold_mb = mb_get_hot(mb_df)
hot_mm, cold_mm = mm_get_hot(mm_df)
hot_pb, cold_pb = pb_get_hot(pb_df)


try:
    data_path = DATA_PATHS[lotto_type]

    # For the table layout
    st.markdown("""
    <style>
    table {
        margin-left: auto;
        margin-right: auto;
    }
    th, td {
        text-align: center !important;
        vertical-align: middle !important;
    }
    </style>
    """, unsafe_allow_html=True)

    #GIMME5
    if lotto_type == "G5 (Gimme 5)":
        use_sequence = st.checkbox("🔗 Include Sequential Numbers", value=False)
        if st.button("🎰 Generate Prediction"):
            result = generate_gimme5_prediction(g5_df, allow_sequences=use_sequence)
            st.success(f"🧠 Predicted Numbers: {result}")
            st.success("ℹ️ No Additional Number for Gimme5")
            st.info(f"🔢 Total Sum of Picks: {sum(result)}")

            #HOT-COLD NUMBERS
            hot_df = pd.DataFrame(hot_g5, columns=["Number", "Frequency"])
            cold_df = pd.DataFrame(cold_g5, columns=["Number", "Frequency"])

            display_hot_cold_tables(hot_df, cold_df)
            display_wheel_table(hot_df, cold_df)


    #LOTTO AMERICA 
    elif lotto_type == "LA (Lotto America)":
        use_sequence = st.checkbox("🔗 Include Sequential Numbers", value=False)
        if st.button("🎰 Generate Prediction"):
            main_numbers = generate_la_prediction(la_df, allow_sequences=use_sequence)
            star_ball = la_predict_star_ball(la_df)
            st.success(f"🧠 Predicted Numbers: {main_numbers}")
            st.success(f"🌟 Predicted Star Ball: [{star_ball}]")
            st.info(f"🔢 Total Sum of Picks: {sum(main_numbers)}")

            #HOT AND COLD NUMBERS
            hot_df = pd.DataFrame(hot_la, columns=["Number", "Frequency"])
            cold_df = pd.DataFrame(cold_la, columns=["Number", "Frequency"])

            display_hot_cold_tables(hot_df, cold_df)
            display_wheel_table(hot_df, cold_df)

    #MEGABUCKS
    elif lotto_type == "MB (Megabucks)":
        use_sequence = st.checkbox("🔗 Include Sequential Numbers", value=False)
        if st.button("🎰 Generate Prediction"):
            main_numbers = generate_mb_prediction(mb_df, allow_sequences=use_sequence)
            star_ball = mb_predict_star_ball(mb_df)
            st.success(f"🧠 Predicted Numbers: {main_numbers}")
            st.success(f"🌟 Predicted Megabucks Number: [{star_ball}]")
            st.info(f"🔢 Total Sum of Picks: {sum(main_numbers)}")

            #HOT AND COLD NUMBERS  
            hot_df = pd.DataFrame(hot_mb, columns=["Number", "Frequency"])
            cold_df = pd.DataFrame(cold_mb, columns=["Number", "Frequency"])

            display_hot_cold_tables(hot_df, cold_df)
            display_wheel_table(hot_df, cold_df)

    #MEGA MILLIONS
    elif lotto_type == "MM (Mega Millions)":
        use_sequence = st.checkbox("🔗 Include Sequential Numbers", value=False)
        if st.button("🎰 Generate Prediction"):
            main_numbers = generate_mm_prediction(mm_df, allow_sequences=use_sequence)
            star_ball = mm_predict_star_ball(mm_df)
            st.success(f"🧠 Predicted Numbers: {main_numbers}")
            st.success(f"🌟 Predicted Mega Ball Number: [{star_ball}]")
            st.info(f"🔢 Total Sum of Picks: {sum(main_numbers)}")

            #HOT AND COLD NUMBERS  
            hot_df = pd.DataFrame(hot_mm, columns=["Number", "Frequency"])
            cold_df = pd.DataFrame(cold_mm, columns=["Number", "Frequency"])

            display_hot_cold_tables(hot_df, cold_df)
            display_wheel_table(hot_df, cold_df)

    #POWER BALL
    elif lotto_type == "PB (Powerball)":
        use_sequence = st.checkbox("🔗 Include Sequential Numbers", value=False)
        if st.button("🎰 Generate Prediction"):
            main_numbers = generate_pb_prediction(pb_df, allow_sequences=use_sequence)
            star_ball = pb_predict_star_ball(pb_df)
            st.success(f"🧠 Predicted Numbers: {main_numbers}")
            st.success(f"🌟 Predicted Powerball Number: [{star_ball}]")
            st.info(f"🔢 Total Sum of Picks: {sum(main_numbers)}")

            #HOT AND COLD NUMBERS  
            hot_df = pd.DataFrame(hot_pb, columns=["Number", "Frequency"])
            cold_df = pd.DataFrame(cold_pb, columns=["Number", "Frequency"])

            display_hot_cold_tables(hot_df, cold_df)
            display_wheel_table(hot_df, cold_df)

except FileNotFoundError:
    st.error(f"❌ File not found: `{data_path}`")
except Exception as e:
    st.error(f"⚠️ Error: {str(e)}")