Spaces:
Sleeping
Sleeping
Fix: Readme
Browse files- streamlit_app.py +28 -8
streamlit_app.py
CHANGED
|
@@ -39,13 +39,23 @@ def get_cached_collections():
|
|
| 39 |
@st.cache_data(ttl=300) # Cache for 5 minutes
|
| 40 |
def load_all_data(_collection):
|
| 41 |
"""Load and cache all data from MongoDB collection."""
|
| 42 |
-
data = list(_collection.find({}
|
| 43 |
if not data:
|
| 44 |
return pd.DataFrame()
|
| 45 |
df = pd.DataFrame(data)
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
return df
|
| 50 |
|
| 51 |
|
|
@@ -58,14 +68,24 @@ def get_filtered_data(_collection, state=None, market=None, days=30):
|
|
| 58 |
if market:
|
| 59 |
query_filter["Market Name"] = market
|
| 60 |
|
| 61 |
-
data = list(_collection.find(query_filter
|
| 62 |
if not data:
|
| 63 |
return pd.DataFrame()
|
| 64 |
|
| 65 |
df = pd.DataFrame(data)
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
return df
|
| 70 |
|
| 71 |
|
|
|
|
| 39 |
@st.cache_data(ttl=300) # Cache for 5 minutes
|
| 40 |
def load_all_data(_collection):
|
| 41 |
"""Load and cache all data from MongoDB collection."""
|
| 42 |
+
data = list(_collection.find({}))
|
| 43 |
if not data:
|
| 44 |
return pd.DataFrame()
|
| 45 |
df = pd.DataFrame(data)
|
| 46 |
+
|
| 47 |
+
# Drop MongoDB _id field
|
| 48 |
+
if '_id' in df.columns:
|
| 49 |
+
df = df.drop(columns=['_id'])
|
| 50 |
+
|
| 51 |
+
# Convert data types
|
| 52 |
+
if 'Reported Date' in df.columns:
|
| 53 |
+
df['Reported Date'] = pd.to_datetime(df['Reported Date'])
|
| 54 |
+
if 'Modal Price (Rs./Quintal)' in df.columns:
|
| 55 |
+
df['Modal Price (Rs./Quintal)'] = pd.to_numeric(df['Modal Price (Rs./Quintal)'], errors='coerce')
|
| 56 |
+
if 'Arrivals (Tonnes)' in df.columns:
|
| 57 |
+
df['Arrivals (Tonnes)'] = pd.to_numeric(df['Arrivals (Tonnes)'], errors='coerce')
|
| 58 |
+
|
| 59 |
return df
|
| 60 |
|
| 61 |
|
|
|
|
| 68 |
if market:
|
| 69 |
query_filter["Market Name"] = market
|
| 70 |
|
| 71 |
+
data = list(_collection.find(query_filter))
|
| 72 |
if not data:
|
| 73 |
return pd.DataFrame()
|
| 74 |
|
| 75 |
df = pd.DataFrame(data)
|
| 76 |
+
|
| 77 |
+
# Drop MongoDB _id field
|
| 78 |
+
if '_id' in df.columns:
|
| 79 |
+
df = df.drop(columns=['_id'])
|
| 80 |
+
|
| 81 |
+
# Convert data types
|
| 82 |
+
if 'Reported Date' in df.columns:
|
| 83 |
+
df['Reported Date'] = pd.to_datetime(df['Reported Date'])
|
| 84 |
+
if 'Modal Price (Rs./Quintal)' in df.columns:
|
| 85 |
+
df['Modal Price (Rs./Quintal)'] = pd.to_numeric(df['Modal Price (Rs./Quintal)'], errors='coerce')
|
| 86 |
+
if 'Arrivals (Tonnes)' in df.columns:
|
| 87 |
+
df['Arrivals (Tonnes)'] = pd.to_numeric(df['Arrivals (Tonnes)'], errors='coerce')
|
| 88 |
+
|
| 89 |
return df
|
| 90 |
|
| 91 |
|