-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli_script_allThreeModels.py
More file actions
204 lines (160 loc) · 8.1 KB
/
cli_script_allThreeModels.py
File metadata and controls
204 lines (160 loc) · 8.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
# -*- coding: utf-8 -*-
"""
ENGLISH PREMIER LEAGUE CHAMPION PREDICTION PROJECT
FINAL COMMAND LINE INTERFACE APPLICATION
"""
import os
import pandas as pd
import subprocess
import sys
# ✅ Ensure script runs from its own directory
script_dir = os.path.dirname(os.path.abspath(__file__))
# ✅ Path to Scripts
simulation_script_path = os.path.join(script_dir, "ModelScriptsForCLI/simulation_approach.py")
ml_script_path = os.path.join(script_dir, "ModelScriptsForCLI/ia_ml_approach.py") # ML script
markov_script_path = os.path.join(script_dir, "ModelScriptsForCLI/markovchain_approach.py") # Markov Chains script
dataset_path = os.path.join(script_dir, "Datasets/premier-league-matches.csv")
# ✅ Verify if scripts exist
ml_script_exists = os.path.exists(ml_script_path)
markov_script_exists = os.path.exists(markov_script_path)
# ✅ Load Dataset
df = pd.read_csv(dataset_path, encoding="utf-8")
# ✅ Get Unique Team Names
unique_teams = sorted(pd.concat([df["Home"], df["Away"]]).unique())
# ✅ Start Application
print(
"""
************************************************************
* *
* 🚀 WELCOME TO PremierPredict ⚽ *
* *
************************************************************
🔹 Predict Premier League match outcomes
🔹 Compare team performances
🔹 Forecast season standings
Powered by: Machine Learning, Markov Chains, and Simulation
****************************************************************
"""
)
# ✅ Function to Select Prediction Model
def select_model():
while True:
model_choice = input("Choose a prediction technique: \n1. Machine Learning (ML) \n2. Markov Chains \n3. Simulation \n\n").strip().lower()
if model_choice in ["1", "ml"]:
if not ml_script_exists:
print("\n❌ ML script not found! Check 'ia_ml_approach.py'.")
continue
print("\n✅ Machine Learning Model Selected.")
return "ml"
elif model_choice in ["2", "markov chains"]:
if not markov_script_exists:
print("\n❌ Markov Chains script not found! Check 'markov_chains_approach.py'.")
continue
print("\n✅ Markov Chains Model Selected.")
return "markov"
elif model_choice in ["3", "simulation"]:
print("\n✅ Simulation Model Selected.")
return "simulation"
else:
print("\n❌ Invalid selection. Please enter 1, 2, or 3.")
# ✅ Function to Run Subprocess
def run_subprocess(args):
"""Runs a subprocess with proper error handling."""
result = subprocess.run(args, capture_output=True, text=True, encoding="utf-8", shell=True)
print(result.stdout)
if result.stderr:
print("\n⚠️ Error:\n", result.stderr)
# ✅ Select Model Initially
selected_model = select_model()
# ✅ Main Loop: Allow User to Analyze Multiple Teams & Switch Models
while True:
# ✅ Print Team List
title = "⚽ TEAM NAMES ⚽"
num_columns = 3
column_width = 25
total_width = num_columns * column_width
print("=" * total_width)
print(title.center(total_width))
print("=" * total_width)
for i, team in enumerate(unique_teams, 1):
print(f"{i:>2}. {team:<{column_width - 5}}", end="")
if i % num_columns == 0:
print()
print("\n" + "=" * total_width)
# ✅ User Selects Team
while True:
team_name = input("\nChoose a team from the list above whose statistics you are interested in: ").strip()
if team_name in unique_teams:
print(f"\n✅ Team Selected: {team_name}")
break # Exit loop if valid team
else:
print("\n❌ Invalid team selection. Please enter a valid team name.")
# ✅ Inner Loop: Allow User to Analyze the Selected Team
while True:
# ✅ Show Analysis Options
print("\nWhat would you like to analyze for this team?")
print("1. Does the selected team have a higher chance of winning home or away?")
print("2. Show who the selected team is versing next and who they versed previously.")
print("3. Put the selected team against another team and see who is most likely to win.")
print("4. Check who the winner will be at the end of the league and who will be 3rd, 4th, etc., up to 10.")
user_choice = input("\nEnter your choice (1-4): ").strip()
# ✅ Handle Each Option
if user_choice == "1":
print(f"\n🔍 Analyzing home vs. away performance for {team_name}...\n")
if selected_model == "ml":
run_subprocess([sys.executable, ml_script_path, team_name, "home_away"])
elif selected_model == "markov":
run_subprocess([sys.executable, markov_script_path, team_name, "home_away"])
else:
run_subprocess([sys.executable, simulation_script_path, team_name, "home_away"])
elif user_choice == "2":
print(f"\n🔍 Fetching previous and upcoming matches for {team_name}...\n")
if selected_model == "ml":
run_subprocess([sys.executable, ml_script_path, team_name, "matches"])
elif selected_model == "markov":
run_subprocess([sys.executable, markov_script_path, team_name, "matches"])
else:
run_subprocess([sys.executable, simulation_script_path, team_name, "matches"])
elif user_choice == "3":
while True:
opponent_team = input("\nEnter the name of the opponent team: ").strip()
if opponent_team in unique_teams:
break # Valid opponent, continue
print("\n❌ Invalid opponent selection. Please enter a valid team name.")
print(f"\n🔍 Simulating match between {team_name} and {opponent_team}...\n")
if selected_model == "ml":
run_subprocess([sys.executable, ml_script_path, team_name, "head_to_head", opponent_team])
elif selected_model == "markov":
run_subprocess([sys.executable, markov_script_path, team_name, "head_to_head", opponent_team])
else:
run_subprocess([sys.executable, simulation_script_path, team_name, "head_to_head", opponent_team])
elif user_choice == "4":
print(f"\n🔍 Running full season simulation and predicting final standings...\n")
if selected_model == "ml":
run_subprocess([sys.executable, ml_script_path, team_name, "league_standings"])
elif selected_model == "markov":
run_subprocess([sys.executable, markov_script_path, team_name, "league_standings"])
else:
run_subprocess([sys.executable, simulation_script_path, team_name, "league_standings"])
else:
print("\n❌ Invalid choice. Please enter a valid option (1-4).")
continue
# ✅ Ask User What They Want to Do Next
while True:
next_action = input("\nWould you like to:\n1. View more statistics for this team\n2. Analyze another team\n3. Switch prediction model\n4. Exit\n\nEnter choice (1-4): ").strip()
if next_action == "1":
break # Continue analyzing the same team
elif next_action == "2":
print("\n🔄 Switching teams...\n")
break # Exit to outer loop to select a new team
elif next_action == "3":
print("\n🔄 Switching prediction model...\n")
selected_model = select_model() # Let the user choose a new model
break # Stay in the loop, allowing a new team to be chosen
elif next_action == "4":
print("\n👋 Thank you for using PremierPredict! Goodbye!\n")
sys.exit(0) # Exit program completely
else:
print("\n❌ Invalid input. Please enter 1, 2, 3, or 4.")
if next_action in ["2", "3"]: # If user switched team or model, restart outer loop
break