Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,6 @@
|
|
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:
|
@@ -64,6 +63,10 @@ def load_data(filename="players.json"):
|
|
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 |
|
@@ -73,6 +76,10 @@ def calculate_fair_play_points(players):
|
|
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 |
|
@@ -98,21 +105,6 @@ def apply_penalty_points(players):
|
|
98 |
if violation in penalties:
|
99 |
player.score += penalties[violation]
|
100 |
|
101 |
-
# Oyuncu ekleme işlevi
|
102 |
-
def add_player(name, league_position, target_hit, cup_stage, yellow_cards, red_cards, goals_conceded, goals_scored, interviews, penalty_points):
|
103 |
-
player = Player(name)
|
104 |
-
player.league_position = league_position
|
105 |
-
player.target_hit = target_hit
|
106 |
-
player.cup_stage = cup_stage
|
107 |
-
player.yellow_cards = yellow_cards
|
108 |
-
player.red_cards = red_cards
|
109 |
-
player.goals_conceded = goals_conceded
|
110 |
-
player.goals_scored = goals_scored
|
111 |
-
player.interviews = interviews
|
112 |
-
player.penalty_points = penalty_points
|
113 |
-
return player
|
114 |
-
|
115 |
-
# DataFrame oluşturma işlevi
|
116 |
def create_dataframe(players):
|
117 |
df_players = pd.DataFrame({
|
118 |
"Oyuncu": [player.name for player in players],
|
@@ -128,47 +120,70 @@ def create_dataframe(players):
|
|
128 |
})
|
129 |
return df_players
|
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 |
-
st.
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
import json
|
|
|
4 |
|
5 |
# Oyuncu sınıfı tanımı
|
6 |
class Player:
|
|
|
63 |
|
64 |
# Fair play ödüllerini belirleme
|
65 |
def calculate_fair_play_points(players):
|
66 |
+
if not players:
|
67 |
+
st.warning("Oyuncu listesi boş. Lütfen en az bir oyuncu ekleyin.")
|
68 |
+
return
|
69 |
+
|
70 |
min_yellow_cards = min(players, key=lambda p: p.yellow_cards).yellow_cards
|
71 |
min_red_cards = min(players, key=lambda p: p.red_cards).red_cards
|
72 |
|
|
|
76 |
|
77 |
# En az gol yiyen ve en çok gol atan takımlara ödül verme
|
78 |
def calculate_goal_awards(players):
|
79 |
+
if not players:
|
80 |
+
st.warning("Oyuncu listesi boş. Lütfen en az bir oyuncu ekleyin.")
|
81 |
+
return
|
82 |
+
|
83 |
min_goals_conceded = min(players, key=lambda p: p.goals_conceded).goals_conceded
|
84 |
max_goals_scored = max(players, key=lambda p: p.goals_scored).goals_scored
|
85 |
|
|
|
105 |
if violation in penalties:
|
106 |
player.score += penalties[violation]
|
107 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
108 |
def create_dataframe(players):
|
109 |
df_players = pd.DataFrame({
|
110 |
"Oyuncu": [player.name for player in players],
|
|
|
120 |
})
|
121 |
return df_players
|
122 |
|
123 |
+
def calculate_scores(players):
|
124 |
+
for player in players:
|
125 |
+
player.score = (
|
126 |
+
20 - player.league_position +
|
127 |
+
player.target_hit +
|
128 |
+
player.cup_stage +
|
129 |
+
(1 if player.yellow_cards == 0 else 0) +
|
130 |
+
(1 if player.goals_conceded == min([p.goals_conceded for p in players]) else 0) +
|
131 |
+
(1 if player.interviews >= 25 else 0)
|
132 |
+
)
|
133 |
+
|
134 |
+
# Ana uygulama akışı
|
135 |
+
def main():
|
136 |
+
st.title("Özel Online Score Manager Ligi")
|
137 |
+
|
138 |
+
player_name = st.text_input("Oyuncu İsmi")
|
139 |
+
player_league_position = st.number_input("Lig Sıralaması", min_value=1, max_value=20)
|
140 |
+
player_target_hit = st.selectbox("Hedef Tutturması", options=[1, -1], index=0)
|
141 |
+
player_cup_stage = st.selectbox("Kupa Aşaması", options=[4, 3, 2, 1], index=0)
|
142 |
+
player_yellow_cards = st.number_input("Sarı Kartlar", min_value=0)
|
143 |
+
player_red_cards = st.number_input("Kırmızı Kartlar", min_value=0)
|
144 |
+
player_goals_conceded = st.number_input("Yenilen Goller", min_value=0)
|
145 |
+
player_goals_scored = st.number_input("Atılan Goller", min_value=0)
|
146 |
+
player_interviews = st.number_input("Röportaj Sayısı", min_value=0)
|
147 |
+
player_penalties = st.multiselect("Kural İhlalleri", options=[
|
148 |
+
"Transfer ihlali",
|
149 |
+
"İç transfer ihlali",
|
150 |
+
"Aktiflik ihlali",
|
151 |
+
"Aynı takım arası iç transfer ihlali",
|
152 |
+
"Toplam iç transfer sayısı ihlali",
|
153 |
+
"Kadro planlaması ihlali"
|
154 |
+
])
|
155 |
+
|
156 |
+
if st.button("Ekle"):
|
157 |
+
new_player = add_player(player_name, player_league_position, player_target_hit, player_cup_stage, player_yellow_cards, player_red_cards, player_goals_conceded, player_goals_scored, player_interviews, player_penalties)
|
158 |
+
|
159 |
+
# Oyuncuyu ekleyip kaydet
|
160 |
+
players = load_data()
|
161 |
+
players.append(new_player)
|
162 |
+
save_data(players)
|
163 |
+
st.success(f"{player_name} eklendi!")
|
164 |
+
|
165 |
+
# DataFrame'i oluştur
|
166 |
+
players = load_data()
|
167 |
+
df_players = create_dataframe(players)
|
168 |
+
|
169 |
+
# Hesapla bölümü
|
170 |
+
if st.button("Hesapla"):
|
171 |
+
calculate_fair_play_points(players)
|
172 |
+
calculate_goal_awards(players)
|
173 |
+
apply_penalty_points(players)
|
174 |
+
calculate_scores(players)
|
175 |
+
save_data(players)
|
176 |
+
st.success("Hesaplamalar yapıldı ve ödüller verildi!")
|
177 |
+
|
178 |
+
# DataFrame'i görüntüle
|
179 |
+
st.write(df_players)
|
180 |
+
|
181 |
+
# Excel çıktısı
|
182 |
+
if st.button("Excel İndir"):
|
183 |
+
st.write("Excel İndiriliyor...")
|
184 |
+
with pd.ExcelWriter('oyuncu_verileri.xlsx') as writer:
|
185 |
+
df_players.to_excel(writer, index=False)
|
186 |
+
|
187 |
+
# Uygulama başlatma
|
188 |
+
if __name__ == "__main__":
|
189 |
+
main()
|