| import streamlit as st |
| import requests |
|
|
| st.set_page_config(page_title="⚽ Maç Olasılık Analizi", layout="centered") |
|
|
| st.title("⚽ İki Takım — Maç Olasılık Analizi") |
|
|
| |
| api_key = st.text_input("API-Sports Key'inizi girin:", type="password") |
|
|
| |
| home_team = st.text_input("Ev Sahibi Takım (ör. Real Madrid)") |
| away_team = st.text_input("Deplasman Takım (ör. Barcelona)") |
|
|
| if st.button("🔍 Analiz Et"): |
| if not api_key: |
| st.error("Lütfen API key giriniz.") |
| else: |
| |
| def get_team_id(team_name): |
| url = f"https://v3.football.api-sports.io/teams?search={team_name}" |
| headers = {"x-apisports-key": api_key} |
| r = requests.get(url, headers=headers) |
| data = r.json() |
| if data["response"]: |
| return data["response"][0]["team"]["id"] |
| else: |
| return None |
|
|
| home_id = get_team_id(home_team) |
| away_id = get_team_id(away_team) |
|
|
| if not home_id or not away_id: |
| st.error(f"Takım bulunamadı: {home_team} veya {away_team}") |
| else: |
| st.success(f"{home_team} (ID: {home_id}) vs {away_team} (ID: {away_id}) bulundu ✅") |
|
|
| |
| def get_last_matches(team_id): |
| url = f"https://v3.football.api-sports.io/fixtures?team={team_id}&last=10" |
| headers = {"x-apisports-key": api_key} |
| r = requests.get(url, headers=headers) |
| return r.json()["response"] |
|
|
| home_matches = get_last_matches(home_id) |
| away_matches = get_last_matches(away_id) |
|
|
| |
| def calc_winrate(matches, team_id): |
| wins = 0 |
| for m in matches: |
| if m["teams"]["home"]["id"] == team_id and m["teams"]["home"]["winner"]: |
| wins += 1 |
| elif m["teams"]["away"]["id"] == team_id and m["teams"]["away"]["winner"]: |
| wins += 1 |
| return wins / len(matches) * 100 if matches else 0 |
|
|
| home_winrate = calc_winrate(home_matches, home_id) |
| away_winrate = calc_winrate(away_matches, away_id) |
|
|
| st.subheader("📊 Olasılık Tahmini") |
| st.write(f"🏠 {home_team} kazanma ihtimali: **{home_winrate:.1f}%**") |
| st.write(f"🚌 {away_team} kazanma ihtimali: **{away_winrate:.1f}%**") |
| st.write(f"🤝 Beraberlik ihtimali: **{100 - (home_winrate + away_winrate)/2:.1f}%**") |