Update app.py
Browse files
app.py
CHANGED
|
@@ -19,6 +19,13 @@ def generate_data():
|
|
| 19 |
bandwidth_usage = max(1, min(150, bandwidth_usage)) # Keep within a realistic range
|
| 20 |
data.append([school, time, bandwidth_usage])
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
df = pd.DataFrame(data, columns=["School", "Timestamp", "Bandwidth_Usage"])
|
| 23 |
df.to_csv("network_data.csv", index=False)
|
| 24 |
return df
|
|
@@ -56,7 +63,7 @@ def allocate_bandwidth(demand_predictions, total_bandwidth=500):
|
|
| 56 |
def sdn_load_balancer(network_graph, demand_predictions):
|
| 57 |
shortest_paths = {}
|
| 58 |
for school in demand_predictions.keys():
|
| 59 |
-
shortest_paths[school] = nx.shortest_path(network_graph, source='Node_A', target=school)
|
| 60 |
return shortest_paths
|
| 61 |
|
| 62 |
# Create a complex network topology
|
|
@@ -102,4 +109,7 @@ with col3:
|
|
| 102 |
|
| 103 |
with col4:
|
| 104 |
st.subheader("Detected Anomalies")
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
bandwidth_usage = max(1, min(150, bandwidth_usage)) # Keep within a realistic range
|
| 20 |
data.append([school, time, bandwidth_usage])
|
| 21 |
|
| 22 |
+
# Introduce anomalies manually
|
| 23 |
+
for _ in range(10): # Increase anomaly occurrences
|
| 24 |
+
school = np.random.choice(schools)
|
| 25 |
+
time = np.random.choice(time_range)
|
| 26 |
+
bandwidth_usage = np.random.choice([1, 160]) # Extreme low or high values
|
| 27 |
+
data.append([school, time, bandwidth_usage])
|
| 28 |
+
|
| 29 |
df = pd.DataFrame(data, columns=["School", "Timestamp", "Bandwidth_Usage"])
|
| 30 |
df.to_csv("network_data.csv", index=False)
|
| 31 |
return df
|
|
|
|
| 63 |
def sdn_load_balancer(network_graph, demand_predictions):
|
| 64 |
shortest_paths = {}
|
| 65 |
for school in demand_predictions.keys():
|
| 66 |
+
shortest_paths[school] = nx.shortest_path(network_graph, source='Node_A', target=school, weight=None)
|
| 67 |
return shortest_paths
|
| 68 |
|
| 69 |
# Create a complex network topology
|
|
|
|
| 109 |
|
| 110 |
with col4:
|
| 111 |
st.subheader("Detected Anomalies")
|
| 112 |
+
if anomalies.empty:
|
| 113 |
+
st.write("No anomalies detected")
|
| 114 |
+
else:
|
| 115 |
+
st.dataframe(anomalies)
|