engralimalik commited on
Commit
8b08df1
·
verified ·
1 Parent(s): 60ef103

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +45 -0
app.py ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pandas as pd
2
+ import folium
3
+ from sklearn.cluster import KMeans
4
+ from folium.plugins import MarkerCluster
5
+
6
+ # Load data from Excel
7
+ def load_data(filename):
8
+ lat_long_data = pd.read_excel(filename, sheet_name='LatLong')
9
+ download_data = pd.read_excel(filename, sheet_name='DownloadUpload')
10
+ return pd.merge(lat_long_data, download_data, on='school_id', how='inner')
11
+
12
+ # Perform clustering to find data center location
13
+ def find_data_center(df, n_clusters=1):
14
+ kmeans = KMeans(n_clusters=n_clusters, random_state=0).fit(df[['latitude', 'longitude']])
15
+ return kmeans.cluster_centers_
16
+
17
+ # Create a map and plot the points
18
+ def plot_map(df, center):
19
+ map = folium.Map(location=[center[0][0], center[0][1]], zoom_start=10)
20
+ marker_cluster = MarkerCluster().add_to(map)
21
+ # Add school locations
22
+ for idx, row in df.iterrows():
23
+ folium.Marker(
24
+ location=[row['latitude'], row['longitude']],
25
+ popup=f"Download Speed: {row['download_speed']} Mbps, Upload Speed: {row['upload_speed']} Mbps",
26
+ icon=folium.Icon(color='blue', icon='info-sign')
27
+ ).add_to(marker_cluster)
28
+ # Add data center
29
+ folium.Marker(
30
+ location=[center[0][0], center[0][1]],
31
+ popup="Proposed Data Center",
32
+ icon=folium.Icon(color='red', icon='cloud')
33
+ ).add_to(map)
34
+ return map
35
+
36
+ # Main function to run the application
37
+ def main():
38
+ filename = '/path/to/your/Copy of data barbados(1).xlsx'
39
+ df = load_data(filename)
40
+ center = find_data_center(df)
41
+ map = plot_map(df, center)
42
+ map.save('index.html')
43
+
44
+ if __name__ == '__main__':
45
+ main()