yunuseduran commited on
Commit
baee29e
·
verified ·
1 Parent(s): 010c8fd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +153 -104
app.py CHANGED
@@ -1,104 +1,153 @@
1
- import streamlit as st
2
- import pandas as pd
3
-
4
- # Oyuncu sınıfı tanımı
5
- class Player:
6
- def __init__(self, name):
7
- self.name = name
8
- self.league_position = None
9
- self.target_hit = None
10
- self.cup_stage = None
11
- self.yellow_cards = 0
12
- self.red_cards = 0
13
- self.goals_conceded = 0
14
- self.goals_scored = 0
15
- self.interviews = 0
16
- self.penalty_points = 0
17
- self.score = 0
18
-
19
- # Oyuncu listesi
20
- players = []
21
-
22
- # Oyuncu ekleme fonksiyonu
23
- def add_player(name):
24
- players.append(Player(name))
25
-
26
- # Oyuncu ekleme arayüzü
27
- st.title("Özel Online Score Manager Ligi")
28
- st.header("Oyuncu Ekle")
29
- new_player_name = st.text_input("Oyuncu İsmi")
30
- if st.button("Ekle"):
31
- add_player(new_player_name)
32
- st.success(f"{new_player_name} eklendi!")
33
-
34
- # Oyuncu bilgilerini güncelleme arayüzü
35
- st.header("Oyuncu Bilgilerini Güncelle")
36
- for player in players:
37
- st.subheader(player.name)
38
- player.league_position = st.number_input(f"Lig Sıralaması ({player.name})", min_value=1, max_value=20)
39
- player.target_hit = st.selectbox(f"Hedef Tutturması ({player.name})", options=[1, -1])
40
- player.cup_stage = st.selectbox(f"Kupa Aşaması ({player.name})", options=[4, 3, 2, 1])
41
- player.yellow_cards = st.number_input(f"Sarı Kartlar ({player.name})", min_value=0)
42
- player.red_cards = st.number_input(f"Kırmızı Kartlar ({player.name})", min_value=0)
43
- player.goals_conceded = st.number_input(f"Yenilen Goller ({player.name})", min_value=0)
44
- player.goals_scored = st.number_input(f"Atılan Goller ({player.name})", min_value=0)
45
- player.interviews = st.number_input(f"Röportaj Sayısı ({player.name})", min_value=0)
46
-
47
- # Puan hesaplama fonksiyonları
48
- def calculate_scores(players):
49
- calculate_league_points(players)
50
- calculate_target_points(players)
51
- calculate_cup_points(players)
52
- calculate_fair_play_points(players)
53
-
54
- def calculate_league_points(players):
55
- for player in players:
56
- if player.league_position is not None:
57
- player.score += (20 - player.league_position + 1)
58
-
59
- def calculate_target_points(players):
60
- for player in players:
61
- if player.target_hit is not None:
62
- player.score += player.target_hit
63
-
64
- def calculate_cup_points(players):
65
- for player in players:
66
- if player.cup_stage is not None:
67
- player.score += player.cup_stage
68
-
69
- def calculate_fair_play_points(players):
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
- min_goals_conceded = min(players, key=lambda p: p.goals_conceded).goals_conceded
73
- max_interviews = max(players, key=lambda p: p.interviews).interviews
74
-
75
- for player in players:
76
- if player.yellow_cards == min_yellow_cards and player.red_cards == min_red_cards:
77
- player.score += 1
78
- if player.goals_conceded == min_goals_conceded:
79
- player.score += 1
80
- if player.interviews >= 25:
81
- player.score += 1
82
-
83
- # Puan hesaplama
84
- if st.button("Puanları Hesapla"):
85
- calculate_scores(players)
86
- st.success("Puanlar hesaplandı!")
87
-
88
- # Sonuçları görüntüleme
89
- st.header("Sonuçlar")
90
- results = [{"Oyuncu": player.name, "Puan": player.score} for player in players]
91
- results_df = pd.DataFrame(results)
92
- st.table(results_df)
93
-
94
- # Excel çıktısı
95
- def to_excel(df):
96
- output = io.BytesIO()
97
- writer = pd.ExcelWriter(output, engine='xlsxwriter')
98
- df.to_excel(writer, index=False, sheet_name='Sheet1')
99
- writer.save()
100
- processed_data = output.getvalue()
101
- return processed_data
102
-
103
- excel_data = to_excel(results_df)
104
- st.download_button(label="Excel İndir", data=excel_data, file_name='sonuclar.xlsx', mime='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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')