Repository navigation
Expand file tree
/
Copy pathanalyzer.py
More file actions
285 lines (222 loc) · 10.1 KB
/
Copy pathanalyzer.py
File metadata and controls
285 lines (222 loc) · 10.1 KB
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
import math
import random
import logging
from collections import Counter, defaultdict
from typing import List, Dict, Tuple
logger = logging.getLogger(__name__)
class AdvancedKenoAnalyzer:
def __init__(self, database):
self.db = database
def calculate_advanced_probabilities(self, draws: List[Dict]) -> Dict[int, float]:
"""Calculate advanced probabilities using multiple factors"""
if len(draws) < 3:
return self._get_default_probabilities()
# Factor 1: Basic frequency
freq_scores = self._calculate_frequency_scores(draws)
# Factor 2: Recency weighting
recency_scores = self._calculate_recency_scores(draws)
# Factor 3: Hot/Cold analysis
hot_cold_scores = self._calculate_hot_cold_scores(draws)
# Factor 4: Pattern analysis
pattern_scores = self._calculate_pattern_scores(draws)
# Factor 5: Streak analysis
streak_scores = self._calculate_streak_scores()
# Combine all factors
combined_scores = {}
for number in range(1, 81):
score = (
freq_scores.get(number, 0) * 0.25 +
recency_scores.get(number, 0) * 0.30 +
hot_cold_scores.get(number, 0) * 0.20 +
pattern_scores.get(number, 0) * 0.15 +
streak_scores.get(number, 0) * 0.10
)
combined_scores[number] = max(score, 0.001)
# Normalize
total = sum(combined_scores.values())
return {k: v/total for k, v in combined_scores.items()}
def _calculate_frequency_scores(self, draws: List[Dict]) -> Dict[int, float]:
"""Calculate frequency-based scores"""
number_counts = Counter()
total_draws = len(draws)
for draw in draws:
number_counts.update(draw['numbers'])
scores = {}
for number in range(1, 81):
count = number_counts.get(number, 0)
scores[number] = count / total_draws if total_draws > 0 else 0.01
return scores
def _calculate_recency_scores(self, draws: List[Dict]) -> Dict[int, float]:
"""Calculate recency-weighted scores"""
if not draws:
return {}
scores = {}
total_draws = len(draws)
for i, draw in enumerate(draws):
weight = 1.0 + (total_draws - i) * 0.1
for number in draw['numbers']:
scores[number] = scores.get(number, 0) + weight
# Normalize
max_score = max(scores.values()) if scores else 1
return {k: v/max_score for k, v in scores.items()}
def _calculate_hot_cold_scores(self, draws: List[Dict]) -> Dict[int, float]:
"""Calculate hot/cold number scores"""
if len(draws) < 10:
return {}
recent_count = max(5, len(draws) // 3)
recent_draws = draws[:recent_count]
older_draws = draws[recent_count:]
recent_numbers = set()
for draw in recent_draws:
recent_numbers.update(draw['numbers'])
older_numbers = set()
for draw in older_draws:
older_numbers.update(draw['numbers'])
scores = {}
for number in range(1, 81):
if number in recent_numbers and number not in older_numbers:
scores[number] = 1.0
elif number not in recent_numbers and number in older_numbers:
scores[number] = 0.3
elif number in recent_numbers:
scores[number] = 0.7
else:
scores[number] = 0.1
return scores
def _calculate_pattern_scores(self, draws: List[Dict]) -> Dict[int, float]:
"""Calculate pattern-based scores"""
if len(draws) < 3:
return {}
last_draw = draws[0]['numbers']
patterns = self._analyze_draw_patterns(last_draw)
scores = {}
for number in range(1, 81):
score = 0.0
if number % 10 in patterns.get('endings', []):
score += 0.3
if (number - 1) // 10 in patterns.get('decades', []):
score += 0.3
if number <= 40 and patterns.get('low_high_balance', 0) > 0.5:
score += 0.2
elif number > 40 and patterns.get('low_high_balance', 0) < 0.5:
score += 0.2
if number % 2 == 0 and patterns.get('even_odd_balance', 0) > 0.5:
score += 0.2
elif number % 2 == 1 and patterns.get('even_odd_balance', 0) < 0.5:
score += 0.2
scores[number] = min(score, 1.0)
return scores
def _calculate_streak_scores(self) -> Dict[int, float]:
"""Calculate scores based on hot/cold streaks"""
stats = self.db.get_number_stats()
scores = {}
for number in range(1, 81):
number_stats = stats.get(number, {})
hot_streak = number_stats.get('hot_streak', 0)
cold_streak = number_stats.get('cold_streak', 0)
if hot_streak >= 3:
scores[number] = 0.8
elif hot_streak >= 2:
scores[number] = 0.6
elif cold_streak >= 5:
scores[number] = 0.9
elif cold_streak >= 3:
scores[number] = 0.7
else:
scores[number] = 0.5
return scores
def _analyze_draw_patterns(self, numbers: List[int]) -> Dict:
"""Analyze patterns in the most recent draw"""
patterns = {
'endings': [],
'decades': [],
'low_high_balance': 0,
'even_odd_balance': 0
}
# Analyze number endings
endings = [n % 10 for n in numbers]
patterns['endings'] = list(set(endings))
# Analyze decades
decades = [(n - 1) // 10 for n in numbers]
patterns['decades'] = list(set(decades))
# Low/High balance (1-40 vs 41-80)
low_count = sum(1 for n in numbers if n <= 40)
patterns['low_high_balance'] = low_count / len(numbers)
# Even/Odd balance
even_count = sum(1 for n in numbers if n % 2 == 0)
patterns['even_odd_balance'] = even_count / len(numbers)
return patterns
def _get_default_probabilities(self) -> Dict[int, float]:
"""Return default probabilities when insufficient data"""
return {i: 1/80 for i in range(1, 81)}
def generate_advanced_predictions(self) -> Dict[str, any]:
"""Generate advanced predictions with confidence scores"""
recent_draws = self.db.get_recent_draws(hours=72, limit=100)
total_draws = self.db.get_total_draws()
if total_draws < 5:
return {
"very_high": random.sample(range(1, 81), 4),
"high": random.sample(range(1, 81), 10),
"confidence": 0.1,
"message": "⚠️ Low confidence - Need more data"
}
# Calculate probabilities
probabilities = self.calculate_advanced_probabilities(recent_draws)
# Generate very high probability numbers (top 4)
very_high = sorted(probabilities.items(), key=lambda x: x[1], reverse=True)[:4]
very_high_numbers = [num for num, prob in very_high]
# Generate high probability numbers (next 10, excluding very high)
high_candidates = sorted(probabilities.items(), key=lambda x: x[1], reverse=True)[4:20]
high_numbers = [num for num, prob in high_candidates[:10]]
# Calculate confidence score
confidence = self._calculate_confidence(recent_draws, probabilities)
return {
"very_high": very_high_numbers,
"high": high_numbers,
"confidence": round(confidence, 3),
"total_draws": total_draws,
"recent_draws": len(recent_draws),
"message": self._get_confidence_message(confidence)
}
def _calculate_confidence(self, draws: List[Dict], probabilities: Dict[int, float]) -> float:
"""Calculate prediction confidence score"""
if len(draws) < 10:
return 0.3
# Base confidence on data quantity
data_confidence = min(len(draws) / 50, 1.0)
# Confidence based on probability distribution
top_probs = sorted(probabilities.values(), reverse=True)[:10]
prob_confidence = sum(top_probs) / 1.0
# Pattern consistency
pattern_confidence = self._calculate_pattern_consistency(draws)
# Combine confidence factors
final_confidence = (
data_confidence * 0.4 +
prob_confidence * 0.4 +
pattern_confidence * 0.2
)
return min(final_confidence, 0.95)
def _calculate_pattern_consistency(self, draws: List[Dict]) -> float:
"""Calculate how consistent patterns are in recent draws"""
if len(draws) < 5:
return 0.5
pattern_changes = 0
total_comparisons = 0
for i in range(min(5, len(draws) - 1)):
current_patterns = self._analyze_draw_patterns(draws[i]['numbers'])
next_patterns = self._analyze_draw_patterns(draws[i + 1]['numbers'])
if set(current_patterns['endings']) != set(next_patterns['endings']):
pattern_changes += 1
total_comparisons += 1
consistency = 1.0 - (pattern_changes / total_comparisons if total_comparisons > 0 else 0)
return consistency
def _get_confidence_message(self, confidence: float) -> str:
"""Get human-readable confidence message"""
if confidence >= 0.8:
return "🎯 HIGH CONFIDENCE"
elif confidence >= 0.6:
return "✅ GOOD CONFIDENCE"
elif confidence >= 0.4:
return "⚠️ MODERATE CONFIDENCE"
else:
return "🔻 LOW CONFIDENCE"