Spaces:
Running
Running
Update pages/Statistics.py
Browse files- pages/Statistics.py +39 -5
pages/Statistics.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
import plotly.express as px
|
|
|
4 |
import json
|
5 |
import re
|
6 |
from datetime import datetime
|
@@ -18,6 +19,9 @@ page_translations = {
|
|
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."
|
22 |
},
|
23 |
'German': {
|
@@ -31,6 +35,9 @@ page_translations = {
|
|
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."
|
35 |
},
|
36 |
'English': {
|
@@ -44,6 +51,9 @@ page_translations = {
|
|
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."
|
48 |
}
|
49 |
}
|
@@ -96,6 +106,13 @@ def main(language):
|
|
96 |
|
97 |
col3.metric(label=translations['fraud_percentage'], value=f"{fraud_percentage:.2f}%")
|
98 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
# Wy艣wietlenie historii analiz w tabeli
|
100 |
if history:
|
101 |
st.markdown(f"### {translations['history_title']}")
|
@@ -114,11 +131,8 @@ def main(language):
|
|
114 |
frauds_over_time = df_history.groupby(['date', 'fraud_detected']).size().reset_index(name='counts')
|
115 |
fig_frauds_over_time = px.bar(frauds_over_time, x='date', y='counts', color='fraud_detected', title=translations['frauds_over_time'])
|
116 |
st.plotly_chart(fig_frauds_over_time)
|
117 |
-
else:
|
118 |
-
st.info(translations['no_data'])
|
119 |
|
120 |
-
|
121 |
-
if history:
|
122 |
st.markdown(f"### {translations['risk_distribution']}")
|
123 |
|
124 |
# U偶ycie wyra偶enia regularnego do wyodr臋bnienia liczby z tekstu oceny ryzyka
|
@@ -127,5 +141,25 @@ def main(language):
|
|
127 |
return int(match.group(1)) if match else 0
|
128 |
|
129 |
df_history['risk_score'] = df_history['risk_assessment'].apply(extract_risk_score)
|
130 |
-
fig_risk_distribution = px.histogram(df_history, x='risk_score', nbins=10, title=translations['risk_distribution'])
|
131 |
st.plotly_chart(fig_risk_distribution)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
import pandas as pd
|
3 |
import plotly.express as px
|
4 |
+
import plotly.graph_objects as go
|
5 |
import json
|
6 |
import re
|
7 |
from datetime import datetime
|
|
|
19 |
'history_title': "Historia analizowanych wiadomo艣ci",
|
20 |
'frauds_over_time': "Liczba wykrytych oszustw w czasie",
|
21 |
'risk_distribution': "Rozk艂ad ocen ryzyka oszustwa",
|
22 |
+
'fraud_country_distribution': "Rozk艂ad oszustw wed艂ug kraj贸w",
|
23 |
+
'heatmap_title': "Mapa ciep艂a oszustw w czasie",
|
24 |
+
'fraud_vs_nonfraud': "Procentowy podzia艂: Oszustwa vs Bezpieczne",
|
25 |
'no_data': "Brak dost臋pnych danych do wy艣wietlenia."
|
26 |
},
|
27 |
'German': {
|
|
|
35 |
'history_title': "Analyseverlauf der Nachrichten",
|
36 |
'frauds_over_time': "Anzahl der erkannten Betr眉gereien im Laufe der Zeit",
|
37 |
'risk_distribution': "Verteilung der Betrugsrisikobewertungen",
|
38 |
+
'fraud_country_distribution': "Betrug nach L盲ndern",
|
39 |
+
'heatmap_title': "Heatmap der Betr眉gereien im Laufe der Zeit",
|
40 |
+
'fraud_vs_nonfraud': "Prozentanteil: Betrug vs Sichere Nachrichten",
|
41 |
'no_data': "Keine Daten zur Anzeige verf眉gbar."
|
42 |
},
|
43 |
'English': {
|
|
|
51 |
'history_title': "History of Analyzed Messages",
|
52 |
'frauds_over_time': "Number of Detected Frauds Over Time",
|
53 |
'risk_distribution': "Distribution of Fraud Risk Scores",
|
54 |
+
'fraud_country_distribution': "Fraud Distribution by Countries",
|
55 |
+
'heatmap_title': "Fraud Heatmap Over Time",
|
56 |
+
'fraud_vs_nonfraud': "Fraud vs Safe Messages Percentage",
|
57 |
'no_data': "No data available to display."
|
58 |
}
|
59 |
}
|
|
|
106 |
|
107 |
col3.metric(label=translations['fraud_percentage'], value=f"{fraud_percentage:.2f}%")
|
108 |
|
109 |
+
# Wizualizacja procentowego podzia艂u oszustw
|
110 |
+
fraud_data = [total_frauds_detected, total_analyses - total_frauds_detected]
|
111 |
+
fraud_labels = ['Fraud', 'Non-Fraud']
|
112 |
+
fig_fraud_pie = go.Figure(data=[go.Pie(labels=fraud_labels, values=fraud_data, hole=.3)])
|
113 |
+
fig_fraud_pie.update_layout(title_text=translations['fraud_vs_nonfraud'])
|
114 |
+
st.plotly_chart(fig_fraud_pie)
|
115 |
+
|
116 |
# Wy艣wietlenie historii analiz w tabeli
|
117 |
if history:
|
118 |
st.markdown(f"### {translations['history_title']}")
|
|
|
131 |
frauds_over_time = df_history.groupby(['date', 'fraud_detected']).size().reset_index(name='counts')
|
132 |
fig_frauds_over_time = px.bar(frauds_over_time, x='date', y='counts', color='fraud_detected', title=translations['frauds_over_time'])
|
133 |
st.plotly_chart(fig_frauds_over_time)
|
|
|
|
|
134 |
|
135 |
+
# Wizualizacja rozk艂adu ocen ryzyka oszustwa
|
|
|
136 |
st.markdown(f"### {translations['risk_distribution']}")
|
137 |
|
138 |
# U偶ycie wyra偶enia regularnego do wyodr臋bnienia liczby z tekstu oceny ryzyka
|
|
|
141 |
return int(match.group(1)) if match else 0
|
142 |
|
143 |
df_history['risk_score'] = df_history['risk_assessment'].apply(extract_risk_score)
|
144 |
+
fig_risk_distribution = px.histogram(df_history, x='risk_score', nbins=10, title=translations['risk_distribution'], color_discrete_sequence=['#FFA07A'])
|
145 |
st.plotly_chart(fig_risk_distribution)
|
146 |
+
|
147 |
+
# Wizualizacja mapy ciep艂a
|
148 |
+
st.markdown(f"### {translations['heatmap_title']}")
|
149 |
+
heatmap_data = df_history.groupby('date').size().reset_index(name='count')
|
150 |
+
fig_heatmap = px.density_heatmap(heatmap_data, x='date', y='count', nbinsx=20, nbinsy=20, title=translations['heatmap_title'])
|
151 |
+
st.plotly_chart(fig_heatmap)
|
152 |
+
|
153 |
+
# Dodanie mapy Europy (wymaga danych kraj贸w dla numer贸w telefon贸w)
|
154 |
+
st.markdown(f"### {translations['fraud_country_distribution']}")
|
155 |
+
if 'country' in df_history.columns:
|
156 |
+
country_data = df_history.groupby('country').size().reset_index(name='counts')
|
157 |
+
fig_map = px.choropleth(country_data, locations='country', locationmode='country names', color='counts',
|
158 |
+
title=translations['fraud_country_distribution'], color_continuous_scale='Viridis')
|
159 |
+
st.plotly_chart(fig_map)
|
160 |
+
else:
|
161 |
+
st.info("Brak danych o krajach numer贸w telefon贸w.")
|
162 |
+
else:
|
163 |
+
st.info(translations['no_data'])
|
164 |
+
|
165 |
+
# Nie dodawaj "if __name__ == '__main__':" w podstronach
|