ThejasRao commited on
Commit
f3e88b4
·
1 Parent(s): 98ef576

Fix: Readme

Browse files
Files changed (1) hide show
  1. streamlit_app.py +5 -24
streamlit_app.py CHANGED
@@ -30,12 +30,6 @@ IS_PROD = os.getenv("PROD", "False").lower() == "true"
30
  st.set_page_config(layout="wide")
31
 
32
 
33
- @st.cache_resource
34
- def get_cached_collections():
35
- """Cache MongoDB collections to avoid reconnecting on every page load."""
36
- return get_collections()
37
-
38
-
39
  def load_all_data(_collection):
40
  """Load all data from MongoDB collection."""
41
  data = list(_collection.find({}))
@@ -108,9 +102,9 @@ if 'authenticated' not in st.session_state:
108
  st.session_state.authenticated = False
109
 
110
  if st.session_state.authenticated:
111
- # Get cached collections only after authentication
112
  try:
113
- cols = get_cached_collections()
114
  except Exception as exc:
115
  st.error(f"Configuration error: {exc}")
116
  st.stop()
@@ -186,20 +180,7 @@ if st.session_state.authenticated:
186
  with st.expander("View grouped data (first 10 rows)"):
187
  st.dataframe(df_grouped.head(10))
188
 
189
- # Only fill gaps if there are multiple data points
190
- if len(df_grouped) > 1:
191
- st.write(f"🔧 **Filling date gaps...**")
192
- original_len = len(df_grouped)
193
- date_range = pd.date_range(start=df_grouped['Reported Date'].min(), end=df_grouped['Reported Date'].max(), freq='D')
194
- st.write(f"- Total days in range: {len(date_range)}")
195
- df_grouped = df_grouped.set_index('Reported Date').reindex(date_range).rename_axis('Reported Date').reset_index()
196
- df_grouped['Arrivals (Tonnes)'] = df_grouped['Arrivals (Tonnes)'].ffill().bfill()
197
- df_grouped['Modal Price (Rs./Quintal)'] = df_grouped['Modal Price (Rs./Quintal)'].ffill().bfill()
198
- st.write(f"- Rows after filling: {len(df_grouped)} (was {original_len})")
199
-
200
- # Show final data before plotting
201
- with st.expander("View final plot data (first 20 rows)"):
202
- st.dataframe(df_grouped.head(20))
203
 
204
  st.subheader(f"📈 Trends for {selected_state} ({'Market: ' + selected_market if market_wise else 'State'})")
205
 
@@ -361,9 +342,9 @@ else:
361
  password = st.text_input("Password", type="password")
362
  login_button = st.form_submit_button("Login")
363
  if login_button:
364
- # Get cached collections for authentication
365
  try:
366
- cols = get_cached_collections()
367
  users_collection = cols['users_collection']
368
  except Exception as exc:
369
  st.error(f"Database connection error: {exc}")
 
30
  st.set_page_config(layout="wide")
31
 
32
 
 
 
 
 
 
 
33
  def load_all_data(_collection):
34
  """Load all data from MongoDB collection."""
35
  data = list(_collection.find({}))
 
102
  st.session_state.authenticated = False
103
 
104
  if st.session_state.authenticated:
105
+ # Get collections after authentication
106
  try:
107
+ cols = get_collections()
108
  except Exception as exc:
109
  st.error(f"Configuration error: {exc}")
110
  st.stop()
 
180
  with st.expander("View grouped data (first 10 rows)"):
181
  st.dataframe(df_grouped.head(10))
182
 
183
+ st.write(f"📊 **Plotting {len(df_grouped)} actual data points (no gap filling)**")
 
 
 
 
 
 
 
 
 
 
 
 
 
184
 
185
  st.subheader(f"📈 Trends for {selected_state} ({'Market: ' + selected_market if market_wise else 'State'})")
186
 
 
342
  password = st.text_input("Password", type="password")
343
  login_button = st.form_submit_button("Login")
344
  if login_button:
345
+ # Get collections for authentication
346
  try:
347
+ cols = get_collections()
348
  users_collection = cols['users_collection']
349
  except Exception as exc:
350
  st.error(f"Database connection error: {exc}")