Tigernawin commited on
Commit
c6f57eb
ยท
verified ยท
1 Parent(s): 18f5dd8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -27
app.py CHANGED
@@ -17,7 +17,6 @@ SITES = {
17
  "Ballari": {"coords": [12.9716, 77.5946], "zone": "Solar Power Plant"}
18
  }
19
 
20
- # ---- Fixed Placement for Each Site ----
21
  def generate_fixed_pole_locations(base_lat, base_lon, num_poles):
22
  area_width = 0.01
23
  area_height = 0.01
@@ -30,7 +29,6 @@ def generate_fixed_pole_locations(base_lat, base_lon, num_poles):
30
  for i in range(rows) for j in range(cols)
31
  ][:num_poles]
32
 
33
- # ---- Simulate Pole Data ----
34
  def simulate_pole(pole_id, site_name, lat, lon):
35
  solar_kwh = round(random.uniform(3.0, 7.5), 2)
36
  wind_kwh = round(random.uniform(0.5, 2.0), 2)
@@ -88,13 +86,11 @@ if selected_site in SITES:
88
  df = pd.DataFrame(all_data)
89
  site_df = df[df['Site'] == selected_site]
90
 
91
- # Summary
92
  col1, col2, col3 = st.columns(3)
93
  col1.metric("Total Poles", site_df.shape[0])
94
  col2.metric("Red Alerts", site_df[site_df['Alert Level'] == 'Red'].shape[0])
95
  col3.metric("Power Insufficiencies", site_df[site_df['Power Status'] == 'Insufficient'].shape[0])
96
 
97
- # Table
98
  st.subheader(f"๐Ÿ“‹ Pole Data Table for {selected_site}")
99
  with st.expander("Filter Options"):
100
  alert_filter = st.multiselect("Alert Level", options=site_df['Alert Level'].unique(), default=site_df['Alert Level'].unique())
@@ -106,16 +102,13 @@ if selected_site in SITES:
106
  ]
107
  st.dataframe(filtered_df, use_container_width=True)
108
 
109
- # Energy Chart
110
  st.subheader("๐Ÿ”‹ Energy Generation per Pole")
111
-
112
  energy_long_df = site_df[['Pole ID', 'Solar (kWh)', 'Wind (kWh)']].melt(
113
  id_vars='Pole ID',
114
  value_vars=['Solar (kWh)', 'Wind (kWh)'],
115
  var_name='Energy Source',
116
  value_name='kWh'
117
  )
118
-
119
  bar_chart = alt.Chart(energy_long_df).mark_bar().encode(
120
  x=alt.X('Pole ID:N', sort=None, title='Pole ID'),
121
  y=alt.Y('kWh:Q'),
@@ -125,24 +118,8 @@ if selected_site in SITES:
125
  width=800,
126
  height=400
127
  ).configure_axisX(labelAngle=45)
128
-
129
  st.altair_chart(bar_chart, use_container_width=True)
130
 
131
- # Fault Type Filter
132
- st.subheader("โš ๏ธ Map Filter: Select Fault Type(s)")
133
- fault_options = ['High Vibration (>3g)', 'Camera Offline', 'Power Insufficient']
134
- selected_faults = st.multiselect("Show poles with these fault conditions:", options=fault_options, default=fault_options)
135
-
136
- def fault_condition(row):
137
- return (
138
- ('High Vibration (>3g)' in selected_faults and row['Vibration (g)'] > 3) or
139
- ('Camera Offline' in selected_faults and row['Camera Status'] == 'Offline') or
140
- ('Power Insufficient' in selected_faults and row['Power Status'] == 'Insufficient')
141
- )
142
-
143
- fault_df = site_df[site_df.apply(fault_condition, axis=1)] if selected_faults else site_df
144
-
145
- # Map Color Logic
146
  def get_color(alert):
147
  if alert == 'Green':
148
  return [0, 255, 0, 160]
@@ -152,10 +129,9 @@ if selected_site in SITES:
152
  return [255, 0, 0, 160]
153
  return [128, 128, 128, 160]
154
 
155
- fault_df['color'] = fault_df['Alert Level'].apply(get_color)
156
 
157
- # Map
158
- st.subheader("๐Ÿ“ Pole Locations with Selected Faults")
159
  st.pydeck_chart(pdk.Deck(
160
  initial_view_state=pdk.ViewState(
161
  latitude=SITES[selected_site]["coords"][0],
@@ -166,7 +142,7 @@ if selected_site in SITES:
166
  layers=[
167
  pdk.Layer(
168
  'ScatterplotLayer',
169
- data=fault_df,
170
  get_position='[Longitude, Latitude]',
171
  get_color='color',
172
  get_radius=100,
 
17
  "Ballari": {"coords": [12.9716, 77.5946], "zone": "Solar Power Plant"}
18
  }
19
 
 
20
  def generate_fixed_pole_locations(base_lat, base_lon, num_poles):
21
  area_width = 0.01
22
  area_height = 0.01
 
29
  for i in range(rows) for j in range(cols)
30
  ][:num_poles]
31
 
 
32
  def simulate_pole(pole_id, site_name, lat, lon):
33
  solar_kwh = round(random.uniform(3.0, 7.5), 2)
34
  wind_kwh = round(random.uniform(0.5, 2.0), 2)
 
86
  df = pd.DataFrame(all_data)
87
  site_df = df[df['Site'] == selected_site]
88
 
 
89
  col1, col2, col3 = st.columns(3)
90
  col1.metric("Total Poles", site_df.shape[0])
91
  col2.metric("Red Alerts", site_df[site_df['Alert Level'] == 'Red'].shape[0])
92
  col3.metric("Power Insufficiencies", site_df[site_df['Power Status'] == 'Insufficient'].shape[0])
93
 
 
94
  st.subheader(f"๐Ÿ“‹ Pole Data Table for {selected_site}")
95
  with st.expander("Filter Options"):
96
  alert_filter = st.multiselect("Alert Level", options=site_df['Alert Level'].unique(), default=site_df['Alert Level'].unique())
 
102
  ]
103
  st.dataframe(filtered_df, use_container_width=True)
104
 
 
105
  st.subheader("๐Ÿ”‹ Energy Generation per Pole")
 
106
  energy_long_df = site_df[['Pole ID', 'Solar (kWh)', 'Wind (kWh)']].melt(
107
  id_vars='Pole ID',
108
  value_vars=['Solar (kWh)', 'Wind (kWh)'],
109
  var_name='Energy Source',
110
  value_name='kWh'
111
  )
 
112
  bar_chart = alt.Chart(energy_long_df).mark_bar().encode(
113
  x=alt.X('Pole ID:N', sort=None, title='Pole ID'),
114
  y=alt.Y('kWh:Q'),
 
118
  width=800,
119
  height=400
120
  ).configure_axisX(labelAngle=45)
 
121
  st.altair_chart(bar_chart, use_container_width=True)
122
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
  def get_color(alert):
124
  if alert == 'Green':
125
  return [0, 255, 0, 160]
 
129
  return [255, 0, 0, 160]
130
  return [128, 128, 128, 160]
131
 
132
+ site_df['color'] = site_df['Alert Level'].apply(get_color)
133
 
134
+ st.subheader("๐Ÿ“ Pole Locations")
 
135
  st.pydeck_chart(pdk.Deck(
136
  initial_view_state=pdk.ViewState(
137
  latitude=SITES[selected_site]["coords"][0],
 
142
  layers=[
143
  pdk.Layer(
144
  'ScatterplotLayer',
145
+ data=site_df,
146
  get_position='[Longitude, Latitude]',
147
  get_color='color',
148
  get_radius=100,