safiaa02 commited on
Commit
1eac4f4
·
verified ·
1 Parent(s): 3191fd5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -4
app.py CHANGED
@@ -7,7 +7,7 @@ from prophet import Prophet
7
  import networkx as nx
8
  from eventlet import event
9
 
10
- # Generate synthetic data
11
  def generate_data():
12
  schools = [f"School_{i}" for i in range(1, 11)] # 10 Schools
13
  time_range = [datetime.now() - timedelta(hours=i) for i in range(24)] # Past 24 hours
@@ -15,7 +15,8 @@ def generate_data():
15
  data = []
16
  for school in schools:
17
  for time in time_range:
18
- bandwidth_usage = np.random.randint(1, 100) # Random bandwidth usage in Mbps
 
19
  data.append([school, time, bandwidth_usage])
20
 
21
  df = pd.DataFrame(data, columns=["School", "Timestamp", "Bandwidth_Usage"])
@@ -26,8 +27,11 @@ def generate_data():
26
  df = generate_data()
27
 
28
  def detect_anomalies(df):
29
- df['Z_Score'] = (df['Bandwidth_Usage'] - df['Bandwidth_Usage'].mean()) / df['Bandwidth_Usage'].std()
30
- anomalies = df[df['Z_Score'].abs() > 2] # Mark as anomaly if Z-score > 2
 
 
 
31
  return anomalies
32
 
33
  def train_prophet(df):
 
7
  import networkx as nx
8
  from eventlet import event
9
 
10
+ # Generate synthetic data with more complexity
11
  def generate_data():
12
  schools = [f"School_{i}" for i in range(1, 11)] # 10 Schools
13
  time_range = [datetime.now() - timedelta(hours=i) for i in range(24)] # Past 24 hours
 
15
  data = []
16
  for school in schools:
17
  for time in time_range:
18
+ bandwidth_usage = np.random.normal(loc=50, scale=20) # Normal distribution for more variation
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"])
 
27
  df = generate_data()
28
 
29
  def detect_anomalies(df):
30
+ # Using IQR for anomaly detection
31
+ Q1 = df['Bandwidth_Usage'].quantile(0.25)
32
+ Q3 = df['Bandwidth_Usage'].quantile(0.75)
33
+ IQR = Q3 - Q1
34
+ anomalies = df[(df['Bandwidth_Usage'] < (Q1 - 1.5 * IQR)) | (df['Bandwidth_Usage'] > (Q3 + 1.5 * IQR))]
35
  return anomalies
36
 
37
  def train_prophet(df):