Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,104 +1,153 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
import pandas as pd
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
self.
|
9 |
-
self.
|
10 |
-
self.
|
11 |
-
self.
|
12 |
-
self.
|
13 |
-
self.
|
14 |
-
self.
|
15 |
-
self.
|
16 |
-
self.
|
17 |
-
self.
|
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 |
-
st.
|
87 |
-
|
88 |
-
|
89 |
-
st.
|
90 |
-
|
91 |
-
|
92 |
-
st.
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import json
|
4 |
+
|
5 |
+
# Oyuncu sınıfı tanımı
|
6 |
+
class Player:
|
7 |
+
def __init__(self, name):
|
8 |
+
self.name = name
|
9 |
+
self.league_position = None
|
10 |
+
self.target_hit = None
|
11 |
+
self.cup_stage = None
|
12 |
+
self.yellow_cards = 0
|
13 |
+
self.red_cards = 0
|
14 |
+
self.goals_conceded = 0
|
15 |
+
self.goals_scored = 0
|
16 |
+
self.interviews = 0
|
17 |
+
self.penalty_points = 0
|
18 |
+
self.score = 0
|
19 |
+
|
20 |
+
# Veri kaydetme fonksiyonu
|
21 |
+
def save_data(players, filename="players.json"):
|
22 |
+
data = []
|
23 |
+
for player in players:
|
24 |
+
player_data = {
|
25 |
+
"name": player.name,
|
26 |
+
"league_position": player.league_position,
|
27 |
+
"target_hit": player.target_hit,
|
28 |
+
"cup_stage": player.cup_stage,
|
29 |
+
"yellow_cards": player.yellow_cards,
|
30 |
+
"red_cards": player.red_cards,
|
31 |
+
"goals_conceded": player.goals_conceded,
|
32 |
+
"goals_scored": player.goals_scored,
|
33 |
+
"interviews": player.interviews,
|
34 |
+
"penalty_points": player.penalty_points,
|
35 |
+
"score": player.score
|
36 |
+
}
|
37 |
+
data.append(player_data)
|
38 |
+
with open(filename, "w") as f:
|
39 |
+
json.dump(data, f, indent=4)
|
40 |
+
|
41 |
+
# Veri yükleme fonksiyonu
|
42 |
+
def load_data(filename="players.json"):
|
43 |
+
with open(filename, "r") as f:
|
44 |
+
data = json.load(f)
|
45 |
+
players = []
|
46 |
+
for player_data in data:
|
47 |
+
player = Player(player_data["name"])
|
48 |
+
player.league_position = player_data["league_position"]
|
49 |
+
player.target_hit = player_data["target_hit"]
|
50 |
+
player.cup_stage = player_data["cup_stage"]
|
51 |
+
player.yellow_cards = player_data["yellow_cards"]
|
52 |
+
player.red_cards = player_data["red_cards"]
|
53 |
+
player.goals_conceded = player_data["goals_conceded"]
|
54 |
+
player.goals_scored = player_data["goals_scored"]
|
55 |
+
player.interviews = player_data["interviews"]
|
56 |
+
player.penalty_points = player_data["penalty_points"]
|
57 |
+
player.score = player_data["score"]
|
58 |
+
players.append(player)
|
59 |
+
return players
|
60 |
+
|
61 |
+
# Uygulama başlatıldığında verileri yükle
|
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.interviews >= 25:
|
129 |
+
player.score += 1
|
130 |
+
|
131 |
+
# Puan hesaplama
|
132 |
+
if st.button("Puanları Hesapla"):
|
133 |
+
calculate_scores(players)
|
134 |
+
st.success("Puanlar hesaplandı!")
|
135 |
+
save_data(players)
|
136 |
+
|
137 |
+
# Sonuçları görüntüleme
|
138 |
+
st.header("Sonuçlar")
|
139 |
+
results = [{"Oyuncu": player.name, "Puan": player.score} for player in players]
|
140 |
+
results_df = pd.DataFrame(results)
|
141 |
+
st.table(results_df)
|
142 |
+
|
143 |
+
# Excel çıktısı
|
144 |
+
def to_excel(df):
|
145 |
+
output = io.BytesIO()
|
146 |
+
writer = pd.ExcelWriter(output, engine='xlsxwriter')
|
147 |
+
df.to_excel(writer, index=False, sheet_name='Sheet1')
|
148 |
+
writer.save()
|
149 |
+
processed_data = output.getvalue()
|
150 |
+
return processed_data
|
151 |
+
|
152 |
+
excel_data = to_excel(results_df)
|
153 |
+
st.download_button(label="Excel İndir", data=excel_data, file_name='sonuclar.xlsx', mime='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
|