Spaces:
Running
Running
Update pages/Statistics.py
Browse files- pages/Statistics.py +8 -11
pages/Statistics.py
CHANGED
@@ -2,6 +2,7 @@ import streamlit as st
|
|
2 |
import pandas as pd
|
3 |
import plotly.express as px
|
4 |
import json
|
|
|
5 |
from datetime import datetime
|
6 |
|
7 |
# Definiowanie tłumaczeń dla zakładki "Statystyki"
|
@@ -15,7 +16,6 @@ page_translations = {
|
|
15 |
'total_frauds_detected': "Wykryte oszustwa",
|
16 |
'fraud_percentage': "Procent oszustw",
|
17 |
'history_title': "Historia analizowanych wiadomości",
|
18 |
-
'analyses_over_time': "Liczba analizowanych wiadomości w czasie",
|
19 |
'frauds_over_time': "Liczba wykrytych oszustw w czasie",
|
20 |
'risk_distribution': "Rozkład ocen ryzyka oszustwa",
|
21 |
'no_data': "Brak dostępnych danych do wyświetlenia."
|
@@ -29,7 +29,6 @@ page_translations = {
|
|
29 |
'total_frauds_detected': "Erkannte Betrügereien",
|
30 |
'fraud_percentage': "Betrugsprozentsatz",
|
31 |
'history_title': "Analyseverlauf der Nachrichten",
|
32 |
-
'analyses_over_time': "Anzahl der analysierten Nachrichten im Laufe der Zeit",
|
33 |
'frauds_over_time': "Anzahl der erkannten Betrügereien im Laufe der Zeit",
|
34 |
'risk_distribution': "Verteilung der Betrugsrisikobewertungen",
|
35 |
'no_data': "Keine Daten zur Anzeige verfügbar."
|
@@ -43,7 +42,6 @@ page_translations = {
|
|
43 |
'total_frauds_detected': "Frauds Detected",
|
44 |
'fraud_percentage': "Fraud Percentage",
|
45 |
'history_title': "History of Analyzed Messages",
|
46 |
-
'analyses_over_time': "Number of Analyzed Messages Over Time",
|
47 |
'frauds_over_time': "Number of Detected Frauds Over Time",
|
48 |
'risk_distribution': "Distribution of Fraud Risk Scores",
|
49 |
'no_data': "No data available to display."
|
@@ -109,13 +107,6 @@ def main(language):
|
|
109 |
# Wyświetlenie tabeli historii
|
110 |
st.dataframe(df_history[['timestamp', 'phone_number', 'risk_assessment']], height=300)
|
111 |
|
112 |
-
# Wizualizacja liczby analiz w czasie
|
113 |
-
st.markdown(f"### {translations['analyses_over_time']}")
|
114 |
-
df_history['date'] = df_history['timestamp'].dt.date
|
115 |
-
analyses_over_time = df_history.groupby('date').size().reset_index(name='counts')
|
116 |
-
fig_analyses_over_time = px.line(analyses_over_time, x='date', y='counts', title=translations['analyses_over_time'])
|
117 |
-
st.plotly_chart(fig_analyses_over_time)
|
118 |
-
|
119 |
# Wizualizacja oszustw w czasie
|
120 |
st.markdown(f"### {translations['frauds_over_time']}")
|
121 |
df_history['fraud_detected'] = df_history['risk_assessment'].apply(lambda x: 'Detected Fraud' if '10/10' in x else 'No Fraud')
|
@@ -128,6 +119,12 @@ def main(language):
|
|
128 |
# Wizualizacje ryzyka oszustwa (jeśli są dostępne dane)
|
129 |
if history:
|
130 |
st.markdown(f"### {translations['risk_distribution']}")
|
131 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
132 |
fig_risk_distribution = px.histogram(df_history, x='risk_score', nbins=10, title=translations['risk_distribution'])
|
133 |
st.plotly_chart(fig_risk_distribution)
|
|
|
2 |
import pandas as pd
|
3 |
import plotly.express as px
|
4 |
import json
|
5 |
+
import re
|
6 |
from datetime import datetime
|
7 |
|
8 |
# Definiowanie tłumaczeń dla zakładki "Statystyki"
|
|
|
16 |
'total_frauds_detected': "Wykryte oszustwa",
|
17 |
'fraud_percentage': "Procent oszustw",
|
18 |
'history_title': "Historia analizowanych wiadomości",
|
|
|
19 |
'frauds_over_time': "Liczba wykrytych oszustw w czasie",
|
20 |
'risk_distribution': "Rozkład ocen ryzyka oszustwa",
|
21 |
'no_data': "Brak dostępnych danych do wyświetlenia."
|
|
|
29 |
'total_frauds_detected': "Erkannte Betrügereien",
|
30 |
'fraud_percentage': "Betrugsprozentsatz",
|
31 |
'history_title': "Analyseverlauf der Nachrichten",
|
|
|
32 |
'frauds_over_time': "Anzahl der erkannten Betrügereien im Laufe der Zeit",
|
33 |
'risk_distribution': "Verteilung der Betrugsrisikobewertungen",
|
34 |
'no_data': "Keine Daten zur Anzeige verfügbar."
|
|
|
42 |
'total_frauds_detected': "Frauds Detected",
|
43 |
'fraud_percentage': "Fraud Percentage",
|
44 |
'history_title': "History of Analyzed Messages",
|
|
|
45 |
'frauds_over_time': "Number of Detected Frauds Over Time",
|
46 |
'risk_distribution': "Distribution of Fraud Risk Scores",
|
47 |
'no_data': "No data available to display."
|
|
|
107 |
# Wyświetlenie tabeli historii
|
108 |
st.dataframe(df_history[['timestamp', 'phone_number', 'risk_assessment']], height=300)
|
109 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
# Wizualizacja oszustw w czasie
|
111 |
st.markdown(f"### {translations['frauds_over_time']}")
|
112 |
df_history['fraud_detected'] = df_history['risk_assessment'].apply(lambda x: 'Detected Fraud' if '10/10' in x else 'No Fraud')
|
|
|
119 |
# Wizualizacje ryzyka oszustwa (jeśli są dostępne dane)
|
120 |
if history:
|
121 |
st.markdown(f"### {translations['risk_distribution']}")
|
122 |
+
|
123 |
+
# Użycie wyrażenia regularnego do wyodrębnienia liczby z tekstu oceny ryzyka
|
124 |
+
def extract_risk_score(risk_assessment):
|
125 |
+
match = re.search(r'(\d+)/10', risk_assessment)
|
126 |
+
return int(match.group(1)) if match else 0
|
127 |
+
|
128 |
+
df_history['risk_score'] = df_history['risk_assessment'].apply(extract_risk_score)
|
129 |
fig_risk_distribution = px.histogram(df_history, x='risk_score', nbins=10, title=translations['risk_distribution'])
|
130 |
st.plotly_chart(fig_risk_distribution)
|