Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
import json
|
|
|
4 |
|
5 |
# Oyuncu sınıfı tanımı
|
6 |
class Player:
|
@@ -40,8 +41,11 @@ def save_data(players, filename="players.json"):
|
|
40 |
|
41 |
# Veri yükleme fonksiyonu
|
42 |
def load_data(filename="players.json"):
|
43 |
-
|
44 |
-
|
|
|
|
|
|
|
45 |
players = []
|
46 |
for player_data in data:
|
47 |
player = Player(player_data["name"])
|
@@ -58,96 +62,103 @@ def load_data(filename="players.json"):
|
|
58 |
players.append(player)
|
59 |
return players
|
60 |
|
61 |
-
#
|
62 |
-
try:
|
63 |
-
players = load_data()
|
64 |
-
except FileNotFoundError:
|
65 |
-
players = []
|
66 |
-
|
67 |
-
# Oyuncu ekleme fonksiyonu
|
68 |
-
def add_player(name):
|
69 |
-
players.append(Player(name))
|
70 |
-
|
71 |
-
# Oyuncu ekleme arayüzü
|
72 |
-
st.title("Özel Online Score Manager Ligi")
|
73 |
-
st.header("Oyuncu Ekle")
|
74 |
-
new_player_name = st.text_input("Oyuncu İsmi")
|
75 |
-
if st.button("Ekle"):
|
76 |
-
add_player(new_player_name)
|
77 |
-
st.success(f"{new_player_name} eklendi!")
|
78 |
-
save_data(players)
|
79 |
-
|
80 |
-
# Oyuncu bilgilerini güncelleme arayüzü
|
81 |
-
st.header("Oyuncu Bilgilerini Güncelle")
|
82 |
-
for player in players:
|
83 |
-
st.subheader(player.name)
|
84 |
-
player.league_position = st.number_input(f"Lig Sıralaması ({player.name})", min_value=1, max_value=20, value=player.league_position or 1)
|
85 |
-
player.target_hit = st.selectbox(f"Hedef Tutturması ({player.name})", options=[1, -1], index=0 if player.target_hit == 1 else 1)
|
86 |
-
player.cup_stage = st.selectbox(f"Kupa Aşaması ({player.name})", options=[4, 3, 2, 1], index=player.cup_stage or 0)
|
87 |
-
player.yellow_cards = st.number_input(f"Sarı Kartlar ({player.name})", min_value=0, value=player.yellow_cards)
|
88 |
-
player.red_cards = st.number_input(f"Kırmızı Kartlar ({player.name})", min_value=0, value=player.red_cards)
|
89 |
-
player.goals_conceded = st.number_input(f"Yenilen Goller ({player.name})", min_value=0, value=player.goals_conceded)
|
90 |
-
player.goals_scored = st.number_input(f"Atılan Goller ({player.name})", min_value=0, value=player.goals_scored)
|
91 |
-
player.interviews = st.number_input(f"Röportaj Sayısı ({player.name})", min_value=0, value=player.interviews)
|
92 |
-
if st.button(f"Güncelle {player.name}"):
|
93 |
-
save_data(players)
|
94 |
-
|
95 |
-
# Puan hesaplama fonksiyonları
|
96 |
-
def calculate_scores(players):
|
97 |
-
calculate_league_points(players)
|
98 |
-
calculate_target_points(players)
|
99 |
-
calculate_cup_points(players)
|
100 |
-
calculate_fair_play_points(players)
|
101 |
-
|
102 |
-
def calculate_league_points(players):
|
103 |
-
for player in players:
|
104 |
-
if player.league_position is not None:
|
105 |
-
player.score += (20 - player.league_position + 1)
|
106 |
-
|
107 |
-
def calculate_target_points(players):
|
108 |
-
for player in players:
|
109 |
-
if player.target_hit is not None:
|
110 |
-
player.score += player.target_hit
|
111 |
-
|
112 |
-
def calculate_cup_points(players):
|
113 |
-
for player in players:
|
114 |
-
if player.cup_stage is not None:
|
115 |
-
player.score += player.cup_stage
|
116 |
-
|
117 |
def calculate_fair_play_points(players):
|
118 |
min_yellow_cards = min(players, key=lambda p: p.yellow_cards).yellow_cards
|
119 |
min_red_cards = min(players, key=lambda p: p.red_cards).red_cards
|
120 |
-
min_goals_conceded = min(players, key=lambda p: p.goals_conceded).goals_conceded
|
121 |
-
max_interviews = max(players, key=lambda p: p.interviews).interviews
|
122 |
|
123 |
for player in players:
|
124 |
if player.yellow_cards == min_yellow_cards and player.red_cards == min_red_cards:
|
125 |
player.score += 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
if player.goals_conceded == min_goals_conceded:
|
127 |
player.score += 1
|
128 |
-
if player.
|
129 |
player.score += 1
|
130 |
|
131 |
-
#
|
132 |
-
|
133 |
-
|
134 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
135 |
save_data(players)
|
136 |
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
st.
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
import json
|
4 |
+
import io
|
5 |
|
6 |
# Oyuncu sınıfı tanımı
|
7 |
class Player:
|
|
|
41 |
|
42 |
# Veri yükleme fonksiyonu
|
43 |
def load_data(filename="players.json"):
|
44 |
+
try:
|
45 |
+
with open(filename, "r") as f:
|
46 |
+
data = json.load(f)
|
47 |
+
except FileNotFoundError:
|
48 |
+
data = []
|
49 |
players = []
|
50 |
for player_data in data:
|
51 |
player = Player(player_data["name"])
|
|
|
62 |
players.append(player)
|
63 |
return players
|
64 |
|
65 |
+
# Fair play ödüllerini belirleme
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
def calculate_fair_play_points(players):
|
67 |
min_yellow_cards = min(players, key=lambda p: p.yellow_cards).yellow_cards
|
68 |
min_red_cards = min(players, key=lambda p: p.red_cards).red_cards
|
|
|
|
|
69 |
|
70 |
for player in players:
|
71 |
if player.yellow_cards == min_yellow_cards and player.red_cards == min_red_cards:
|
72 |
player.score += 1
|
73 |
+
|
74 |
+
# En az gol yiyen ve en çok gol atan takımlara ödül verme
|
75 |
+
def calculate_goal_awards(players):
|
76 |
+
min_goals_conceded = min(players, key=lambda p: p.goals_conceded).goals_conceded
|
77 |
+
max_goals_scored = max(players, key=lambda p: p.goals_scored).goals_scored
|
78 |
+
|
79 |
+
for player in players:
|
80 |
if player.goals_conceded == min_goals_conceded:
|
81 |
player.score += 1
|
82 |
+
if player.goals_scored == max_goals_scored:
|
83 |
player.score += 1
|
84 |
|
85 |
+
# Uygulama başlatıldığında verileri yükle
|
86 |
+
players = load_data()
|
87 |
+
|
88 |
+
# Oyuncu ekleyici bölümü
|
89 |
+
st.title("Özel Online Score Manager Ligi")
|
90 |
+
|
91 |
+
player_name = st.text_input("Oyuncu İsmi")
|
92 |
+
|
93 |
+
player_league_position = st.number_input("Lig Sıralaması", min_value=1, max_value=20)
|
94 |
+
player_target_hit = st.selectbox("Hedef Tutturması", options=[1, -1], index=0)
|
95 |
+
player_cup_stage = st.selectbox("Kupa Aşaması", options=[4, 3, 2, 1], index=0)
|
96 |
+
player_yellow_cards = st.number_input("Sarı Kartlar", min_value=0)
|
97 |
+
player_red_cards = st.number_input("Kırmızı Kartlar", min_value=0)
|
98 |
+
player_goals_conceded = st.number_input("Yenilen Goller", min_value=0)
|
99 |
+
player_goals_scored = st.number_input("Atılan Goller", min_value=0)
|
100 |
+
player_interviews = st.number_input("Röportaj Sayısı", min_value=0)
|
101 |
+
|
102 |
+
if st.button("Ekle"):
|
103 |
+
player = Player(player_name)
|
104 |
+
player.league_position = player_league_position
|
105 |
+
player.target_hit = player_target_hit
|
106 |
+
player.cup_stage = player_cup_stage
|
107 |
+
player.yellow_cards = player_yellow_cards
|
108 |
+
player.red_cards = player_red_cards
|
109 |
+
player.goals_conceded = player_goals_conceded
|
110 |
+
player.goals_scored = player_goals_scored
|
111 |
+
player.interviews = player_interviews
|
112 |
+
players.append(player)
|
113 |
+
st.success(f"{player_name} eklendi!")
|
114 |
+
|
115 |
+
# Hesapla bölümü
|
116 |
+
if st.button("Hesapla"):
|
117 |
+
calculate_fair_play_points(players)
|
118 |
+
calculate_goal_awards(players)
|
119 |
+
st.success("Hesaplamalar yapıldı ve ödüller verildi!")
|
120 |
save_data(players)
|
121 |
|
122 |
+
# Sonuçları görüntüleme
|
123 |
+
st.header("Sonuçlar")
|
124 |
+
for player in players:
|
125 |
+
st.subheader(player.name)
|
126 |
+
st.write(f"Lig Sıralaması: {player.league_position}")
|
127 |
+
st.write(f"Hedef Tutturması: {player.target_hit}")
|
128 |
+
st.write(f"Kupa Aşaması: {player.cup_stage}")
|
129 |
+
st.write(f"Sarı Kartlar: {player.yellow_cards}")
|
130 |
+
st.write(f"Kırmızı Kartlar: {player.red_cards}")
|
131 |
+
st.write(f"Yenilen Goller: {player.goals_conceded}")
|
132 |
+
st.write(f"Atılan Goller: {player.goals_scored}")
|
133 |
+
st.write(f"Röportaj Sayısı: {player.interviews}")
|
134 |
+
st.write(f"Puan: {player.score}")
|
135 |
+
st.write("---")
|
136 |
+
|
137 |
+
# Excel çıktısı
|
138 |
+
def to_excel(df):
|
139 |
+
output = io.BytesIO()
|
140 |
+
writer = pd.ExcelWriter(output, engine='openpyxl')
|
141 |
+
df.to_excel(writer, index=False, sheet_name='Oyuncu Verileri')
|
142 |
+
writer.close()
|
143 |
+
output.seek(0) # Dosya başlangıcına geri dön
|
144 |
+
processed_data = output.getvalue()
|
145 |
+
return processed_data
|
146 |
+
|
147 |
+
if st.button("Excel İndir"):
|
148 |
+
df_players = pd.DataFrame([
|
149 |
+
{
|
150 |
+
"Oyuncu": player.name,
|
151 |
+
"Lig Sıralaması": player.league_position,
|
152 |
+
"Hedef Tutturması": player.target_hit,
|
153 |
+
"Kupa Aşaması": player.cup_stage,
|
154 |
+
"Sarı Kartlar": player.yellow_cards,
|
155 |
+
"Kırmızı Kartlar": player.red_cards,
|
156 |
+
"Yenilen Goller": player.goals_conceded,
|
157 |
+
"Atılan Goller": player.goals_scored,
|
158 |
+
"Röportaj Sayısı": player.interviews,
|
159 |
+
"Puan": player.score
|
160 |
+
}
|
161 |
+
for player in players
|
162 |
+
])
|
163 |
+
excel_data = to_excel(df_players)
|
164 |
+
st.download_button(label="Excel İndir", data=excel_data, file_name='oyuncu_verileri.xlsx', mime='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
|