rafaldembski commited on
Commit
6a02207
verified
1 Parent(s): cb63f35

Update pages/Statistics.py

Browse files
Files changed (1) hide show
  1. pages/Statistics.py +18 -64
pages/Statistics.py CHANGED
@@ -13,9 +13,6 @@ import requests
13
  # Importowanie funkcji z utils/functions.py
14
  from utils.functions import get_phone_info, get_stats, get_history, get_fake_numbers
15
 
16
- # Importowanie funkcji 'card' z 'streamlit_extras.card'
17
- from streamlit_extras.card import card
18
-
19
  # Definiowanie t艂umacze艅 dla zak艂adki "Statystyki"
20
  page_translations = {
21
  'Polish': {
@@ -37,7 +34,6 @@ page_translations = {
37
  'no_data': "Brak dost臋pnych danych do wy艣wietlenia.",
38
  'download_button': "馃摜 Pobierz dane jako CSV",
39
  'select_date_range': "Wybierz zakres dat:",
40
- 'search_placeholder': "Wyszukaj w historii:",
41
  'recent_days': 30 # Domy艣lny zakres dat
42
  },
43
  'German': {
@@ -59,7 +55,6 @@ page_translations = {
59
  'no_data': "Keine Daten zum Anzeigen verf眉gbar.",
60
  'download_button': "馃摜 Daten als CSV herunterladen",
61
  'select_date_range': "Datumsbereich ausw盲hlen:",
62
- 'search_placeholder': "Suche in der Historie:",
63
  'recent_days': 30
64
  },
65
  'English': {
@@ -81,7 +76,6 @@ page_translations = {
81
  'no_data': "No data available to display.",
82
  'download_button': "馃摜 Download data as CSV",
83
  'select_date_range': "Select date range:",
84
- 'search_placeholder': "Search in history:",
85
  'recent_days': 30
86
  }
87
  }
@@ -128,27 +122,12 @@ def get_iso_alpha3(country_name):
128
  except LookupError:
129
  return None
130
 
131
- def inject_custom_css():
132
- st.markdown(
133
- """
134
- <style>
135
- .stCard {
136
- padding: 0.5rem;
137
- margin: 0.2rem;
138
- }
139
- </style>
140
- """,
141
- unsafe_allow_html=True
142
- )
143
-
144
  def main(language):
145
  translations = page_translations.get(language, page_translations['Polish'])
146
 
147
  st.title(translations['header'])
148
  st.markdown(translations['description'])
149
 
150
- inject_custom_css()
151
-
152
  # Pobieranie danych z plik贸w JSON
153
  try:
154
  stats = get_stats()
@@ -160,28 +139,19 @@ def main(language):
160
  # Kluczowe metryki
161
  total_analyses = stats.get("total_analyses", 0)
162
  total_frauds_detected = stats.get("total_frauds_detected", 0)
 
 
 
 
163
 
164
- # Wy艣wietlenie metryk za pomoc膮 funkcji `card()`
165
- col1, col2, col3, col4, col5, col6 = st.columns(6)
166
  with col1:
167
- card(
168
- title=translations['total_analyses'],
169
- text=str(total_analyses),
170
- )
171
  with col3:
172
- card(
173
- title=translations['total_frauds_detected'],
174
- text=str(total_frauds_detected),
175
- )
176
- with col5:
177
- if total_analyses > 0:
178
- fraud_percentage = (total_frauds_detected / total_analyses) * 100
179
- else:
180
- fraud_percentage = 0 # Ustawienie na 0% w przypadku braku analiz
181
- card(
182
- title=translations['fraud_percentage'],
183
- text=f"{fraud_percentage:.2f}%",
184
- )
185
 
186
  st.markdown("---")
187
 
@@ -222,13 +192,6 @@ def main(language):
222
  st.error(f"{translations['no_data']} ({e})")
223
  st.stop()
224
 
225
- # Dodanie pola wyszukiwania
226
- search_query = st.text_input(translations.get('search_placeholder', "Wyszukaj w historii:"), "")
227
- if search_query:
228
- df_filtered = df_filtered[
229
- df_filtered.apply(lambda row: row.astype(str).str.contains(search_query, case=False, regex=False).any(), axis=1)
230
- ]
231
-
232
  # Wy艣wietlenie tabeli historii analiz
233
  st.markdown(f"### {translations['history_title']}")
234
  if not df_filtered.empty:
@@ -255,22 +218,13 @@ def main(language):
255
 
256
  # Wy艣wietlenie metryk dla filtrowanej historii
257
  st.markdown("### " + translations['fraud_trend_title'])
258
- col7, col8, col9, col10, col11, col12 = st.columns(6)
259
- with col7:
260
- card(
261
- title=translations['total_analyses'],
262
- text=str(total_filtered),
263
- )
264
- with col9:
265
- card(
266
- title=translations['total_frauds_detected'],
267
- text=str(frauds_filtered),
268
- )
269
- with col11:
270
- card(
271
- title=translations['fraud_percentage'],
272
- text=f"{fraud_percentage_filtered:.2f}%",
273
- )
274
 
275
  # Wizualizacja procentowego podzia艂u oszustw
276
  st.markdown("### " + translations['fraud_vs_nonfraud'])
@@ -365,4 +319,4 @@ def main(language):
365
  else:
366
  st.info(translations['no_data'])
367
 
368
- # Funkcja main nie wywo艂uje st.set_page_config(), aby unikn膮膰 konfliktu z app.py
 
13
  # Importowanie funkcji z utils/functions.py
14
  from utils.functions import get_phone_info, get_stats, get_history, get_fake_numbers
15
 
 
 
 
16
  # Definiowanie t艂umacze艅 dla zak艂adki "Statystyki"
17
  page_translations = {
18
  'Polish': {
 
34
  'no_data': "Brak dost臋pnych danych do wy艣wietlenia.",
35
  'download_button': "馃摜 Pobierz dane jako CSV",
36
  'select_date_range': "Wybierz zakres dat:",
 
37
  'recent_days': 30 # Domy艣lny zakres dat
38
  },
39
  'German': {
 
55
  'no_data': "Keine Daten zum Anzeigen verf眉gbar.",
56
  'download_button': "馃摜 Daten als CSV herunterladen",
57
  'select_date_range': "Datumsbereich ausw盲hlen:",
 
58
  'recent_days': 30
59
  },
60
  'English': {
 
76
  'no_data': "No data available to display.",
77
  'download_button': "馃摜 Download data as CSV",
78
  'select_date_range': "Select date range:",
 
79
  'recent_days': 30
80
  }
81
  }
 
122
  except LookupError:
123
  return None
124
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  def main(language):
126
  translations = page_translations.get(language, page_translations['Polish'])
127
 
128
  st.title(translations['header'])
129
  st.markdown(translations['description'])
130
 
 
 
131
  # Pobieranie danych z plik贸w JSON
132
  try:
133
  stats = get_stats()
 
139
  # Kluczowe metryki
140
  total_analyses = stats.get("total_analyses", 0)
141
  total_frauds_detected = stats.get("total_frauds_detected", 0)
142
+ if total_analyses > 0:
143
+ fraud_percentage = (total_frauds_detected / total_analyses) * 100
144
+ else:
145
+ fraud_percentage = 0 # Ustawienie na 0% w przypadku braku analiz
146
 
147
+ # Wy艣wietlenie metryk za pomoc膮 st.metric()
148
+ col1, col2, col3 = st.columns(3)
149
  with col1:
150
+ st.metric(label=translations['total_analyses'], value=str(total_analyses))
151
+ with col2:
152
+ st.metric(label=translations['total_frauds_detected'], value=str(total_frauds_detected))
 
153
  with col3:
154
+ st.metric(label=translations['fraud_percentage'], value=f"{fraud_percentage:.2f}%")
 
 
 
 
 
 
 
 
 
 
 
 
155
 
156
  st.markdown("---")
157
 
 
192
  st.error(f"{translations['no_data']} ({e})")
193
  st.stop()
194
 
 
 
 
 
 
 
 
195
  # Wy艣wietlenie tabeli historii analiz
196
  st.markdown(f"### {translations['history_title']}")
197
  if not df_filtered.empty:
 
218
 
219
  # Wy艣wietlenie metryk dla filtrowanej historii
220
  st.markdown("### " + translations['fraud_trend_title'])
221
+ col1, col2, col3 = st.columns(3)
222
+ with col1:
223
+ st.metric(label=translations['total_analyses'], value=str(total_filtered))
224
+ with col2:
225
+ st.metric(label=translations['total_frauds_detected'], value=str(frauds_filtered))
226
+ with col3:
227
+ st.metric(label=translations['fraud_percentage'], value=f"{fraud_percentage_filtered:.2f}%")
 
 
 
 
 
 
 
 
 
228
 
229
  # Wizualizacja procentowego podzia艂u oszustw
230
  st.markdown("### " + translations['fraud_vs_nonfraud'])
 
319
  else:
320
  st.info(translations['no_data'])
321
 
322
+ # Upewnij si臋, 偶e st.set_page_config() jest wywo艂ywane tylko w app.py